Jump to content
ENnut

Backup individual notebooks with this Applescript

Recommended Posts

Here's an Applescript you can use to back up all your notes into individual .enex notebook files. Only have 6.0.5 Direct Download version, so I can confirm that it works on that version (both on Yosemite and Mavericks).

 

Be sure to set your osx username and that you set a valid path.

 

with timeout of (30 * 60) seconds

tell application "Evernote"

activate

set myFolder to "/Users/USERNAME/Desktop/EvernoteBackup/" -- path to backup folder

delay 7 -- need some time for EN to launch if it's not already running. Raise number if needed.

set myNotebooks to every notebook

repeat with selectedNoteBook in myNotebooks

set theNotebook to (the name of selectedNoteBook)

set theNotes to every note in notebook theNotebook

set myFile to (myFolder & theNotebook & ".enex")

export theNotes to myFile

end repeat

end tell

end timeout

  • Like 1

Share this post


Link to post

Thanks for sharing.

 

Does the ENEX export in AppleScript automatically include Tags, or is there a parameter needed to do that?

Share this post


Link to post

@JMichael,

 

Export includes tags by default.

 

Please post here whether or not the script works for you; you're on Yosemite, right?

Share this post


Link to post

I've made some changes to the script. Among them:

 

• Now will NOT attempt to back up an empty notebook

• Now appends the notebook name with date/time stamp

 

with timeout of (30 * 60) seconds

tell application "Evernote"

activate

set backupFolder to "/Users/USERNAME/Desktop/EvernoteBackup/" -- path to backup folder

delay 7 -- need some time for EN to launch if it's not already running. Adjust as needed.

set allNotebooks to every notebook

repeat with currentNoteBook in allNotebooks

set notebookName to (the name of currentNoteBook)

set allNotes to every note in notebook notebookName

 

if every note in notebook notebookName exists then -- proceed if notebook is not empty

set dateString to (current date) as text -- get the date

set newDatestring to {}

repeat with i in dateString -- change colon in time stamp (changed to slash in Finder) to dash

if (i as string) is ":" then

set end of newDatestring to "-"

else

set end of newDatestring to (i as string)

end if

end repeat

set exportFilename to (backupFolder & notebookName & "-" & newDatestring & ".enex")

export allNotes to exportFilename

end if

 

end repeat

end tell

end timeout

  • Like 2

Share this post


Link to post

Made a few improvements to make this script a little friendlier:

 

• Now confirms that the backup folder path you entered is valid. If it's not valid, you get a notification.

• Now starts the backup faster than previous versions

• Added confirmation dialog on completion with button to view backup folder

 

Be sure to set your backup path on line 3.

 

