Backing up Obsidian on Mac with rsync

I’ve written about the importance of backups scattered throughout my notes. For months now, I’ve been using Obsidian for all my writing (everything in Markdown). I wanted to make sure the files in my vault weren’t just sitting in iCloud, but also synced with my local Mac and my server on Uberspace. Automatically, of course.

Took me a while to get it right.

Here’s my setup so I can replicate it later (and so can you):

  1. My Obsidian vault lives in iCloud in the Obsidian/texts directory. I’d prefer not having it in the cloud, but I use the vault across multiple Macs. Didn’t want to mess around with Git like I used to.

  2. Every hour, I copy the iCloud directory to a local folder on my MacBook. Plus I sync the vault with a texts directory on my server. Multiple backups: cloud, local, server (and on an external drive when I remember to back up my Mac).

Here’s a script that lives on my Mac in /user/macbookpro called sync_icloud.sh:

#!/bin/bash

# Define the source and target directories
src="/Users/macbookpro/Library/Mobile Documents/iCloud~md~obsidian/Documents/texts/"
local_target="/Users/macbookpro/texts/"
remote_target="youruser@yourserver.de:texts/"

# Sync the iCloud directory to the local target directory
rsync -avh --delete "$src" "$local_target"

# Sync the local target directory to the remote target directory
rsync -avhz -e "ssh" --delete "$local_target" "$remote_target"

Make the script executable:

chmod +x ~/sync_icloud.sh

For hourly updates, edit your crontab:

crontab -e

Add this line (syncs every hour):

0 * * * * /Users/macbookpro/sync_icloud.sh

Test if the script works manually first:

./sync_icloud.sh

Now everything should work and you’ll have backups of your Obsidian vault contents.


The German original lives at reinergaertner.de, my blog since before most of the internet existed (1997). Translation: AI. Quality control: me, squinting. Apologies in advance.