Homepage    |    GitHub    |    API    |    Wiki    |    FAQ

Best method to backup notes

We use Evernote at work, and I’ve been using it personally as well. As part of researching Joplin as a replacement for work i’m going to use it personally for the next month or so. I have it syncing to Nextcloud running on a personal server.
Currently trying without encryption.
I exported my notebook from Evernote, and imported it, and that all looks good. I see my directory is filled with .md files now, and the pictures are in .resource on the sync target as well.
I was experimenting with how best to automate backups and what I tried doing was using Nextcloud to sync the target directory to a computer. This gives me all of the .md files somewhere else. I then tried importing the “md directory” which works in importing, but all of the notes are the filenames of the .md files. Not really sure what the original note name.
So, I thought, “What’s the best way to back up Joplin?”
Anyone else?

3 Likes

Best way, if you can, is to use the command line tool along with the export command and export at a regular intervals from a cron script. Even better if you can version this in a Git repository.

This is the cron script I use for backup:

#!/bin/bash

# 0 0 10,15/12 * * /home/laurent/scripts/joplin_bak.sh >> /var/log/joplin_bak.log 2>&1

BACKUP_DIR="/path/to/backup_dir"
JOPLIN_BIN="$HOME/.npm-global/bin/joplin"

$JOPLIN_BIN sync
$JOPLIN_BIN e2ee decrypt

