09 May

Backing up a folder on macOS with rsync

Terminal

Quite often we’re asked how to keep a backup folder in sync with a work in progress folder. There are many possible solutions apps and third party solutions out there, but its quite easy to set up a rough, homespun backup solution. All you need is a little command line wizardry using something called rsync.

Syncing with rsync

First, lets imagine we have two folders on our desktop. One is called WIP, which contains all my work in progress. The other is called Backup which is where I’d like to keep a backup of all my WIP.

Open up a Terminal window (you’ll find Terminal in /Applications/Utilities) and type:

rsync -av --delete

Don’t hit return yet! Next, drag the WIP folder onto your Terminal to get the path to your folder. Add a slash to the end of it. You should have something like this:

rsync -av --delete /Users/YourUserName/Desktop/WIP/

Don’t hit return yet! Of course, the path will be different on your Mac – don’t worry about it. Next, drag the Backup folder onto the Terminal. You should now have something like this:

rsync -av --delete /Users/YourUserName/Desktop/WIP/ /Users/YourUserName/Desktop/Backup

Now you can hit return! You should find that the contents of WIP are copied to Backup. If you run the command a second time, nothing will happen. This is the beauty of rsync. It’s smart enough to only copy files from WIP if an identical copy doesn’t already exist in Backup. Our “–delete” option means that anything in in Backup that’s NOT in WIP gets deleted.

Of course, your backup folder can be anywhere – on an external drive or even on a remote server.

Scheduling

There are a number of ways to make this rsync command run a schedule. You could run it via a scheduled Automator action, via cron using something like Cronnix, or (my favourite) using a Launch Agent.

Have fun with your new backup command!

While we have your attention… why not check out our macOS apps?

Barcode Basics – macOS barcode generator (including Automator support)
Ai Actions – Automator action pack for Adobe Illustrator
Pages Automator Actions – Automator action pack for Pages