github twitter linkedin instagram email
backing up Evernote to git

I love Evernote, but I don’t trust it to never lose my data. The Mac app syncs all your notes locally in an HTML format, so you can get some protection by doing automated backups of its folder (which is within ~/Library/Application Support/com.evernote.Evernote/accounts/ with a backup service like CrashPlan.

I thought it would be nice to additionally commit the notes to a git repository. The script below will:

  1. Force Evernote to sync.
  2. Export notes in HTML format into a git repo, using separate subdirectories for each notebook, and commit the changes. (All files in the repo are git rm’d before starting the export, so that notes which no longer exist will be deleted in the commit.)
  3. Display a notification with stats about the commit.

example notification

I originally tried exporting using the enex file format instead - which dumps all data into one large file - but I found that the repo’s size grew out of control due to excessive changes in that output. This hasn’t been an issue with the HTML export so far, even though updates to the application do sometimes cause a large number of the exported files to be altered. Since metadata like tags and created/updated time are included as meta tags in the exported HTML files, I don’t think anything important is lost by using the HTML format rather than the enex format.

You can set this up to run automatically by putting the launchd config below into ~/Library/LaunchAgents/ and either rebooting, or running launchctl load ~/Library/LaunchAgents/net.brokensandals.evernote.backup.html.plist.

(In this gist, backup_dir should be changed to point to an initialized, empty git repo where you want to store the exports, and /Users/jacob/dotfiles/bin/ should be replaced with wherever you install the script.)

Tags: code

Back to posts