Walker News

How To Use Robocopy To Sync Backup Files In Windows 7?

OK, the Windows Backup program bundled with Windows 7 is better than the one offered by Windows Vista. The new Backup and Restore allows user to decide which folders to include in the backup, instead of which file types, as what is seen in Windows Vista.

However, it is still not good enough to meet my backup requirement. And so is you, I believe.

My backup plan is not complicated. Indeed, I just would like Windows to synchronize backup files in USB hard disk with those data files in local hard disks of Desktop and laptop.

Having said that, the content of backup drive (destination) and backup source will be the same when the backup program completes its job (theoretically is 100%, suppose that there is no change in the source when backup in progress).
To create a sync backup is like using a RAID-1 disk mirroring, means having the backup program to copy new or newer files to backup drive, at the same time delete those files in backup drive that are no longer exist in backup source.

So, if not using Backup and Restore program, what program I can use to create a sync backup? The answer is using Robocopy, a command-line utility program bundled with Windows Vista as well as the latest Windows 7.

Using Robocopy program of Windows 7 to create synchronize backup, i.e. mirror the data files in source to backup drive.

If you type robocopy /? in Command Prompt window, the long list of Robocopy command options probably would keep you fainted for a while.

Don’t worry. Here is the sample of using Robocopy mirroring function, that I use at least once a day to sync data files in Desktop and laptop to the USB hard disk drive:
robocopy C:\WalkerData G:\WalkerData /MIR /ZB /R:3 /V /FP /LOG:D:\sync.log /TEE

Where C:\WalkerData is the backup source and G:\WalkerData is the backup destination.
  • /MIR – MIRror a directory tree (equivalent to /E plus /PURGE). This option does exactly what I want to the backup plan to be.
  • /ZB – use restartable mode; if access denied use Backup mode. This option is not necessary, anyway. Restartable mode is useful for copying files over network (if the link drop). Backup mode is simply means allow files to be opened without security restrictions (Robocopy in Windows 7 is still not using Volume Shadow Copy or VSS service to copy open file). NOTE: you need elevated privilege to use backup mode option (or the combined /ZB option).
  • /R:3 is useful to restrict number of retries on failed copies to only 3, instead of the default 1 million :-)
  • /V option produces Verbose output, showing skipped files. It’s good to see how well Robocopy performs in Command Prompt window.
  • /FP option includes Full Pathname of files in the output.
  • /LOG: means to create or overwrite the specified log file of job done by Robocopy. To append, instead of overwrite, use /LOG+: option.
  • /TEE option means to show whatever log to the log file to the standard output as well (in this case, the standard output is Command Prompt window).

Using the sample at above, you can simply modify the backup source and destination for your case. You can also save it to a command file (.cmd) to save typing the Robocopy backup options again and again.

Custom Search

  1. Carl Spanoghe 04-12-09@10:22

    Thanks for that Walker — I have made the script, but in win7 my user is set to the Administrator type, but when I try the script I’m told I do not have Backup and Restore user rights. Is there a way to make my account have those rights? Is this because I have Win7 Premium instead of Pro?


  2. Walker 05-12-09@14:56

    Ops, sorry. Forgot to mention that with Windows Vista, Windows 7, Windows Server 2008, or above, you need to run robocopy in Command Prompt with elevated privilege.

  3. David Barham 21-09-10@17:44

    Have you tried this to backup c:\users\{username}
    I’m finding I get recursive directory structures
    c:\users\{username}AppData\Local\Application Data\Application Data\…..

    Any ideas?

  4. Walker 21-09-10@18:26

    @David, I never tried to backup the %userprofile%.

    I guess you can by explicitly backup some of the folders but not all in the %UserProfile%, because there are lot of junction (similar to symbolic links in UNIX/Linux).

    You can view the junctions by typing this in command prompt:

    dir /A:D %UserProfile%
  5. Walker 29-09-10@01:02

    Just realize there is an option of robocopy to exclude Junction points:

    Type robocopy /? for more information on the options.

  6. David 22-11-10@02:28

    When running RoboCopy in Win7 remember to run CMD as Administrator This will allow you to use /B and /ZB

  7. jason404 03-03-11@22:35

    Robocopy does not sync both ways, so it’s not actual syncing, is it? It’s just one way copying.

  8. Walker 04-03-11@00:01

    It mirrors files from “source” to “destination” – depends on how you define the “source” and “destination”, it can be “both” way.

    My requirement is simply as this:

    1. All data files that has changed on Desktop/Laptop are sync to USB drive for backup.

    2. In case of restoring, I swap the “source” and “destination” so all files are “sync” from USB drive to Desktop/Laptop.

  9. Surm 19-09-11@09:16

    Hi Walker,

    From your description (dated 04-03-11@00:01), it appears that RoboCopy does merely does a one-way copy from Source to Target.

    In other words, what RoboCopy does is functionally equivalent to:

    1. Delete everything in Target
    2. Copy everything from Source to Target

  10. Walker 20-09-11@02:15

    Only those files that have changed will be replaced with a copy from source.

2018  •  Privacy Policy