Solved

Getting started with Robocopy

Posted on 2012-03-25
6
558 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
Comment Utility
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
Comment Utility
best link for robocopy is
http://ss64.com/nt/robocopy.html

it has all th command options
0
 
LVL 6

Expert Comment

by:Tomislavj
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 8

Expert Comment

by:bchallis
Comment Utility
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
Comment Utility
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
Comment Utility
Did that provide what you needed?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

With voice direction tools, various map viewing styles, the ability to get directions for different means of transportation and great service, Google Maps is simply one of the best navigations app in the market.    However, over the past year, an …
New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
This Micro Tutorial  demonstrates whether your site uses one subdomain or multiple subdomains, how to create full URLs from Google Analytics content reports. This procedure is called concatenation and can also be done with the CONCATENTATE function.…
This Micro Tutorial will introduce a Google tool, which is a great way to learn more about dimensions in metrics in Google Analytics, even if you use the interface or the API.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now