DEV Community

Cover image for Free automated backups of Obsidian notes to GDrive for Mac, Windows and Linux
Claire Froelich
Claire Froelich

Posted on • Updated on

Free automated backups of Obsidian notes to GDrive for Mac, Windows and Linux

No one wants to lose all their years of note-taking to a spilled cup of coffee on the keyboard.

Obsidian has a robust paid Obsidian Sync proprietary service that enables two-way sync between devices both on and offline, version history and end-to-end encryption. If these features are important to you, I recommend this service.

However, if you just want simple free, automated backups of your local notes to GDrive you have options.

These solutions are scalable in that they only sync file changes and do not copy your entire vault every time.

Free backups for Mac/Windows

Luckily this one is easy. Google has a free Google Drive for Desktop client available for these operating systems that enables automated real-time, two-way syncing of local directories on your computer.

Once installed, follow these instructions to sync your vault folder to GDrive.

Free backups for Linux

Unfortunately there is no Google Drive for Desktop client for Linux today. Here is something I hacked together using FreeFileSync and a shell script run on a 5 minute cron job.

Note FreeFileSync does not encrypt your files. If that is important to you, check out this thread for some solutions.

1. Install FreeFileSync

This tool can be used 100% free for the purposes of this article.

Consider downloading the Donation version with some extra thank-you features if you appreciate their service.

Don't be fooled by the malwaresque look of their website. The service is great, community is friendly, and I haven't been frauded yet since making a donation.

2. Create a new sync configuration

Open FreeFileSync and create a "New" sync configuration from the upper left.

Image description

3. Configure source and destination directories

On the left, select the directory of your Obsidian vault.

On the right, click the cloud icon to configure a connection to your GDrive

Image description

When you click the cloud icon, a connection menu will appear. Authorize a connection to your GDrive, select which drive you will save to, and select a destination directory.

By default, it will sync to the root of your drive - this is messy! I recommend specifying a destination directory for your vault files, (you can create one if it doesn't exist yet). I named mine the same as my local vault, "claire-thinkpad"

Image description

Once set up, your configure screen should look something like below

Image description

FreeFileSync lets you set the sync mode to "mirror" (one-way, left to right), or other sync modes such as "two-way", which in theory would enable you to pull changes from GDrive and share work across multiple devices. I didn't try two-way sync yet - comment if you do and find it useful!

4. Save configuration as a batch job

Once you have your source and destination directories selected, click "Save as" in the upper left

Image description

Accept the defaults and click Save as

Image description

Save the .ffs_batch file inside your vault. For me that was ~/Documents/claire-thinkpad

Image description

5. Create the backup script

First create a shell script file that will execute the sync.

touch ~/cron/backup.sh

You can call it something other than backup.sh.

Paste the below script in the file:

#!/bin/sh

if ping -c 1 google.com >/dev/null 2>&1; then
  # Internet is up, run batch job via FreeFileSync
  env DISPLAY=:1.0 /usr/local/bin/FreeFileSync /home/claire/Documents/claire-thinkpad/SyncSettings.ffs_batch
else
  # Internet is down, do not run cron job
  exit 1
fi
Enter fullscreen mode Exit fullscreen mode

Replace /home/claire/Documents/claire-thinkpad/SyncSettings.ffs_batch with the path to your .ffs_batch file.

The script checks whether you are connected to the internet by pinging google.com. If true, it will execute a headless run of your batch job via FreeFileSync.

I was saved here by Joe Lotz's post about running background jobs with FreeFileSync. The DISPLAY=:1.0 is the trick Joe found to run this headlessly, without opening the GUI.

Test your script

Run ~/cron/backup.sh and then check your GDrive destination folder and see that your files are there. Make sure your local vault is not empty first.

6. Create a cron job to execute your script

In your terminal, run crontab -e to enter the cron editor.

Add this cron job at the bottom of the file :

*/5 * * * * /home/claire/cron/backup.sh
Enter fullscreen mode Exit fullscreen mode

Replace home/claire/cron/backup.sh with the path to your shell script from step 5

This will run your backup script every 5 minutes. Feel free to change to a desired interval, with the help of a cron editor tool or ChatGPT.

There you have it

Your changed files should now sync every 5 minutes, so long as you have internet connection.

Technically, instead of FreeFileSync you could code up your own diff calculator and Google Drive API calls to post changes directly to Google Drive. The benefit of using FreeFileSync is that it will calculate diffs for you out of the box and handle all the Google Drive API logic. Google APIs are not fun.

Top comments (0)