(Here's my Alfred workflow for this script http://cl.ly/2N3b3D081j1V )

 

with timeout of (30 * 60) seconds

tell application "Finder"

set setBackupfolder to "/Users/USERNAME/Desktop/SOMEFOLDER/" as POSIX file -- set backup folder path

 

-- confirm valid path exists

if setBackupfolder exists then

else

display dialog "The backup path you set does not exist. Please go to line 3, set a valid path and re-run this script." giving up after 99999999

error number -128

end if

set backupFolder to setBackupfolder as text

end tell

 

-- activate evernote

tell application "Evernote"

activate

 

-- wait for evernote to come to the front

tell application "Finder"

set frontAppname to "whatever"

repeat while frontAppname is not "Evernote"

tell application "System Events" to set frontAppname to name of first process where frontmost is true

end repeat

delay 1 -- wait a little more

end tell

 

-- do the backup

set allNotebooks to every notebook

repeat with currentNotebook in allNotebooks

set notebookName to (the name of currentNotebook)

set allNotes to every note in notebook notebookName

if every note in notebook notebookName exists then -- proceed if notebook is not empty

set dateString to (current date) as text -- get the date

set newDatestring to {}

repeat with i in dateString -- change colon in time stamp (changed to slash in Finder) to underscore

if (i as string) is ":" then

set end of newDatestring to "_"

else

set end of newDatestring to (i as string)

end if

end repeat

set exportFilename to (backupFolder & notebookName & " - Backed up on " & newDatestring & ".enex")

export allNotes to exportFilename

end if

end repeat

 

-- confirmation dialog

display dialog "The backup of your Evernote notebooks is complete." buttons {"View Backup Folder", "OK"} default button 2 giving up after 99999999

if the button returned of the result is "View Backup Folder" then

tell application "Finder"

activate

open backupFolder

end tell

end if

 

end tell

end timeout

  • Like 1

Share this post


Link to post

@ENUT...

 

Very nice!!! bravo..

 

how would I append current date to the backup folder name? (~/Documents/bkup(current date))

 

Great script

Share this post


Link to post
9 hours ago, Patricio D. Anguita said:

Hi, I've further elaborated these and other ideas into a (i hope) more capable backup script. See: https://pda0.wordpress.com/2016/10/23/evernote-for-mac-backup/

I've been using it to do full & incremental backups for a while.

I like the implementation of a scheduler, and incremental backups.

Can you identify scenarios and the recovery process; for example

  1. Local database is corrupted, and can't be used
  2. Accidently deleted a notebook
  3. Discovered a note  is missing some critical attachments.  You're sure it was ok last month or maybe 3
  4. Discovered some notes are missing; not sure when they disappeared

Are you aware of the Evernote Note History.
I attempt to duplicate this with my backups
- I use the incremental backups daily that you demonstrate in your script
- I accumulate the files in a backup folder
- Instead of the enex format, I prefer html format
  The notes are exported as individual files, and can be viewed and searched
- When a note is created, it will be exported to the backup folder
   When a note is updated, a new version will be exported 
  So the backup folder contains all versions of the note

 

Share this post


Link to post

Hello, I'll try to elaborate the scenarios you mention:

1- i guess in that case the best option would be to re-download all notes from Evernote Cloud, but if you can't for some reason then you should import latest full backup, then latest incremental backups as needed. For example, I backup a monthly full, weekly and daily so I would need to import full+at most 4 weekly's+at most 7 daily's = 12 imports in the worst case for each notebook.

If you'd like to make this easier, then you can full backup every day, and then just 1 import for each notebook. Or maybe build a script that imports and sorts everything in place.

 

Note that in any case, you'll lose the last day worth of your notes!

 

2- Similar to 1 

3- Same thing, then find the note in the imported notes notebook and retrieve the attachments. 

4. Same thing as 3. You can import several full backups and then use Evernote search function to find it. 

 

It would be pretty easy to modify the script so as to export a single enex file for every note. Would tha be more useful? Take into consideration that HTML files do not preserve tags for example. 

 

 

I am aware of Evernote Note History, I recently had to use it in order to retrieve some attachments which got deleted in the latest big bug.

 

.pd

Share this post


Link to post
22 hours ago, Patricio D. Anguita said:

I've been using it to do full & incremental backups for a while.

Since you are using a Mac, I wonder why you don't just use Time Machine (TM) for Evernote Mac backups?

I have found the TM backup strategy to be superior to the traditional (Windows?) backup strategy using full and incremental backups.  Without having to restore full backups, and then multiple incremental backups, TM provides you with a restore of all of the files/notes at any given point in time.  Although TM does incremental backups (only changed files) on an hourly basis, it combines these to provide a full restore of the latest version at any given point in time.

Just to be clear, EN Mac stores all of its Notes as folders/files, rather than in an actual database.

 

Share this post


Link to post

Actually, I do. I use Time Machine & Crashplan.

The tricky part of those backups is that, AFAIK, its an all-or-nothing approach. Also, I wonder what would happen if you open a EN database from a previous version?

.pd

Share this post


Link to post
1 hour ago, Patricio D. Anguita said:

1- i guess in that case the best option would be to re-download all notes from Evernote Cloud, but if you can't for some reason then you should import latest full backup, then latest incremental backups as needed. For example, I backup a monthly full, weekly and daily so I would need to import full+at most 4 weekly's+at most 7 daily's = 12 imports in the worst case for each notebook.

If you'd like to make this easier, then you can full backup every day, and then just 1 import for each notebook. Or maybe build a script that imports and sorts everything in place.

 

Note that in any case, you'll lose the last day worth of your notes!

 

2- Similar to 1 

3- Same thing, then find the note in the imported notes notebook and retrieve the attachments. 

4. Same thing as 3. You can import several full backups and then use Evernote search function to find it. 

 

59 minutes ago, JMichaelTX said:

Since you are using a Mac, I wonder why you don't just use Time Machine (TM) for Evernote Mac backups?

I'm not thrilled about the recovery process for these backup processes.
My user case is mostly single note data loss, and I favour Note History as a backup model

I also plan for the day Evernote goes dark for a short or extended time.  
I don't want to lose access to my notes.
Having an enex or Time Machine backup won't help

Share this post


Link to post
7 minutes ago, Patricio D. Anguita said:

The tricky part of those backups is that, AFAIK, its an all-or-nothing approach.

Actually, you can restore individual Notes, since each Note is represented by a folder.  Just restore the Note folder to another location, and copy the contents.

8 minutes ago, Patricio D. Anguita said:

Also, I wonder what would happen if you open a EN database from a previous version?

If you restored the entire Evernote folder (while the Evernote app is NOT running), then when you started the Evernote app it should automatically do any conversions that are necessary.  If not, then also restore the Evernote App that is of the same date as the Evernote folder.  Then start the old EN App.  After it has finished loading, then would need to export to ENEX any Notes that you wish to use with your current EN account.

Of course, when you restore the entire Evernote folder, you need to do so disconnected to the Internet.  Otherwise the current EN Cloud will overwrite what you have just restored.  After restoring, then would need to export to ENEX any Notes that you wish to use with your current EN account.

I won't repeat details here, but the short version is that, IMO, it is easier, less burden, to just use TM for my backup, and then, IF I need to restore prior versions of Notes I can't get from EN Note History, then, and only then, incur the overhead of restore/export.

IMO and IME, an actual restore is rarely needed.  So I would rather not incur the pain of export to ENEX until I actually need it, which may be years, or never.  So far, after using Evernote for over 7 years with 16K+ Notes, I have not needed ever to restore from my backup.  I have used the EN Note history a couple of times.

Share this post


Link to post
2 hours ago, JMichaelTX said:

I won't repeat details here, but the short version is that, IMO, it is easier, less burden, to just use TM for my backup,

This has been discussed many times before.  Here is the reference:

Which Strategy Causes the Least Pain/Effort? (Daily backup to ENEX/HTML, or Time Machine Auto-Backup)

Share this post


Link to post

IMO, I use a script, backup both enex AND HTML. I am also  syncing application support/Evernote (peer to peer syncing ) from one mac to two anothers,  And I also do Time Machine on all computers.  I feel SAFE having html. My fear is that evernote will become absolute or self destructive.  As most, I have a lot of very import info in evernote land. 

Share this post


Link to post
12 minutes ago, vixster said:

I am also  syncing application support/Evernote (peer to peer syncing ) from one mac to two anothers

Can you explain the "peer to peer"
Evernote itself syncs your notes

>>My fear is that evernote will become absolute or self destructive.  
   As most, I have a lot of very import info in evernote land. 

This might apply to those users who ignore having backups
Evernote is a useful tool, but I'm prepared to drop out at any time

>>And I also do Time Machine on all computers.

I actually turned off TM for the Evernote folders.
I thought it was a waste of resources considering the limited use as a restore tool

Share this post


Link to post
8 minutes ago, DTLow said:

Can you explain the "peer to peer"
Evernote itself syncs your notes

>>My fear is that evernote will become absolute or self destructive.  As most, I have a lot of very import info in evernote land. 

Not sure what you mean by this.
Evernote is a useful tool, but I'm prepared to drop out at any time

>>And I also do Time Machine on all computers.

I actually turned off TM for the Evernote folders.
I thought it was a waste of resources considering the limited use as a restore tool

Peer to Peer http://lmgtfy.com/?q=peer+to+peer

I do NOT rely on evernote to sync notes. In fact, I do not employ "the cloud."

Evernote fails users.. either self destructing / deleting data on it own as other posters mentioned. It's a very useful tool, however, the company is NOT very responsible in owning up to it's faults. Therefor, I make precautions.

TM backup the rest of the Application Support folder.. not reason to exclude one item.  The overhead is NOT that significant for me. Actually minimal. 

 

Share this post


Link to post
2 minutes ago, vixster said:

very nice.. would you be up for adding html export to this as well? thank you.

Its an easy conversion for html export
The Applescript syntax is     export theNotes to fileBackup format HTML

Share this post


Link to post
34 minutes ago, vixster said:

I do NOT rely on evernote to sync notes. In fact, I do not employ "the cloud."

Odd choice when selecting to use a cloud application
For me, one of the major features is the Evernote cloud aspect
- syncing to my devices
- sharing notes
- cross-linking notes
- OCR and indexing for searches
- another level of data backup

Its not a great idea to use this "peer-to-peer" to sync your Evernote database between devices

Share this post


Link to post
5 minutes ago, DTLow said:

Odd choice when selecting to use a cloud application
For me, one of the major features is the cloud aspect
- syncing to my devices
- sharing notes
- cross-linking notes
- OCR for searching
- another level of data backup

my point is i don't use a "cloud"

for evernote cloud issues... http://bfy.tw/8NAv

 

Share this post


Link to post
16 minutes ago, vixster said:

my point is i don't use a "cloud"
for evernote cloud issues... http://bfy.tw/8NAv

Are you sure you want to use a computer
I can provide you with a search for ....computer issues

Share this post


Link to post
38 minutes ago, DTLow said:

Are you sure you want to use a computer
I can provide you with a search for ....computer issues

Meh, not really! although the only other language I speak is unix! ;) 

