ROBOCOPY command to do an incremental backup
Solution 1:
I have been successfully using a variant of the following script for a few years now:
robocopy C:\source M:\destination /MIR /FFT /R:3 /W:10 /Z /NP /NDL
Parameters explained
The
/MIR
option (equivalent to/E /PURGE
) stands for "mirror" and is the most important option. It regards your source folder as the "master", causing robocopy to copy/mirror any changes in the source (new files, deletions etc.) to the target, which is a useful setting for a backup./FFT
is a very important option, as it allows a 2-second difference when comparing timestamps of files, such that minor clock differences between your computer and your backup device don't matter. This will ensure that only modified files are copied over, even if file modification times are not exactly synchronized./R:3
specifies the number of retries, if the connection should fail, and/W:10
specifies a wait time of 10 seconds between retries. These are useful options when doing the backup over a network./Z
copies files in "restart mode", so partially copied files can be continued after an interruption./NP
and/NDL
suppress some debug output, you can additionally add/NS
,/NC
,/NFL
to further reduce the amount of output (see the documentation for details). However, I would suggest to print some debug output during the first runs, to make sure everything is working as expected.
Additional useful parameters mentioned by other users
/XJD
excludes "junction points" for directories, symbolic links that might cause problems like infinite loops during backup. See Brian's comments for details./MT[:N]
uses multithreading and can speed up transfers of many small files. For N, a value of 2-4 times the number of cores should do on a normal machine. Commented by Zoredache on the original question.
Edit in response to Granger's comment:
If you really want to keep files that exist on the destination, but not on the source side, simply replace the /MIR
option with /E
. However, I would strongly suggest to use /MIR
when you want to use the destination for incremental backups. Otherwise any files that have been renamed or moved at the source will clutter up the destination, meaning you get duplicates. I usually create a subfolder "backup" on the destination which contains a 1:1 copy of my source folder tree. That way you can still keep around historical files next to the backup folder and remove or reorganize them safely later on.
Solution 2:
I like to use the following:
robocopy "C:\Users\<user>" "F:\robocopy\<user>" /XJD /R:0 /XA:SH /E /ZB /XO /XD "Downloads" "AppData" /LOG:robocopy.log /TEE
I run this as Administrator so backup mode (/b
option) can make copy of files in use.
Other options not related to incremental nature of backup are:
/XD
to exclude directories from backup.
/XJD
to exclude junction points ("My Music").
/R:0
to set retry on failed attempts to 0.
/XA:SH
to skip hidden and system files.
To remove as much logging info as possible, append the following options /NP /NS /NDL /NFL /NC
.