rsync
When I first started learning photography, I used Aperture as my photo editor and management solution. But I was too dumb to use it right and accidentally deleted the only copy of many photos from the first years of my son’s life. Since then, I have been diligent, borderline fanatical, about having backup copies of family media and important files.
Determined to never repeat that mistake, I explored various tools for creating better backups. One of the most versatile tools I found is rsync, built right into macOS.
What is rsync?
rsync is a terminal command that is essentially the pro level of copy and paste but for files.
Unlike copy and paste, rsync intelligently checks what’s already been copied and only transfers what’s different or new, so it’s much faster on subsequent backups. rsync can also resume a backup if interrupted, so you don’t have to start over if something happens, and at the end, rsync verifies that everything copied correctly, so you can rest easy knowing that your second copy is real and complete.
Basically, rsync is a tool that makes it so you never have to say “bye, bye, bye” to your photos or important files ever again.
Why should you use rsync?
rsync excels at creating a backup copy of many small to medium-sized files from one computer or drive to another. Especially if you are moving those files across a network and plan on doing this repeatedly.
The bonus is that rsync is a function built into macOS and most Linux distributions, so you don’t have to download or buy anything new.
If you have a folder of photos or other important files you can’t replace, you might want to use rsync to create a copy.
How I use rsync
Running terminal commands is not something I want to do manually, so I wrap my terminal commands in Keyboard Maestro macros. This lets me tie these commands to other automations and events on my Mac, and when it comes to backup solutions, you really don’t want to have to think about it.
Example 1
Every time I close Lightroom, Keyboard Maestro runs an rsync command to back up my catalog to my NAS.
This makes sure that every new photo is saved, every moved photo is updated on the NAS, and every (intentionally) deleted photo is gone from the NAS to save my storage space.
Example 2
I like to keep a local copy of all of my bank statements and financial files. I have several years of this information stored on my device with subfolders for different accounts, and I update this throughout the month as new statements become available.
Since I want to have a backup of these important files, I have a Keyboard Maestro macro that runs each night. It is a one-step macro that just runs an rsync command to update my financial file backup to another Mac on my network.
Example 3
But you can get a little more creative with rsync, too.
I have another Keyboard Maestro macro that I run manually each January 1st. It uses rsync to make a copy of just the folders from the same local copy of my financial files from Example 2. This lets me easily replicate the folder structure of my financial files for the upcoming year.
As an extra bit of cleverness, this macro uses some Keyboard Maestro variables and calculations to figure out the values for last year and this year and include those in the file path of the folders it creates.
rsync -a /sourceFolder/$KMVAR_LastYear/ /destinationFolder/$KMVAR_ThisYear/ --include \*/ --exclude \*
This example uses a feature of rsync called flags. The --include \*/
flag ensures only folders are copied, while --exclude \*
skips the files thenselves.
How you can use rsync
I know terminal commands can be intimidating, so I created two tools to help you. But first, there is a Finder option that is super helpful for this, and I leave it on all the time. “Show the Path Bar.” In Finder, go to View, then click Show Path Bar.
With this option on, you can easily get the Pathname to any folder on your Mac by right-clicking on it in the path bar.
Required Information
To create an rsync command, you need two things: the Pathname to where the original files are (i.e., the source) and the Pathname to where you want your backup to exist (i.e., the destination). I suggest you create a new empty folder for your destination.
Using the Path Bar trick described above, you can easily find this information. Once you have the pathnames, you need to write the command, which is pretty annoying, so I made two different tools to help you write your commands.
Creating rsync Commands
I created a custom GPT called Rsync Robot that will answer questions and write the command for you based on your answers and the pathnames you share.
I also created a Drafts Action for those of you who would prefer a non-AI approach. Full disclosure: I wrote the action with AI, so if you want to check our work, you can (and probably should) use the official rsync docs here and here.
Your command should look something like this:
rsync -azvh --delete "/sourceFolder/" "/destinationFolder/"
You can read through the rsync docs here and here to find a ton of options. As you can see from the example above and the output of the tools I provided, I use -azvh --delete
as my options for most of my commands – feel free to adjust the options to best suit your needs.
Understand that, like all things terminal, your rsync command is very unforgiving. Each letter and space means something. Don’t edit your command without understanding that.
Using rsync Commands
By default, rsync is a command that you run in the Terminal, but I run all of mine from Keyboard Maestro, and I suggest you do too.
Mainly because Keyboard Maestro lets you easily schedule the running of these commands while also allowing you to run them manually when you like.
That being said, before automating your rsync command, it’s a good idea to test it manually first to make sure it’s doing exactly what you expect.
To integrate a rsync command in Keyboard Maestro, you want to use an Execute Shell Script action in your macro. Use the options for “With input from Nothing,” “Execute text script,” and “Ignore results” (see the red box in the image below). Then paste your rsync command into the text box for the action (see the blue line in the image below). Feel free to build anything you like around this action with your applicable triggers.
Conclusion
rsync is an example of a powerful tool that is much more approachable and useful than it is scary, and I encourage you to test it out.
Paired with tools like Time Machine for local system backups and Backblaze for cloud backup, rsync creates a solid, multi-modal backup solution to make sure that precious memories don’t get lost forever.
Start by backing up a single important folder using rsync, and once you’re comfortable with how it works, you can start automating your backups with Keyboard Maestro.
Leave a Reply
Want to join the discussion?Feel free to contribute!