Share this post


Link to post
On 10/24/2016 at 8:08 PM, DTLow said:

I also plan for the day Evernote goes dark for a short or extended time.  
I don't want to lose access to my notes.
Having an enex or Time Machine backup won't help

That is incorrect.

As long as I remain signed in to EN Mac, I do NOT need an Internet connection to access my Notes.

IF, and this is a very big IF, the Evernote Service was stopped, I could still access all of my Notes, and then, at that time, export them to HTML (and/or ENEX).  There are other apps/tools that will read ENEX.

To be clear, I cannot imagine that the Evernote Service would suddenly be permanently stopped without any warning.  There would surely be rumors, and, not providing their users with an exit strategy goes against the core of Evernote policy, from the very beginning.

Share this post


Link to post
21 minutes ago, JMichaelTX said:

That is incorrect.

As long as I remain signed in to EN Mac, I do NOT need an Internet connection to access my Notes.

IF, and this is a very big IF, the Evernote Service was stopped, I could still access all of my Notes, and then, at that time, export them to HTML (and/or ENEX).  There are other apps/tools that will read ENEX.

To be clear, I cannot imagine that the Evernote Service would suddenly be permanently stopped without any warning.  There would surely be rumors, and, not providing their users with an exit strategy goes against the core of Evernote policy, from the very beginning.

