Robocopy backup

Backups with rsync in Linux world is the de facto standard, but when you have to admin Windows based systems you really miss it.
How can I perform Windows Backups? How can I sync two folders?
In this post we will review how to perform files/folder backups, not system backups.

Robocopy

We will not discuss here how to use rsync in Windows. We will work with Microsoft native tool for this matters: Robocopy.

Objective

We will synchronize one folder. Each time we execute our robocopy command, it will compare both source and backup folder and only new or modified files and/or folders will be copied. Deleted files and folders in source will be deleted in backup folder as well.

Backup examples

We will see two common cases:

  1. Local backup
  2. Remote backup

You can review the meaning of every flag used with robocopy at the final section of this post “Robocopy options”.

Local backup

In this case we will sync two folders on the same server.
We are going to backup the whole content of “F:\ImportantFolder” in “E:\Backup” and leave a log in “E:\Backup.log”.

Open a “cmd” console and type:

robocopy F:\ImportantFolder E:\Backup *.* /e /sec /PURGE /Xd "System Volume Information" "$RECYCLE.BIN" /LOG:E:\Backup.log /Xo

At the end, backup folder is synchronized and a log is created in the specified path.

Remote backup

This example is the same, but with the source folder in a different server.
We need to saveĀ “F:\ImportantFolder” in “servername”.

robocopy \\servername\F$\ImportantFolder E:\Backup *.* /e /sec /PURGE /Xd "System Volume Information" "$RECYCLE.BIN" /LOG:E:\Backup.log /Xo

Make sure you have the right permissions.

Robocopy options

In this section, we are going to review the robocopy flags used in the examples, so you can check and modify as you need.

  • /e: Copy subdirectories, including empty ones.
  • /sec: Copy files with SECurity (equivalent to /COPY:DATS).
  • /PURGE: Delete dest files/dirs that no longer exist in source.
  • /Xd: eXclude Directories matching given names/paths.
  • /Xo: eXclude Older files (incremental).

For further info you can check help output.

robocopy /?

 

Leave a Reply

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