I’m putting this here as a reference for myself and anyone else that frequently uses Robocopy. The following Robocopy command is my go to for most cases. If you don’t use Robocopy, I highly recommend it as the command line tool to automate file copy/sync jobs either locally or across the network between Windows machines. Don’t use the GUI version, you are better than that.
Step 1
RTFM: http://ss64.com/nt/robocopy.html
Step 2
Modify this for your use case:
robocopy.exe "D:Source" "ServerDestination" *.* /NFL /NDL /LOG:logscopylog.txt /R:2 /W:1 /COPYALL /XO /ZB /E
Break It Down
- /NFL and /NDL – Suppresses file and directory lists. Unless you need to see a line for every file it copied, use these.
- /LOG – If you are running this on a scheduled task, it’s probably a good idea to write to a log so you can review it later if there are issues. Use /log+ to append instead of overwrite.
- /R and /W – Determines the number of retries (/r) and the wait time between retries (/w). This is completely preference, but it could greatly impact the amount of time the job takes to run depending on the number of files and failures.
- /COPYALL – Copy all the things. But seriously, read the manual on this one. If you need to exclude any meta data of the files, you can be more specific.
- /XO – This is optional but recommended if you plan to run a job multiple times. This will make your scheduled tasks run much faster than the initial seed. If you have a scenario where you will be migrating files to a destination and files will be changing at both the source and destination, you may want to use this to prevent changes being lost on the destination.
- /ZB – This has been useful in some servers where permissions are very granular and locked down. The command will attempt to copy using regular mode first and fall back to backup mode if it fails. Backup mode happens immediately and is not dependent on your /w value.
- /E – Use this flag to include subfolders. You probably want this.
Mirror, Purge, Kill
Be very cautious when using the purge and mirror options. You may delete files and not realize the impact. For example, you run a Robocopy command with /MIR to replicate a folder from serverA to serverB with the hopes of freeing up space on serverA. After the Robocopy job finishes, you delete those files on serverA. Users continue to store files serverA, and you want to move those files to serverB. If you run that same Robocopy script, you will lose everything you previously copied to serverB. Hopefully, you had backups :). Mirror sounds like a great idea, until you read the description and realize it also runs a purge. I prefer not to use these and avoid any accidents like this.