You mention internet connection - that could be a point of failure
Definitely more real than Evernote suddenly shutting down

And as you said "as long as you remain signed in to EN Mac"
- I actually sign out after a session; its a security thing
I do remain signed in on my iPad, relying on a PIN/fingerprint for security

 

 

Share this post


Link to post
10 minutes ago, DTLow said:

- I actually sign out after a session; its a security thing
I do remain signed in on my iPad, relying on a PIN/fingerprint for security

I rely on my complex password for Mac signin (even after a screen saver is activated) for security.

I see no need to sign out of the EN Mac app.  Since all of the EN Mac notes are in text files (and the attachments are in folders as files), anyone who has access to your Mac user login can get/read these files easily enough, even though they are not signed in to EN Mac app.

Share this post


Link to post
1 minute ago, JMichaelTX said:

I see no need to sign out of the EN Mac app.

I gather you don't use shared computers - home or work

Share this post


Link to post
1 minute ago, DTLow said:

I gather you don't use shared computers - home or work

Each person who uses the same Mac should have their own Mac User account, which will provide the security you need.

If you are allowing  others to use your Mac User credentials then you are opening up yourself to a huge security risk, both intentional, and unintentional.  There is no reason to share a Mac User account.

Share this post


Link to post
16 hours ago, JMichaelTX said:

Each person who uses the same Mac should have their own Mac User account, which will provide the security you need.

If you are allowing  others to use your Mac User credentials then you are opening up yourself to a huge security risk, both intentional, and unintentional.  There is no reason to share a Mac User account.

In and ideal world, we would each use our own Mac user account.  In reality, I simply use the Guest account, open the app (Evernote, browser etc), then close after I'm done.

Share this post


Link to post
17 hours ago, JMichaelTX said:

To be clear, I cannot imagine that the Evernote Service would suddenly be permanently stopped without any warning.  There would surely be rumors, and, not providing their users with an exit strategy goes against the core of Evernote policy, from the very beginning.

Absolutely could! So many companies go out of biz without notification. Backup and protect yourself! Evernote has had problems of disappearing notes as well, as well as disappearing accounts!. sh*t happens.  Export via a scripting on a schedule is fantastic!

Share this post


Link to post
On 10/27/2016 at 10:46 AM, DTLow said:

In and ideal world, we would each use our own Mac user account.  In reality, I simply use the Guest account, open the app (Evernote, browser etc), then close after I'm done.

You make it sound like the "ideal world" of each using their own Mac account is something unattainable.

It is not.  It is very easy to setup.  I see no reason not to do so.

By allowing others to use your login, but then you try to protect your Evernote data by signing out, is like gagging at a gnat, while swallowing an elephant.  LOL

All of your Mac Evernote Notes are easily found by a Spotlight search and/or a Finder Search.  Since they are just text files, anyone can read them.  So what have you really accomplished by signing out of Evernote?  Nothing is the answer.

I really hope no one else is following your bad example.

Share this post


Link to post
On 2016-11-01 at 5:02 PM, JMichaelTX said:

You make it sound like the "ideal world" of each using their own Mac account is something unattainable.

It is not.  It is very easy to setup.  I see no reason not to do so.

My experience is the owners of the shared/public machines aren't always receptive to setting up individual user accounts

To be clear, I'm not letting people use my user id; On my Mac, I have set up Guest Ids

>>All of your Mac Evernote Notes are easily found by a Spotlight search and/or a Finder Search.  Since they are just text files, anyone can read them.  So what have you really accomplished by signing out of Evernote?  Nothing is the answer.

Good point about the searches if you use the Evernote app on a shared/public Mac with the Guest Id
It's safer using web access, but only if you log off

Share this post


Link to post

@ENnut I get 

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

 

on line: export allNotes to exportFilename

 

I've check the exportFilename and it looks fine

 

What should I be checking to solve this 

 

Thx

Share this post


Link to post
6 minutes ago, johnnygoodface said:

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

 

on line: export allNotes to exportFilename

 

I've check the exportFilename and it looks fine

 

What should I be checking to solve this 

It would help if you post the line where you assign a value to exportFilename

As to duplicate postings, there is an Options link under the post.  Clicking on it gives you a delete option.

Share this post


Link to post

Thx for the tip (I've deleted my duplicated posts)

Now about your script: I must apologize because it's working very well today... Don't ask! :huh:

Now I feel much more secure

Cheers!

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...