Skip to content

Create Time Machine-like backups via rsync

Taking a break from the recent Frankenmac posts, here's a little trick for creating "Time Machine like" backups of anything you'd care to back up1I don't know how well this might work for Mac files, as opposed to Unix files. But Mac files can be saved to the real Time Machine.. In my case, it's the HTML files off of my web sites, both personal and work. I used to simply back these up, but then realized it'd be better to have versions rather than totally overwriting the backup each day (which is what I had been doing).

Once you've got it set up and working, you'll have a folder structure similar to the one at right, with one folder for each backup, and a "current" link that takes you to the newest backup.

I get zero credit for this one; my buddy James explained that he'd been using this method for a year without any troubles, and pointed me to this great guide2The original site that hosted this script is gone; I've linked to a copy I found on Original URL:
that explains the process.

I used that guide and added the following to my backup script to create my own customized Time Machine for the files from here,

/usr/local/bin/rsync -aP \
  --link-dest=/path/to/quasi/TM_backup/current user@host:/path/to/files/on/server/ \
  --exclude "errors.csv" \
  --delete --delete-excluded \
rm -f /path/to/quasi/TM_backup/current
ln -s /path/to/quasi/TM_backup/back-$newtime /path/to/quasi/TM_backup/current

And that's all there is to it. Note that you may need a newer version of rsync than what comes with macOS now (2.6.9)—I use version 3.1.2 from Homebrew, so I can't say for sure that this script works with the stock version.

I've only been using this for a couple weeks, but it's working well for me so far.

9 thoughts on “Create Time Machine-like backups via rsync”

  1. I am not sure you need or even want --delete since you want snapshots *as they were*. I am not sure if it would delete on the older backup or do nothing at all.

    I wrote a Python wrapper around this rsync call to automatically delete older snapshots and do some other exclusions. I will post it to github eventually and pass it on

  2. I'm currently testing this with a few modifications tailored to my environment. Thanks for finding the time and posting it here!!

    I have a doubt though. I wonder if the global behaviour matches what time machine does, meaning that every snapshot that TM creates I think has symbolic links to the previous backup, thus sparing a lot of space. My feeling at this point (and I reiterate that I'm currently testing this) is that every back-$newtime folder will only contain the "delta", but it will not be self-contained in itself, will it? Not sure I'm making my point correctly...

    1. No, they're full backups—I have a complete copy of all the files in each backup. It's done with hard links, I believe, so it doesn't take up a ton of space.


  3. I appreciate this, but a backup example without the associated restore procedure is not so useful. The very nice thing with Apple's TimeMachine solution is that restore is flexible and easy. One can restore a single file or a whole machine, and this can be done even when restoring to new hardware. Can you please write about restore of the rsync data?

    1. Bob:

      There is no "restore procedure," as you're merely creating copies of files. Want something back? Copy it from the backup to wherever you want it. Of course, there's no Time Machine-like interface, so you'll have to choose how far back you go, and just work with the folders in Finder.

      This isn't designed as a replacement for Time Machine, in particular when using Time Machine to restore to a new machine. it's designed for backing up files and folders that you absolutely positively cannot lose. I use it to keep local backups of my web sites, to back up our financial data, and my work files. (This is in addition to all my usual backups, i.e. Time Machine, removable drives, and an offsite drive.)

      Hope that helps...


  4. Thanks for the heads-up. I was able to find a copy of the original on the site, so I updated the link above.


  5. To "keep" previous versions of web contents (HTML / CSS / JS), an even more efficient solution would be a decent versioning tool, like Git. It does automatically what you're doing manually, without hacks, and the ability to retrieve anything since the beginning of times ;-)
    This doesn't scale well with binary data (assuming your financial/work files are not in text-like format), but Git-annex ( may help.

Comments are closed.