Robocopy

Robocopy is a great tool for copying and syncing data between source and destination (and vice-versa).
Here you can find both general knowledge about the tool and few examples on how to use Robocopy.

Reference

All commands can be found here:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy

Known issues

  • Sometimes there should be “” around source and destination, sometimes not. You really just need to try both.
  • Sometimes the destination folder goes “missing” after sync is started. That is because the destination folder gets a hidden attribute. Then sync is finished, you can remove hidden attribute on the destination folder with this command:
    attrib -H -S F:\data\rootfolder /D
  • Then copying files with /mt:2 or higher, only files in thread 1 will be showed in the window, other threads will run, but not be shown in the prompt.

How to run Robocopy

Robocopy is included in Windows. You can start Robocopy from both CMD and PowerShell. You need to be elevated in the prompt of choise, otherwise you will get an error abour lack of backup permissions.

Examples

One-way Copy – Copy NFTS Permissions – Include Empty folders

This command set will copy all files and folders from source to destination (files that exist in the destination that are newer, will be skipped Files that exist with same date but different size, will be copied). This command also copies NFTS permissions. You can run the command multiple times without changing it, if you need to copy all files first, and then updating one or more times (delta-copy) before final cutover (final-copy).

Please note that files that was first copied to destination, then deleted in source and command is run again to do final-copy, deleted files in source, will still be present in destination because this command does not mirror. (this is useful if you do not want to delete any files in destination that have been modified or created)

  • Source is set to F:data\rootfolder
  • Destination is set to “\newfileserver\F$\data\rootfolder”
  • Please change both to fit your setup.
  • Please also note that /mt:5 should be set to 2 if you are copying files in and performance sensible environment.

robocopy F:\data\rootfolder "\\newfileserver\F$\data\rootfolder" /E /zb /r:5 /w:3 /xc /xo /copyall /mt:5 /log:robocopy.txt

/E = Copies subdirectories. This option automatically includes empty directories.
/zb = Copies files in restartable mode. If file access is denied, switches to backup mode.
/r:5 = Specifies the number of retries on failed copies.
/w:3 = Specifies the wait time between retries, in seconds.
/xc = Excludes existing files with the same timestamp, but different file sizes.
/xo = Source directory files older than the destination are excluded from the copy.
/copyall = Copies all file information (data, attributes, time stamps, extended attribute, NFTS ACLs, Owner info, audit info, skip alt data streams)

/mt:5 = Creates multi-threaded copies with 5 threads.
/log:robocopy.txt = Specify log file for output. Please note that the file will be created in the folder where the command is executed from.

One-way Copy – Exclude NFTS Permissions – Include Empty folders

This command set will copy all files and folders from source to destination (files that exist in the destination that are newer, will be skipped. Files that exist with same date but different size, will be copied). This command does not copy NFTS permissions (best suited for situations where source and destination are not in the same domain). You can run the command multiple times without changing it, if you need to copy all files first, and then updating one or more times (delta-copy) before final cutover (final-copy).

Please note that files that was first copied to destination, then deleted in source and command is run again to do final-copy, deleted files in source, will still be present in destination because this command does not mirror. (this is useful if you do not want to delete any files in destination that have been modified or created)

  • Source is set to F:data\rootfolder
  • Destination is set to “\newfileserver\F$\data\rootfolder”
  • Please change both to fit your setup.
  • Please also note that /mt:5 should be set to 2 if you are copying files in and performance sensible environment.

robocopy F:\data\rootfolder "\\newfileserver\F$\data\rootfolder" /E /zb /r:5 /w:3 /xc /xo /copy:dat /mt:5 /log:robocopy.txt

/E = Copies subdirectories. This option automatically includes empty directories.
/zb = Copies files in restartable mode. If file access is denied, switches to backup mode.
/r:5 = Specifies the number of retries on failed copies.
/w:3 = Specifies the wait time between retries, in seconds.
/xc = Excludes existing files with the same timestamp, but different file sizes.
/xo = Source directory files older than the destination are excluded from the copy.
/copyall = Copies all file information (data, attributes, time stamps, extended attribute, NFTS ACLs, Owner info, audit info, skip alt data streams)

/mt:5 = Creates multi-threaded copies with 5 threads.
/log:robocopy.txt = Specify log file for output. Please note that the file will be created in the folder where the command is executed from.

One-way Sync – Exclude NFTS Permissions

This command set will sync all files and folders from source to destination (files that exist in the destination will be deleted, and all files newer or modified in source will be updated on destination). This command does not sync NFTS permissions. You can run the command multiple times without changing it, if you need to sync all files first, and then updating one or more times (delta-copy) before final cutover (final-copy).

  • Source is set to F:data\rootfolder
  • Destination is set to “\newfileserver\F$\data\rootfolder”
  • Please change both to fit your setup.
  • Please also note that /mt:5 should be set to 2 if you are copying files in and performance sensible environment.

robocopy F:\data\rootfolder "\\newfileserver\F$\data\rootfolder" /MIR /mt:5 /log:robocopy.txt

One-way Sync – Include NFTS Permissions

This command set will sync all files and folders from source to destination (files that exist in the destination will be deleted, and all files newer or modified in source will be updated on destination). This command does sync NFTS permissions. You can run the command multiple times without changing it, if you need to sync all files first, and then updating one or more times (delta-copy) before final cutover (final-copy).

  • Source is set to F:data\rootfolder
  • Destination is set to “\newfileserver\F$\data\rootfolder”
  • Please change both to fit your setup.
  • Please also note that /mt:5 should be set to 2 if you are copying files in and performance sensible environment.

robocopy F:\data\rootfolder "\\newfileserver\F$\data\rootfolder" /MIR /SEC /mt:5 /log:robocopy.txt

Other relevant parameters

  • /s = Copies subdirectories. This option automatically excludes empty directories. /s and /e must not be used in the same command, because they conflict.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *