[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Getting started with Robocopy

Posted on 2012-03-25
6
Medium Priority
?
590 Views
Last Modified: 2014-11-12
a friend recomended robocopy, i wish to get started, but have no idea how.

i am using server 2008 r2
i want to copy a folder called c:\gdrive  to my f drive
i woul dlike robocopy to make a new folder on my f drive, rather then over write it.
my ideal situation would be to have a new folder corresponding to the day of the month the copies were made.
it is fine with me, if it makes one copy, then subsequent are only the changed files... but i do  have a small amount of data and a large destination drive.

is anyone familiar....with how i would begin.?
0
Comment
Question by:intelogent
6 Comments
 
LVL 2

Expert Comment

by:ven16
ID: 37762572
may the below link helps you to do it, it use the powershell script.
and let me know the result
http://itnshare.blogspot.co.uk/2009/10/autorotate-and-renaming-files-as-for_14.html
0
 
LVL 30

Expert Comment

by:IanTh
ID: 37762586
best link for robocopy is
http://ss64.com/nt/robocopy.html

it has all th command options
0
 
LVL 6

Expert Comment

by:Tomislavj
ID: 37762590
maybe free cobian backup 8 is easier to use for this purpose because there's no need for scripts, just choose options (and there is option for have daily backups as different names)
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 8

Expert Comment

by:Brent Challis
ID: 37769618
I have a PowerShell function that I use for backing up files.  It creates a command line for running RoboCopy after reading a configuration file which is a csv file listing the sourcedirectory,targetdirectory


# ==============================================================================================
#
# NAME: Backup-RCopy
#             PowerShell utility which utilises RoboCopy to perform the copying of the directory
#            structure copying the files that are new or altered.
# AUTHOR: bchallis ,
# DATE  : 26/01/2012
#
# COMMENT:
#
# ==============================================================================================
function Backup-RCopy
{
    [CmdletBinding(SupportsShouldProcess=$True)]
    Param
    (
        [Parameter(Mandatory=$True)]
        [string]$ConfigurationFileName,
        [Parameter(Mandatory=$True)]
        [string]$LogFileName,
        [switch]$Force
    )

    function Log
    {
        Param
        (
            [parameter(Mandatory=$true)]
            [int]$Level,
            [parameter(Mandatory=$true)]
            [String]$TaskCategory,
            [parameter(Mandatory=$true)]
            [String]$Message
        )
        if (Test-Path Function:\Add-BCLogEntry)
        {
            Add-BCLogEntry -Path $LogFileName -Level $Level -Source "BackupRCopy" -taskCategory $TaskCategory -message $Message
        }
          else
        {
              ("[{0}] {1}" -f ([System.DateTime].Now.ToString()),$Message) | Out-File -FilePath $LogFileName -Append
        }
    }
   
    function IsNull
    {
          Param
          (
                $value,
                $default
          )
          $retValue = $value
          if ($value -eq $null)
          {
                $retValue = $default
          }
          else
          {
                if ([String].IsNullOrEmpty($value))
                {
                      $retValue = $default
                }
          }
          return $retValue
    }
   
    function Display-Configuration
    {
          $configurations = Import-Csv $ConfigurationFileName
            foreach ($config in $configurations)
            {
            $sourceDirectory = $config.SourceDirectory.Trim()
            if (-not $sourceDirectory.EndsWith("\"))
            {
                $sourceDirectory += "\"
            }
            $targetDirectory = $config.DestinationDirectory.Trim()
            if (-not $targetDirectory.EndsWith("\"))
            {
                $targetDirectory += "\"
            }
            Write-Host      "Source directory = $sourceDirectory - Target directory = $targetDirectory."
            }
    }

#############################################################################################################
# Main Code
#############################################################################################################

      $errorsFound = $false
      if (Test-Path $ConfigurationFileName)
      {
          Write-Verbose "Using configuration file $ConfigurationFileName"
            $configurations = Import-Csv $ConfigurationFileName
            foreach ($config in $configurations)
            {
                  if ($config -ne $null)
                  {
                        $sourceDirectory = $config.SourceDirectory
                        $targetDirectory = $config.DestinationDirectory
                        if (($sourceDirectory -ne $null) -and ($targetDirectory -ne $null))
                        {
                              if ($PSCmdlet.ShouldProcess((Get-Item env:\ComputerName).Value, ("Backing up {0} up to {1}" -f $sourceDirectory,$targetDirectory)))
                              {
                              if (-not $sourceDirectory.EndsWith("\"))
                              {
                                  $sourceDirectory += "\"
                              }
                              if (-not $targetDirectory.EndsWith("\"))
                              {
                                  $targetDirectory += "\"
                              }
                              
                              if (-not (Test-Path $targetDirectory))
                              {
                                  if ((Test-Path (Split-Path $targetDirectory -Qualifier)) -and $Force)
                                  {
                                      New-Item $targetDirectory -type directory
                                  }
                              }
                              
                                    if ((Test-Path $sourceDirectory) -and (Test-Path $targetDirectory))
                                    {
                                  $command = "RoboCopy " + $sourceDirectory + " " + $targetDirectory + " /E /Z /XO /COPY:DAT"
                                  
                                      try
                                      {
                                          Write-Verbose "Command: $command"
                                                    $procres = Invoke-Expression $command
                                          if ($verbosePreference)
                                          {
                                              foreach ($o in $procres)
                                              {
                                                  Write-Host $o.ToString()
                                              }
                                          }
                                      }
                                      Catch
                                      {
                                          $errorsFound =$true
                                      }
                                    }
                                    else
                                    {
                                  $message = ("Unable to locate source ($sourceDirectory) and destination ($targetDirectory) directories.")
                                  Log -Message $message -Level 2 -TaskCategor y "Backing up files"
                                  $errorsFound =$true
                                          Write-Warning $message
                                    }
                              }
                              else
                              {
                                    # Selected to not perform action
                              }
                        }
                  }
            }
                Add-BCLogEntry -Path $LogFileName -Level 0 -Source "rBackup" -TaskCategory "SuccessfulBackup" -Message "Backup Complete"
      }
      else
      {
            $errorsFound =$true
            Log -Level 3 -TaskCategory "Initialisation" -Message "configuration File not found."
            Write-Warning "Unable to find configuration file $ConfiguratinFileName"
      }
}
0
 
LVL 8

Expert Comment

by:SeaSenor
ID: 37777088
Intelogent... here is the .bat file I think you were wanting from me.

it is attached
Here are the steps:

1. rename the extension from .txt to .bat

2. I have the source name as:    C:\gdrive
3. I have the destination name as :   F:\gdrive

4. create your 'folderlist' to include the folders you want to copy.  Name it:  folderlist.txt  and place it in the same diretory you put this .bat file ( i use just the C:\  folder)
5. Create a folder named Robocopylogfiles on the F:\   drive.

This script will create a folder with the current date, and copy any new/changed files only.
The first round it will probably copy everything... which is good.

It will also create a log file and it will then put a copy of that days log file into the folder of the day it was created.

This should accomplish what you are asking in your post.

Let me know if you need more help.
Daily-incremental.txt
0
 
LVL 8

Accepted Solution

by:
SeaSenor earned 2000 total points
ID: 37814914
Did that provide what you needed?
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OfficeMate Freezes on login or does not load after login credentials are input.
Many of you may be aware of the recent Google Docs scam emails that have been floating around coming from various people that you know. Here's a guide on identifying How To Identify the Scam Email You will see an email from someone you’ve had co…
This Micro Tutorial demonstrates in Google Analytics how to create a custom report that shows you traffic over time using the month of year dimensions. There are also instructions on how to fix Google's odd month of year formatting, which Microsoft …
This Micro Tutorial demonstrates how to create custom reports and the secrets of determine the metrics and dimensions for your data that works best with your needs.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question