Notifications after backup

Hello all,

Good day.

i recenrly started making some backups of my Nextcloud to an external hdd (config file, apache sites-available, mysqldump, etc) using a bash script and addedd it to /etc/crontab under root.

everything works fine, maintenance mode gets enabled and disabled.

at the very end of the script, i have a command to send a notification to a user in Nextcloud saying “Backup complet” using the occ notification:generate user “xxx” which also works, but instead of just one notification, i get around 20.

is this a normal behaviour or am i missing something?

your advice is much appreciated.!

Regards!

I wouldn’t say that this is normal, because I’m receiving a message only once.

What happens if you execute the command manually?
Are you executing the script as the web server user or a different one?
Are you execution the occ command as web server user or a different one?

this is the script im running as root:

#! /bin/bash

sudo -u www-data /var/www/html/nextcloud/occ maintenance:mode --on

rsync -Aaxh /var/www/html/nextcloud/ /media/backup/Nextcloud-bak/nextcloud-bak_date + '%m-%d-%Y'/

mysqldump --all-databases > /media/backup/MySQL-bak/databases_date + '%m-%d-%Y'.sql

rsync -Aaxh /etc/apache2/sites-available/ /media/backup/Apache-conf-bak/apache-bak_date + '%m-%d-%Y'/

sudo -u www-data /var/www/html/nextcloud/occ maintenance:mode --off

sudo -u www-data /var/www/html/nextcloud/occ notification:generate username “Backup Completed”

if i run manually sudo -u www-data /var/www/html/nextcloud/occ notification:generate username “Backup Completed” i only get 1 notification.

i hope this helps.

That’s strange. I have no idea how this could happen. For testing purposes you can try to write a lock-file at the beginning of the script or the command to find the root cause of the problem, like

if [ ! -f /tmp/xxx.lock ]
then
    touch /tmp/xxx.lock
    ...
    exec commands
    ...
    rm -f /tmp/xxx.lock
fi

it is weird the amount of notifications.
once cleared everything is good to go, and looking at the script, everything seems to be ok…

Regards!

1 Like

i just noticed that i had the “Admin Notifications” app enabled and was last updated about 1.5 years ago.

i just uninstalled it and removed it.

another thing that i noticed is that im no longer receiving the notifications on my cellphone screen, so not sure if because i had that old app.

i had another run at the script last night and i got 25 notifications saying “Backup Complete” on Nextcloud

Another run and another 25 notifications… :man_shrugging:

Have you tried to use the recommended lock mechanism?
Have you tried to trace the script execution to find out if the script call is executed multiple times? You can e.g. add the following lines to the beginning of the script to activate tracing:

#!/bin/sh

exec 2>/tmp/trace-$$.log
set -x
...

so i ran a trace as recommended and i found this on the /tmp/ folder:

