Robocopy All the Things

IT

Robocopy All the Things

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.

More About the Author

Tim Rhymer

Systems Engineer
Protect Tableau Server for Free with Let’s Encrypt (Windows) These days, there isn’t really an excuse to not protect all the things with some form of encryption. If your web server supports ...
How to Use Kaseya to Detect Meltdown and Spectre Vulnerable Machines To help detect client Windows machines that are vulnerable to Meltdown and Spectre at the OS and Hardware level, we built a Kaseya ...

See more from this author →

Subscribe to our newsletter

  • I understand that InterWorks will use the data provided for the purpose of communication and the administration my request. InterWorks will never disclose or sell any personal data except where required to do so by law. Finally, I understand that future communications related topics and events may be sent from InterWorks, but I can opt-out at any time.
  • This field is for validation purposes and should be left unchanged.

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK

×

Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Germany
Geschäftsführer: Mel Stephenson

Kontaktaufnahme: markus@interworks.eu
Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072