Jump to content
jefito

Other How-To: Backing up Evernote using PowerShell

Recommended Posts

For Valentine's day, I'm offering up a simple Windows PowerShell script that you can use to backup your Evenote notes. It uses the Evernote auxiliary program, ENScript.exe, to export Evernote notebooks to respective Evenote format (.ENEX) files.

The script is very dumb. You'll need to change the script to specify a backup directory location where the backups will land. You may need to change the script to specify the location of ENScript.exe.

The script will create a new directory in that location with a name that's based on the current date, and write the .ENEX files in that directory. There will be a .ENEX file for each notebook (which is what you want, because notebook name is not stored in a .ENEX file, so if you need to restore you can get the source notebook from the .ENEX filename).

Note: I am not a PowerShell expert, and while I've tested the script, it may not be particularly robust in the face of errors. In normal use it appears to work, but use it at your own risk. This script comes with a no-money-back guarantee. Oh, and feel free to modify it for your own use, or offer changes / suggestions / comments. I may or may not respond. You'll notice I have a list of Todos in the script. I may or may not deliver on those either.

You may need to change your execution policy to let this script operate properly. The command I used was: "Set-ExecutionPolicy RemoteSigned". In addition, you may want to make a Windows shortcut for the script. You'll need to search the web for that, but it can be done.

Take the following code and save it as a PowerShell script file Ii.e., with an extension ".PS1") somewhere that PowerShell can find it. I called mine "ENBackup.PS1". Creative, no?

# Simple Evernote backup PowerShell Script
#
# Backs up all notebooks in your account as .enex files, located in a designated
# directory. The backup directory name is generated by a base name with the
# current date (mm-dd-yy) appended.
#
# Todo:
# * Specify backup directory base via command-line
# * Backup single notebook specified via command-line
# * Restore notebook

# You may need to modify this according to the location of ENScript.exe
$ENscript = "C:\Users\Jeff\AppData\Local\Apps\Evernote\Evernote\ENScript.exe"

# Modify backup directory base as desired
$BackupLocation = "E:\Backups\Evernote\"

# Write out notebook names to a temporary file, one line at a time
$tempfile = "notebooks.txt"
& $ENscript listNotebooks >$tempfile
$reader = [System.IO.File]::OpenText($tempfile)

# Create a backup directory for this date
# Get current date (mm-dd-yy) and append it to the backup directory base
$date = get-date -uformat "%m-%d-%y"
$BackupDir = $BackupLocation + "Backup " + $date
# Make the actual backup directory
if ( ! (Test-Path $BackupDir) )
{
     md $BackupDir
}

# Process notebook names
try
{
    for( ; ; )
     {
          # fetch a notebook name
        $name = $reader.ReadLine()
        if ($name -eq $null) { break }
         
          # write out the backup file for this notebook: <notebook name>.enex
          "Backing up " + $name + "..."
          $BackupFileName = $BackupDir + "\" + $name + ".enex"
          & $ENscript exportNotes /q "notebook:$name" /f $BackupFileName
    }
     # Show your work
     dir $BackupDir
}
finally
{
    $reader.Close()
}
# delete the temp file
remove-item $tempfile

 

Have fun & Happy Valentine's Day for all of the Evernoters!!!

2/24/14 - Edit: Fixed ENScript exportNotes query. It was missing the 'notebook:' specifier. Also fixed problems with notebooks containing spaced in their names.

  • Like 5

Share this post


Link to post

For those of you who prefer Cherry Cokes, cars with fins, or that rich 8-bit sound, you can always go retro with a DOS batch file:
 
 

@echo offset enbackup=c:\Archive\Evernote\SimpleBackupset notelist=Notebooks.txtecho Backing up Evernote notebooks to %enbackupif not exist %enbackup% md %enbackup%del /q %enbackup%\*.enexenscript listNotebooks >%notelist%for /f "delims="  %a in ( Notebooks.txt) do (echo %a... & enscript exportnotes /q notebook:"%a" /f "%enbackup%\%a.enex")dir %enbackup%set enbackup=set notelist=

Edit: Warning! The above .bat file doesn't work under the standard CMD command shell. I tested this using the more capable TCC command shell, where it all works well. I'll try to update this for CMD when feasible.

Share this post


Link to post
For those unfamiliar with "codes" and "scripts" like me :(, you can use this alternative method.

 

Choose your Evernote Database folder, which can be seen from Tools-> Options -> Open Database folder.

 

Map the directory path to an automated, backup Software, and periodically run the software and back up your database to an external hard disk. :)
  • Like 2

Share this post


Link to post

 

For those unfamiliar with "codes" and "scripts" like me :(, you can use this alternative method.
 
Choose your Evernote Database folder, which can be seen from Tools-> Options -> Open Database folder.
 
Map the directory path to an automated, backup Software, and periodically run the software and back up your database to an external hard disk. :)

 

These methods were created expressly to help out people who don't want to monkey around with .exb files. The .enex file format is text, and XML-based, so may be more portable than binary .exb files, and more readily accessible to writing programs / scripts to process them. Aside from that, these methods will work even if Evernote is currently active, which, as far as I can tell doesn't work with copying the .exb file.

  • Like 1

Share this post


Link to post

Doesn't work for any notebook that has a name containing any accentuated characters on my computer.

The ENScript listNotebooks commands is the problem, it replaces every accentuated character with a pair of characters!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...