Best method to backup notes

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"

You were correct, I hadn't installed the terminal app, just the desktop :blush:

When I run the script it now returns 'There is no data to export'. I assume I need to edit to include the path to where my joplin deskop data is stored, but I don't understand what to edit.

Would you please mind elaborating what the 2 vars: NODEJS_GLOBAL_HOME and NODEJS_HOME need adjusted to?

According to this message, it seems you don't have to set the 2 vars, but rather configure the terminal client to use the same sync target as your dekstop app.

May I ask, why you are using a script and the terminal app when you can also do the backups with the desktop app? I don't want to sound harsh, but it looks like you are not really familiar with the command line.

No offence taken, my terminal knowledge is rather sparse.

I'm trying to do backups with the terminal app so I can automate the backing up of the .jex file instead of doing it manually. But seems trickier than I thought, I will leave this for now, thanks for your help.

For an automatic backup on the desktop app, you can use the Simple Backup plugin.

3 Likes

I just wanted to suggest JackGruber's backup plugin as well. (Since he's in Europe, he read your answer before me... :wink: )

Also, don't forget: If you use the terminal app on the same machine as the desktop app, you will use twice the space for notes. Each of these apps use their own local storage and you also have to use a comnmon sync target.

I really think that using the backup plugin might be the best solution in your case.

1 Like

@JackGruber:
Does your plugin also work with the portable version of Joplin?

Yes

@JackGruber :
Seems to work perfect. Suggestion: Can you implement a notification when the backup has been finished? Or some kind of status bar...