Solved

Getting started with Robocopy

Posted on 2012-03-25
6
567 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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 500 total points
ID: 37814914
Did that provide what you needed?
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Google Forms is a great platform to easily create polls, questionnaires and surveys. The service allows you to receive data in real-time and is a simple way to conduct large-scale surveys that can be distributed to multiple people.   The platform …
Whether you’re looking to gather data for research or gather feedback on an idea, being able to build and distribute your own online survey is not only cost-effective, but allows you to reach a larger audience and receive results in real-time. Googl…
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.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

792 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