cd "$BACKUP_DIR"
rm -f *.md
rm -f resources/*
$JOPLIN_BIN --log-level debug export --format raw "$BACKUP_DIR"
git add .
git commit -m "Update"

I have this running because I often run dev versions of Joplin so I need a robust backup in case I mess up, but for normal use a simple export to JEX format is sufficient. Unlike the ENEX format, JEX is a lossless format so you can export and re-import and get everything back including tags, resources, notebooks, and all metadata.

An alternative to all this is indeed to backup the sync directory. That might be easier to automate and Nextcloud should also keep a history so you get benefits similar to using Git.

8 Likes

Thank you for your reply Laurent.

I tried something: Nextcloud has my ‘joplin’ target directory in it, and is synced to computer A. I created a new directory in Nextcloud called ‘testjoplin’. I copied the contents of the ‘joplin’ directory to the ‘testjoplin’ directory, hidden directories included. Then on Computer B I clean installed Joplin, and pointed it at Nextcloud…/testjoplin

It then synced and everything looked just like it should. I have a computer that’s always on, and is syncing Nextcloud, and that directory is getting backed up with versioning. I think this will suffice for me.
The other thing I played with was using Nextcloud’s versioning to restore an individual .md to a previous version. This did not work as expected. Joplin on Windows desktop will keep showing the note as it last was, but using the text viewer on Nextcloud shows that .md file as being a previous version. I’m probably just missing something.

Yes that doesn’t work because when you restore an earlier version it will have a timestamp that’s earlier than the one that’s on your computer. So Joplin compares the versions, see that the one on your computer is more recent and therefore keeps this one.

There’s no simple way to restore just one note from sync at the moment unfortunately. You would need to do it manually - i.e. restore the note, copy the body, and paste it in the note on your computer.

fair enough. Figure if it’s bad enough I need an older version it’s either a one time thing where copy/paste would suffice, or i’m redoing the entire directory in which case my previous test works too.

Hello,

I am also looking for a way to do periodic automated backups using a cronjob on Linux. But from the Desktop version, not Terminal.

Of course I could point the terminal version to use the database of the Desktop version, but this seems untested (https://github.com/laurent22/joplin/issues/332).
I could of course set the terminal version to sync with the Desktop version, but somehow this seems not right (having the database three times on my harddrive: Desktop-Version, Sync-Directory and Terminal-Version). What would you recommend? Is it enough to just backup the database (database.sqlite file in the Joplin directory)?

Greetings,
Stefan

You could backup the sync directory as that would give you more control if you ever want to restore only some files. Otherwise backing up the entire profile folder would be fine too, but you can’t restore individual items.

1 Like

Thanks. I´m gonna use one of these two options.

2 posts were split to a new topic: Export and import while preserving note IDs

Hi Laurent,
I like your solution and am trying to implement it. I installed Joplin on OSX from the .dmg installer file. If I point to the binary
JOPLIN_BIN="/Applications/Joplin.app/Contents/MacOS/joplin"

Joplin ignores the command line arguments and just opens the UI. How do I get it to run in command line mode?

Thanks
Steve

You would need to install and setup the CLI app, as that’s what’s being used in the cron script.

Hi,

I'm very new to all this, slowly but surely moving away from "proprietary" solutions, so hope you won't loose your patience with my questions :wink:

If I "read" your script properly

BACKUP_DIR="/path/to/backup_dir" --> you specify the backup directory

JOPLIN_BIN="$HOME/.npm-global/bin/joplin" --> you are saying where the Joplin.bin file is

$JOPLIN_BIN sync --> are you here synchronizing the version on your desktop? Which means you have a sync version somewhere else, and you make sure you sync everything before backing up, right?

$JOPLIN_BIN e2ee decrypt --> is this needed all the time? Let's say I don't use encryption for my notes, but maybe Joplin.bin is encrypted? I will most likely use encryption, but just checking my understanding. So this means you are backing up a non crypted version of the app, correct?

cd "$BACKUP_DIR" --> you (the script) goes into the backup directory

rm -f *.md --> delete all pre-existing md file

rm -f resources/* --> delete all pre-existing file in the resources folder --> I saw that resources folder in the pack content (I'm on Mac), but are those resources backed up when you only back up the Joplin.bin file?

$JOPLIN_BIN --log-level debug export --format raw "$BACKUP_DIR" --> log-level debug I guess is a type of log, a txt file to show you if everything went well, and if not what could it be, correct? Then you export in RAW format, into the backup directory, correct? Why not in JEX? Is it because your backup is only for the app (since you are the developper)? So I guess I could change that to JEX for my own script right?

git add . --> I read it is adding the file to the indexation, correct?

git commit -m "Update" --> I read it changes the head, what is it? Where? Does it change the name of the file?


Reason why I tried to understand is I'd like to create a script to back up my notes, ie, basically have a script which makes :

  • a JEX export to a specific location (I believe I can use part of your script to do that)

  • on a regular basis --> from your script it seems to be a script you run manually?

  • And ideally, I'd like to keep x versions, so have a check on how many version there is in the back up directory, if I have "maxed out" the number of version, delete the most ancient one, and add the new one. So if I want to keep 5 versions, and there are already 5, delete the oldest one, and create the new one.

I would appreciate if:

  1. You can confirm I understood the script properly
  2. If you (anyone reading this thread in fact) can support me with terminal code achieving what I would like to do :slight_smile:

Thanks,

Virginie

I think your understanding of the script is correct. You indeed can remove e2ee decrypt if you are not using encryption, and you would need to setup the CLI tool for sync (see https://joplinapp.org/terminal for info on how to do this).

And I picked the RAW format so that each note, notebook, etc. is in its own single file as it’s easier to version.

Perhaps try the script and check what files it generates to see if it fits your purpose.

For reference:

Backup: GIT

Backup: JEX

3 Likes

Why are there no command line arguments for the standard application? If I’m on Windows I need a second installation in WSL to make this work.

2 Likes

Are there any plans to add command line arguments to the Windows Joplin to allow automating backing up?

5 Likes

topic: Serverbased backup

Hi all,
I'm using joplin-server (dockerized) and really happy.
if I understood @laurent correctly it's sufficient, backing up the postgreSQL database.

What I've found in the forums is a few one liners for a Postgres dump.

What I use from cron is the following script, that might be useful for people hosting an own
joplin-server

Best regards Bjoern

#!/usr/bin/env bash
#
# dump of the PG Database in Joplin
#
# 2021-07 Bjoern Runden <br@chamaeleoncloud.de>
#

# Where is PSQL Data found in dockerized PostgreSQL
DOCKERPGDIR=/var/lib/postgresql/data/psql-backup

# Where does joplin server / PostgreSQL container reside on host:
HOSTPGDIR=/containers/joplin-server/data/postgres/psql-backup

# Docker instance name is normally like this
DOCKERINSTANCE=joplin-server_db_1

# e.g. Debian user for owning Containers (maybe numerical user id is more useful)
OSUSER=systemd-coredump

if [ ! -d $HOSTPGDIR ] ; then
        echo "directory not existent. Creating..."
        mkdir -p $HOSTPGDIR
        chown -R $OSUSER: $HOSTPGDIR
else
        echo "directory is here. Fine!"
fi

# do the backup
docker exec $DOCKERINSTANCE sh -c "pg_dumpall -U joplin > ${DOCKERPGDIR}/$(date +%Y-%m-%d)_psql.backup.sql"

# cleanup for files older than 7 days
find $HOSTPGDIR/* -mtime +7 -exec rm {} \;

2 Likes

thanks for the script.

I'm getting an error on the 'joplin export' line (14) saying the joplin command was not found https://i.imgur.com/0mpZxuD.png

any idea why?! obviously I installed joplin on the machine

You have to adjust the following 2 vars: NODEJS_GLOBAL_HOME and NODEJS_HOME

Which Joplin? The terminal app?

2 Likes

Thank you, works great!

I just added gzip -c to the dump to keep the file size small.

# do the backup
docker exec $DOCKERINSTANCE sh -c "pg_dumpall -U joplin | gzip -c > ${DOCKERPGDIR}/$(date +%Y-%m-%d)_psql.backup.sql"