Backing-up with Rsync and Robocopy

Disclaimer: With great power comes great responsibility –improper use of rsync and robocopy may result in irreversible data-loss. If working on your OS X terminal or Windows command prompt takes you too far out of your comfort zone, then you may be better off with a tried and tested off-the-shelf solution.

Face it – there is no “undo button” in real life. Maybe it was your hard drive that suddenly died on you. Your precious memories now forever consigned to the digital wasteland. This then followed by the cruel realisation that there isn’t a spare copy lying around. Yes – just like many “oh s**t” moments in life – you didn’t see it coming. You could have made a backup.

A “backup”, in this context, is a copy of your files that you can put aside for safekeeping. There are many other off-the-shelf solutions that offer a variety of functions and we hear terminology like “delta copy”, “disk imaging” getting thrown around frequently. However, in the strictest sense of the word, a backup is just a duplicate of your files.

This is not meant to be an exhaustive guide on rsync and robocopy. Rather, I intend to illustrate how a simple backup operation can be performed with these two terminal commands.

What You Will Need

  1. An external storage device – preferably a hard drive.
  2. A computer running Microsoft Windows Vista and above, or a Mac.
  3. Some patience and common sense (see Additional Notes at bottom of page).

Introducing rsync and robocopy

If you haven’t figured out already, rsync and robocopy are terminal commands that can be used to perform simple to fairly advanced synchronization of files between two folders.

There is risk associated with using rsync and robocopy, but in my opinion, for that it more than makes up for in a few ways:

  • It’s FREE (comes with your operating system).
  • It’s powerful – plenty of sync options available (beyond the scope of this guide).
  • It’s smart – can be configured to sync only files that have been changed/updated.

Rsync – “Remote Sync”, use this on UNIX-based systems (eg. Linux, Mac OS X etc.)

rsync -option --delete --progress [source path] [destination path]

Robocopy – “Robust File Copy”, use this on Windows Vista, Server 2008 and up

robocopy /MIR [source path] [destination path]    

I will provide more examples and a detailed breakdown of the options available.

It is possible to use both rsync and robocopy in conjunction with the Automator on OS X and the Task Scheduler for Windows, but that is a topic for a future blog post.

Robocopy

Syntax format for robocopy is:

robocopy /MIR [source path] [destination path]

Example usage:

robocopy /MIR C:\src C:\dest

Copy the above line of text and paste it in notepad. The under filename, key in “robocopy-example.bat”. Include the double quote marks to force notepad to save the file with a .bat extension.

You may save the .bat file to your desktop or anywhere that is convenient. Make sure there are two folders in drive C:\ called src and dest as the script won’t work if these folders are not created beforehand.

Copy some files or folders into the src folder and double-click the .bat file that you earlier created. Notice the files and folders getting synced over to the destination folder. Because we invoked the “/MIR”, or “mirror” switch, note that any files or folders deleted from the source folder will also be deleted from the destination. Consider yourself warned.

Do note that you can assign any folder path for the source and destination folders. Note that this is a one-direction sync; adding files only to the destination folder, then running the script will result in the files being deleted from the destination as they don’t exist in the source folder.

Rsync

With rsync, things are a little less straighforward as you will need to configure file permissions in order to run your command script (more on this later). Notice that there are also more options. I’ll run through these one-by-one. Take note that rsync, like robocopy, syncs in one direction.

Syntax format is:

rsync -option --delete --progress [source path] [destination path]

The below example is what I am using to backup

rsync -av --progress --delete /Volumes/Seagate\ Backup\ Plus\ Drive/My\ Files/Photo\ Backups/2016/ /Volumes/Seagate\ FreeAgent/My\ Files/Photo\ Backups/2016

The -av option defines that the copying should preserve the file and folder attributes (eg. Date modified, created etc.) and that the copying process should output verbose logs. The –progress parameter indicates that rsync should output the progress of the copy process. And finally, –delete will remove any files or folders in the destination path that is not found in the source.

Note that the back slashes in the source and destination paths are used in conjunction with the spaces in the folder names.

Here’s a clearer picture:

Source: /Volumes/Seagate Backup Plus Drive/My Files/Photo Backups/2016/

Destination: /Volumes/Seagate FreeAgent/My Files/Photo Backups/2016

Note: The destination path is missing the terminating forward slash (/). This is intentional.

Save the above script in a text file with extension .command (example: rsync-sample.command). For simplicity, save this file to your desktop.

Now we’ll need to adjust the file permissions so we can execute the script in OS X via double-click.

In the OS X terminal, navigate to the desktop (or the location where the command script was placed) and enter the following:

chmod 775 rsync-sample.command

Then hit [Enter].

You should then be able to execute the file via double-click.

Additional Tips

  • Any files that are used by any open programs will not be synced. Make sure to close all applications before syncing.
  • Be careful when specifying the source and destination folders. Reversing the order may cause irreversible data loss.
  • The examples provided here are based on my usage and workflow. There are many other options switches available for rsync and robocopy.
  • I recommend doing a few practice runs before trying out rsync or robocopy on your actual data.

Leave a Comment

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