Robocopy Overview

2 minute read

Description:

Robocopy is a built-in Windows tool that is used to copy files from one location to another in seamless way. It is used by administrators for its efficiency and convenience. Here are some example uses. NOTE: Replace “(source) (destination)” with UNC paths or mapped drive letters. Also, don’t put the trailing backslash in path names as Robocopy will treat this as an escape character.

See here for uses.

To Copy Directories On Internal Disks:

robocopy (source) (destination) #will perform standard copy

robocopy (source) (destination) /mir /r:1 /w:1 #will delete files in dest that don’t match source

To Copy Directories Over Network:

robocopy (source) (destination) /mir /mt:32 /r:10 /w:10

To Copy Folder Structure (and permissions) But Not Files:

robocopy (source) (destination) /e /z /SEC /xf *

To Resolve A “Path Too Long Error”:

Robocopy can overcome the 255 character limitation in Windows:

robocopy c:\emptyfolder c:\deletefolder /purge

Batch File To Copy User Files To Backup Server:

cd c:windowssystem32
robocopy C:Users%username%Documents \fileserveruserbackups%username%Documents /mir /z /e /R:10 /W:10 /mt:4
robocopy C:Users%username%Desktop \fileserveruserbackups%username%Desktop /mir /z /e /R:10 /W:10 /mt:4
robocopy C:Users%username%Favorites \fileserveruserbackups%username%Favorites /mir /z /e /R:10 /W:10 /mt:4
robocopy C:Users%username%Pictures \fileserveruserbackups%username%Pictures /mir /z /e /R:10 /W:10 /mt:4

*For an extra step, I would go into the file server itself and set permissions for each user to where only the administrator and that user can modify their directory. Then when they access the file server, they can only use and see their backups.

**
** File Server Migration:

robocopy (source) (destination) /b /mir /copyall /dcopy:T /R:1 /W:1 /log+:C:DATARoboCopyLog.txt

or

robocopy (source) (destination) /mir /sec /secfix /v /mt:20 /log:c:robocopy.log /tee

or

robocopy z: g: /mir /sec /secfix /copyall /R:5 /W:1 /log:C:robo.log /tee

 

Example backup script:
ROBOCOPY C:\Source \Server\Destination *.* /E /R:1 /W:1 /XX /LOG+:C:\scripts\robo.log /NP /NFL /NDL
:: /E :: Copy empty folders
:: /R:1 :: Retry once
:: /W :: Wait one second between retries
:: /XX :: Don’t delete at destination
:: /LOG+ :: Append to log
:: /NP :: Log – don’t display progress
:: /NFL :: Log – don’t list files
:: /NDL :: Log – don’t list directories

Backup a Server:
The script below copies data from FileServ1 to FileServ2, the destination holds a full mirror along with file security info. When run regularly to synchronize the source and destination, robocopy will only copy those files that have changed (change in time stamp or size.)

@ECHO OFF
SETLOCAL
SET _source=\FileServ1\e$\users
SET _dest=\FileServ2\e$\BackupUsers
SET _what=/COPYALL /B /MIR
:: /COPYALL :: COPY ALL file info
:: /B :: copy files in Backup mode.
:: /MIR :: MIRror a directory tree
SET _options=/R:0 /W:0 /LOG:C:\batch\RoboLog.txt /NFL /NDL
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /NFL :: No file logging
:: /NDL :: No dir logging
ROBOCOPY %_source% %_dest% %_what% %_options%

Copy only permission changes (additions and removals) assuming we already have a copy of the data:
ROBOCOPY \FileServer\C$ \SVR-Backups\c$\Backups /E /Copy:S /IS /IT