-rw-r–r-- 1 root root 507 Jan 10 01:00 trace-3843.log
-rw-r–r-- 1 root root 507 Jan 10 01:01 trace-3946.log
-rw-r–r-- 1 root root 507 Jan 10 01:02 trace-4000.log
-rw-r–r-- 1 root root 507 Jan 10 01:03 trace-4042.log
-rw-r–r-- 1 root root 507 Jan 10 01:04 trace-4084.log
-rw-r–r-- 1 root root 507 Jan 10 01:05 trace-4162.log
-rw-r–r-- 1 root root 507 Jan 10 01:06 trace-4206.log
-rw-r–r-- 1 root root 507 Jan 10 01:07 trace-4248.log
-rw-r–r-- 1 root root 507 Jan 10 01:08 trace-4290.log
-rw-r–r-- 1 root root 507 Jan 10 01:09 trace-4334.log
-rw-r–r-- 1 root root 507 Jan 10 01:10 trace-4555.log
-rw-r–r-- 1 root root 507 Jan 10 01:11 trace-4614.log
-rw-r–r-- 1 root root 507 Jan 10 01:12 trace-4656.log
-rw-r–r-- 1 root root 507 Jan 10 01:13 trace-4698.log
-rw-r–r-- 1 root root 507 Jan 10 01:14 trace-4740.log
-rw-r–r-- 1 root root 507 Jan 10 01:15 trace-4787.log
-rw-r–r-- 1 root root 507 Jan 10 01:16 trace-4865.log
-rw-r–r-- 1 root root 507 Jan 10 01:17 trace-4916.log
-rw-r–r-- 1 root root 507 Jan 10 01:18 trace-4959.log
-rw-r–r-- 1 root root 507 Jan 10 01:19 trace-5004.log
-rw-r–r-- 1 root root 507 Jan 10 01:20 trace-5047.log
-rw-r–r-- 1 root root 507 Jan 10 01:21 trace-5106.log
-rw-r–r-- 1 root root 507 Jan 10 01:22 trace-5164.log
-rw-r–r-- 1 root root 507 Jan 10 01:23 trace-5206.log
-rw-r–r-- 1 root root 507 Jan 10 01:24 trace-5249.log
-rw-r–r-- 1 root root 507 Jan 10 01:25 trace-5293.log
-rw-r–r-- 1 root root 507 Jan 10 01:26 trace-5337.log
-rw-r–r-- 1 root root 507 Jan 10 01:27 trace-5411.log
-rw-r–r-- 1 root root 507 Jan 10 01:28 trace-5452.log
-rw-r–r-- 1 root root 507 Jan 10 01:29 trace-5494.log
-rw-r–r-- 1 root root 507 Jan 10 01:30 trace-5538.log
-rw-r–r-- 1 root root 507 Jan 10 01:31 trace-5585.log
-rw-r–r-- 1 root root 507 Jan 10 01:32 trace-5650.log
-rw-r–r-- 1 root root 507 Jan 10 01:33 trace-5709.log
-rw-r–r-- 1 root root 507 Jan 10 01:34 trace-5751.log
-rw-r–r-- 1 root root 507 Jan 10 01:35 trace-5795.log
-rw-r–r-- 1 root root 507 Jan 10 01:36 trace-5839.log
-rw-r–r-- 1 root root 507 Jan 10 01:37 trace-5882.log
-rw-r–r-- 1 root root 507 Jan 10 01:38 trace-5956.log
-rw-r–r-- 1 root root 507 Jan 10 01:39 trace-6016.log
-rw-r–r-- 1 root root 507 Jan 10 01:40 trace-6221.log
-rw-r–r-- 1 root root 507 Jan 10 01:41 trace-6280.log
-rw-r–r-- 1 root root 507 Jan 10 01:42 trace-6322.log
-rw-r–r-- 1 root root 507 Jan 10 01:43 trace-6364.log
-rw-r–r-- 1 root root 507 Jan 10 01:44 trace-6438.log
-rw-r–r-- 1 root root 507 Jan 10 01:45 trace-6503.log
-rw-r–r-- 1 root root 507 Jan 10 01:46 trace-6549.log
-rw-r–r-- 1 root root 507 Jan 10 01:47 trace-6599.log
-rw-r–r-- 1 root root 507 Jan 10 01:48 trace-6641.log
-rw-r–r-- 1 root root 507 Jan 10 01:49 trace-6683.log
-rw-r–r-- 1 root root 507 Jan 10 01:50 trace-6757.log
-rw-r–r-- 1 root root 507 Jan 10 01:51 trace-6817.log
-rw-r–r-- 1 root root 507 Jan 10 01:52 trace-6859.log
-rw-r–r-- 1 root root 507 Jan 10 01:53 trace-6901.log
-rw-r–r-- 1 root root 507 Jan 10 01:54 trace-6943.log
-rw-r–r-- 1 root root 507 Jan 10 01:55 trace-7003.log
-rw-r–r-- 1 root root 507 Jan 10 01:56 trace-7079.log
-rw-r–r-- 1 root root 507 Jan 10 01:57 trace-7138.log

inside the trace file is this:

  • sudo -u www-data /var/www/html/nextcloud/occ maintenance:mode --on
    ++ date +%m-%d-%Y
  • rsync -Aaxh /var/www/html/nextcloud/ /media/backup/Nextcloud-bak/nextcloud-bak_01-10-2020/
  • mysqldump --all-databases
    ++ date +%m-%d-%Y
    ++ date +%m-%d-%Y
  • rsync -Aaxh /etc/apache2/sites-available/ /media/backup/Apache-conf-bak/apache-bak_01-10-2020/
  • sudo -u www-data /var/www/html/nextcloud/occ maintenance:mode --off
  • sudo -u www-data /var/www/html/nextcloud/occ notification:generate username ‘Backup Completed’

crontab shows this:

  • 1 * * * root bash /home/username/backup_script.sh

not sure if i have an error on crontab making it run 60 minutes from 1am to 2 am.

Regards!!

i think i found my issue…
in /etc/crontab i had the script to run all minutes of 1 am
*1 * * * root bash /home/username/backup_script.sh

i believe the correct would be
0 1 * * * root bash /home/username/backup_script.sh

ill provide an update tomorrow to confirm.

Indeed that seems to be the problem. My assumption was that the script would be
executed multiple times, that’s why I recommended to implement a lock mechanism,
but I didn’t expect such a simple error :wink:

* * * * * command to execute
┬ ┬ ┬ ┬ ┬
│ │ │ │ │
│ │ │ │ └──── day of week (0-7, Sunday is 0 or 7)
│ │ │ └────── month (1-12)
│ │ └──────── day (1-31)
│ └────────── hour (0-23)
└──────────── minute (0-59)

thank you for the help on getting this resolved. :smile: