Going Paperless: How and Why I’ve Automated Backups of My Evernote Data

Short post today as I am in L.A. for work and insanely busy. I’m actually writing this post from the bar in my hotel and it is last night, after a roughly 15 hour day of work. So please forgive any brevity.

Once a month, export all of my Evernote data to an ENEX file, which sits on an external disk. That file, in turn, gets backup by my cloud backup service, CrashPlan. It may seem kind of silly to back up notes that are already stored in the cloud, but I have what I think is one really good reasons for backing up my data.

Why I backup my Evernote data

Backing up data–even data in the cloud that is generally readily accessible–acts as a kind of insurance policy. I am planning ahead for the unexpected. Being prepared for the unexpected is something that I picked up back in my flying days, when all kinds of little problems might crop up, and being able to decide whether or not they were serious was important.

In truth, what I am preparing for is my inevitable screw up. I know that at some point in time, I am bound to so something unintentionally destructive. Perhaps, after working hard many days, with little sleep, I accidentally drag an important notebook to the trash, and then purge the trash before I realized what happened. Once that happens, and Evernote syncs with the server, the notes are unrecoverable.

That might seem extreme, and perhaps it is. But I’ve worked with technology (and been a professional in the IT field) long enough to know that I am eventually bound to screw up. Having a backup of my notes provides some measure of protection against those screw-up, and that is the main reason that I back up my Evernote data.

How I backup my Evernote data

I work primarily on a Mac, and so I wrote an AppleScript to take advantage of Evernote’s AppleScript interface to automate the process of backing up my Evernote data.

You can find my AppleScript on GitHub.

Evernote Backup

The script is pretty simple. It selects all notes after January 1, 1990, and exports them to an ENEX file on a specified path. I chose that date because it will backup any notes after that date. If you’ve created notes and dated them prior to 1990, you’ll want to change line 10 of the script to reflect the appropriate date.

You’ll also want to update line 5 with the path on your machine that you want the export file to reside. In my code, I’ve export mine to an external drive that is backed up by my cloud backup service.

When I run the script, it selects all of the notes that meet the criteria and then exports them. I have more than 8,000 notes so this takes a little while. I set the timeout to 30 minutes, which is usually plenty of time for me. When the export is complete, the script then compresses the export file so that it is a little smaller when it is backed up to my cloud backup service.

Automating the process

As it stands, the script has to be run manually. To automate the process, I use an app called Lingon, which makes it easy to schedule jobs on the Mac. I have my script run once a month (usually on the first day). Once the job is setup in Lingon, the script runs automatically.

Restoring from the export

“In the unlikely event of a water landing,” as they say, optimistically before your flight… I’ve done some testing of restoring ENEX files into Evernote, and the process works very well. All of the notes are restored, including the tags. But the notes are all restored to a single “restore” notebook. This actually makes sense, because you might be restoring a small set of notes and don’t want to overwrite existing notes. I was able to import the ENEX file, see all of my notes, and then manually move them into the appropriate notebooks. A little cumbersome, yes, but if I’ve made a dumb mistake that requires me to restore notes from backups, I’m happy to do a little extra work.

What about Windows?

As I said, I primarily work on a Mac. It is possible to script exports on Windows, but it is from the command line using command line options of Evernote itself. Since I don’t use Windows as my primary Evernote repository, I haven’t investigated this. But I’m pretty sure it is possible.

ETASee the first comment for a good example of how to automate your backups in Windows.

ETA 8/16: For folks who have been reporting an error with the script, see Scott’s comment below. Apparently, the error only occurs in version of Evernote downloaded from the App Store. If you download Evernote from Evernote.com, you won’t see any error. My guess is that the error from the App store version has something to do with sandboxing.

If you have a suggestion for a future Going Paperless post, let know me. Send it to me at feedback [at] jamietoddrubin.com. As always, this post and all of my Going Paperless posts is also available on Pinterest.

Last week’s post: How I Use Playbooks with Evernote.

Enjoy these posts? – Tell a friend

Recommending readers is one of the highest compliments you can pay to a writer. If you enjoy what you read here, or you find the posts useful, tell a friend! Find me online here:

Twitter | Facebook | Google+ | Reddit |  Blog | RSS

Or use one of the share buttons below. Thanks for reading!

35 thoughts on “Going Paperless: How and Why I’ve Automated Backups of My Evernote Data

  1. For Windows, I use a batch file (which in my case is simply a .cmd shell script) with the following command:

    “c:\Program Files (x86)\Evernote\Evernote\ENScript.exe” exportNotes /q any:* /f X:\Evernote\%date:~-4,4%%date:~-7,2%%date:~-10,2%_bkp_Evernote.enex

    Which will generate a file named something like 20140808_bkp_Evernote.enex in my X:\evernote folder (which for me is connected to a NAS) containing all of my notes. This could be filtered down as you point out in the blog post.

    The command breakdown is:

    – We use the ENScript.exe utility, suplying the ‘exportNotes’ command.
    exportNotes takes two options: /q to retrieve the notes to export, and /f

    – for the query, we just select all the notes doing a search for any:* — but could also be filtered using the search grammar adding notebook:something and tag:something filters.

    – To generate the filename, we use the %DATE% environment variable name, but printing it ‘as is’ would give us a string like 04/05/2014, which has problematic slashes. We also want to reverse the format. This is done with a slight modification on the one-liner answer by Jess Stone on this post http://superuser.com/questions/47885/windows-command-line-create-a-file-with-the-current-date-in-its-name leading to %date:~-4,4%%date:~-7,2%%date:~-10,2%

    – I’m also appending _bkp_Evernote.enex to the exported file to match my file naming convention.


  2. I’m a certifiable backup freak so I appreciate your instinct, but I wonder if this adds enough marginal security to justify the effort, particularly if your organization has to be restored (although I can see ways around that).

    I figure that Evernote’s own Shard 1 is my first backup; Time Machine is my second; CrashPlan is my third. Is that enough, or not?

  3. Thank you for your very sharp-minded ideas! The biggest (bad) surprise for me is the apparent impossibility to recover any Evernote notebook you would have deleted!
    Are you sure you can’t fix it, at least for a premium user as you?

  4. Hi Jamie
    Thanks. I’ve never knowingly run an Applescript in my life never mind edited one. However your script is currently running backing up my, meagre, 2265 notes. Next I’ll try Automating it with Lingon – or could I use Automator for that?

    I really enjoy the blog, keep up the great work!

    best wishes

  5. Great info. Love to hear more about your use of Crashplan and any hints you may have on speeding up the back up process (initial). Thanks!

  6. Hi Jamie,

    Thanks for the idea, I’ve created a Windows script that does the same thing with a couple of extra items on GitHub. It also performs a sync before the backup, then creates a note saying the backup was successful.

    Alton(ius) Blom

  7. I like the reasoning for the backup. Eventually everyone makes a mistake. I’ve gotten quite heavy into evernote usage, and I think it might be wise to start doing backups.

  8. I’m wondering … I make a backup of my HD to Time Machine and Crashplan. Isn’t that enough? Isn’t Time Machine (and Crashplan) taking a backup of the Evernote files on my HD? Or am I wrong here?

  9. Fl6anders, I think you are good for disaster recovery. Same for me with Crashplan. But I like the export because it exports the notes in an open (XML) format that allows me to recover from non-disasters. That is, rather than my drive blowing up, I accidentally trash all notes tagged “receipts” or something like that. If I restored from the Evernote data store on my Mac, the restore would potentially overwrite other notes I’ve created outside of the notes I deleted. By restoring from the XML file (ENEX) I can pick and choose which notes I want to restore, and not disturb any notes I might have created between my last backup and my mistake.

  10. It’s fine for full disaster recovery, but I’m worried about non-disasters–accidents of my own doing, where I don’t want to restore *all* of my notes, just some of them. This gives me a mechanism to pick and choose what I want to restore without overwriting notes that might have been created or modified in the meantime.

  11. On the Mac you can use cron and osascript (the command line AppleScript runner) to perform these backups automatically instead of manually. Open a terminal and enter crontab -e (or, if you don’t like the default vi editor, you can use env EDITOR=nano crontab -e to use nano (much more user-friendly) as a crontab editor.

    Following is an example of how it works—this is the crontab I use to run some AppleScripts to pull information into Evernote as well as apply some tagging (use man crontab to learn how it works):

    01 00 * * * osascript /Users/steven/Library/Mobile\ Documents/com\~apple\~ScriptEditor2/Documents/All\ Received\ SMSs\ from\ Yesterday.scpt
    01 00 * * * osascript /Users/steven/Library/Mobile\ Documents/com\~apple\~ScriptEditor2/Documents/Yesterday\'s\ Financial\ Transactions.scpt
    01 00 * * * osascript /Users/steven/Library/Mobile\ Documents/com\~apple\~ScriptEditor2/Documents/Notes\ created\ yesterday.scpt
    02 00 * * * osascript /Users/steven/Library/Mobile\ Documents/com\~apple\~ScriptEditor2/Documents/Notes\ modified\ yesterday.scpt
    00 0,6,12,18 * * * osascript /Users/steven/Library/Mobile\ Documents/com\~apple\~ScriptEditor2/Documents/Add\ Annual\ Tags.scpt

  12. This is a great post, but I’m running into an issue. At the “export matches to f” line I’m getting:

    error "Evernote got an error: The operation couldn’t be completed. Operation not permitted" number 1

    I tried exporting to different locations, all of which are set with 777 permissions. No dice. Any idea why this would be happening?

    BTW, same result on OS X 10.7.5 and 10.9.4 (two different Macs).

  13. It also could be that the account the AppleScript is running as doesn’t own the file. You could try adding the phrase “with administrator privileges” to the end of the line in question, e.g.:

    export matches to f with administrator privileges

    This will force the script to prompt you for a login/password, but might also confirm that you need to change ownership of the file.

  14. I got the same ‘Operation not permitted exception’. I tried to append ‘with administrator privileges’ but then I get the following error ‘Expected end of line, etc. but found idnetifier’

  15. I encountered the same problem. I think that the script doesn’t create the .enex file if it doesn’t exist. I created a file with the correct name by exporting a single note directly from Evernote, and then the script ran to completion.

  16. I’m getting the same error. I’m trying to write to my user directory, so I definitely have permissions.

  17. Try as I might, I can’t reproduce the error. I installed the script on my new Macbook Air just now and ran it, exporting the note my Documents folder, and it runs without an error. I can’t think of what my cause it–except maybe file ownership?

  18. Yeah, I’m baffled. As I said above, I just copied the script to a new machine and ran it there without any error. This is what it looks like for me:

    Export Script

    If anyone has ideas as to why the error might be cropping up, I’m all ears.

  19. I had a similar issue too. After doing some digging, I realized that it was because I was using the App Store version of Evernote. Once I uninstalled that version and downloaded/installed the Evernote.com version, it worked great!

    BTW – thanks for the script, JTR!

  20. What a great idea! I’m a huge Evernote (Premium) user and this is quite helpful. I wasn’t really satisfied with having all my notes in one export file though and the hack with the 1990 date bothered me, so I rewrote the script. This version asks Evernote of a list of its notebooks, then exports every note in each notebook to its own file. Hope this is helpful!

    set exportPath to path to documents folder as text

    with timeout of (30 * 60) seconds
    tell application “Evernote”
    repeat with nb in every notebook of application “Evernote”
    set theName to the name of nb

    set matches to find notes “notebook:” & “\”” & theName & “\””
    set f to exportPath & theName & “.enex”
    export matches to f
    if (count of matches) > 0 then
    set p to POSIX path of f

    do shell script “/usr/bin/gzip -f ” & quoted form of p

    end if
    end repeat
    end tell

    end timeout

  21. There is an app/website that is growing in popularity that automates a whole host of tasks, and you can create your own “recipe” too.


    It stands for “If This Then That.” It seems to be free right now, so I don’t know if they will charge in the future.

    I am fairly new to it, but I’d assume you should be able to archive Evernote to something like DropBox, or Google Drive.

  22. I like Brent Neal’s modification to export entire notebooks vs. one huge backup. However, I am a fan of keeping multiple backups, so I tweaked the code to append the current date to the name of the backup files plus create the target directory (also w/ the backup date) if it doesn’t already exist

    — PURPOSE: Export all notes in Evernote to an ENEX file so that
    — the notes can be backed up to an external drive or to the cloud

    set curDate to do shell script “date +’%Y%m%d'”

    — Change the path below to the location you want the notes to be exported
    set exportPath to “/Volumes/Data/bkp/Evernotxe-” & curDate & “/”

    do shell script “if [ ! -e ” & exportPath & ” ]; then mkdir ” & exportPath & “; fi;”

    do shell script “mkdir ” & exportPath

    with timeout of (30 * 60) seconds
    tell application “Evernote”
    repeat with nb in every notebook of application “Evernote”
    set theName to the name of nb

    set matches to find notes “notebook:” & “\”” & theName & “\””
    set f to exportPath & theName & “-” & curDate & “.enex”
    export matches to f
    if (count of matches) > 0 then
    set p to POSIX path of f

    do shell script “/usr/bin/gzip -f ” & quoted form of p

    end if
    end repeat
    end tell

    end timeout

  23. I think there are two other ways you could automate this with Automator, and it wouldn’t require purchasing another program.

    1. Create an application with the script, and add it to your login items. Every time you start your computer, it would run. The downside is that it will use resources at your login, and if you login/restart often, you’d end up with a lot of backups. But if you only login/restart every two to four weeks, an application would work.

    2. Setup a Calendar alarm via Automator. You could then specify a repeat date (1st of month) and the script would automatically run.

    Although I haven’t specifically tried it with this script, I have a couple of Automator workflows that do #1 and #2 for various tasks.

Comments are closed.