Rsync is cool

written on 2022-09-06 20:56:13 +0300 EEST

If you don’t know how to use rsync you should take the time to learn at least the basics. It’s a very neat little program that can make simple backups a breeze.

I have a growing collection of books:

smarton@macton Books % find . -type f | wc -l
smarton@macton Books % du -sh .
5.5G	.

My problem is that I keep downloading cool stuff I find on the internet on multiple devices. I don’t want a cloud backup solution. My files, my choice.

I was diagnosed with severe distro-hopping so I can’t bother to set up syncthing 20 times per month. I want something simple and reliable. I also have a fear that I might accidentally format a drive that hosts some important files whenever I (re)install my systems, and I have an external hard drive lying around so I’d like to use it.

If you read the rsync manual, you can see that the author included a section about how he’s using rsync. I adapted the samba-source-tree example for my personal use, making the following Makefile:

	rsync -avuzb "/Volumes/TOSHIBA Ext/Books/" ~/Documents/Books

	rsync -avuzb ~/Documents/Books/ "/Volumes/TOSHIBA Ext/Books"

sync: get put

Now, whenever I want to sync my books between my laptop and my external drive, I can just run make sync. Of course, this won’t work on my other machines because these paths are macOS specific, but the commands are so easy to edit that having to “maintain” a similar Makefile on each of my systems won’t be a headache.

Rsync can do a lot more stuff than just copying files locally. It’s good for synchronizing with remotes also, so you can do things like deploying a website with it. I’d advise you to read the (entire) manual – it’s not that big.