Operating system
Linux
Joplin version
3.2.2
Sync target
Joplin Cloud
What issue do you have?
I have been running "joplin sync", "joplin e2ee decrypt", and "joplin export" shell commands in a cron job to create a backup. What I've noticed recently, though, is that "joplin status" shows un-sync'd and still-encrypted items that have been sync'd, making the exported backup files inconsistent with respect to the sync target.
I believe what's happening is that "e2ee decrypt" (and "sync"?) are processed in the background while joplin is running, but when the commands are executed from the shell, joplin exits before those background tasks are complete.
Is there some way to prevent joplin from exiting until its background tasks have completed?
If one of these commands doesn't complete sync or decryption it's actually a bug that should be fixed. But are you able to replicate this consistently? Also could you please share your cron script just in case the order of commands is not right
Thanks for the quick response. It happened a few times while I was recreating the local repository from Joplin Cloud in hopes of resolving a large number of items (50-100) that couldn't be decrypted (even after using --retry-failed-items) without inspecting each one individually. It took several hours to do the sync (with a few restarts), as I have a fairly large number of notes and attachments:
Note: 17872/17872
Folder: 74/74
Resource: 39821/39821
Tag: 21/21
NoteTag: 22497/22497
Revision: 0/0
Total: 80285/80285
My cron script is written in Perl. I've included it below. The order of joplin operations is in lines 28-36. The rest of the script sets up the name of the backup .jex file for the current date and trims older backup files. I've tried various orderings of the joplin operations, and the one below is just the last one I've tried.
Unfortunately, joplin's premature exits have occurred after hours of sync'ing. Now that I've gotten my tens of thousands of items sync'ed, it probably won't happen again for a while. I could set up a test on a different machine, though, if that would help; just let me know what you'd like observed/logged.
Here's the perl code...
#!/usr/bin/perl
#
# JoplinDailyBackup - Create a Joplin backup file named yyyy-mm-dd.jex after
# synchronizing to make sure everything's up to date.
# The file is written into the directory specified as our
# first argument. The second argument is the number of
# daily backups to keep in the destination directory; we
# delete any older backups.
#
# JoplinDailyBackup /DWMedia/Backups/JoplinDaily/dhwalker 5
#
my $Destination;
my $NKeep;
($Destination,$NKeep) = @ARGV;
die "A Joplin destination directory must be provided!"
unless ((length($Destination) > 0) &&
(-d $Destination));
die "A positive number of days to keep must be specified!"
unless ($NKeep > 0);
my $FileName = `date +%F`;
chomp $FileName;
$FileName = "$FileName.jex";
my $TempDir = `mktemp --directory --tmpdir JoplinDailyBackup.XXXX`;
chomp $TempDir;
chdir $TempDir;
if (system ("/usr/local/bin/joplin sync --use-lock 0" .
" > $TempDir/export.log 2>&1") ||
system ("/usr/local/bin/joplin e2ee decrypt --retry-failed-items" .
" >> $TempDir/export.log 2>&1") ||
system ("/usr/local/bin/joplin sync --retry-failed-items" .
" >> $TempDir/export.log 2>&1") ||
system ("/usr/local/bin/joplin export $Destination/$FileName " .
"--format jex" .
" >> $TempDir/export.log 2>&1"))
{
print STDERR "Backup errored!! Error log follows...\n\n";
print STDERR `cat $TempDir/export.log`;
} else {
print STDERR "Backup successful.\n";
system ("/usr/local/bin/joplin status " .
"| grep --before-context 999 \"# Notebooks\"");
open (PURGE, "ls $Destination/*.jex | sort -r |");
$NKept = 0;
while (<PURGE>)
{
$NKept++;
chomp;
if ($NKept > $NKeep)
{
print STDERR "Removing $_ to stay under $NKeep backups.\n";
system ("rm $_");
};
};
close (PURGE);
};
system ("rm -r $TempDir");