1

I've made a little bash script to backup my nextcloud files including my database from my ubuntu 18.04 server. I want the backup to be executed every day. When the job is done I want to reseive one mail if the job was done (additional if it was sucessful or not). With the current script I reseive almost 20 mails and I can't figure out why. Any ideas?

My cronjob looks like this:

* 17 * * * "/root/backup/"backup.sh >/dev/null 2>&1

My bash script

#!/usr/bin/env bash

LOG="/user/backup/backup.log"

exec > >(tee -i ${LOG})

exec 2>&1

cd /var/www/nextcloud

sudo -u www-data php occ maintenance:mode --on

mysqldump --single-transaction -h localhost -u db_user --password='PASSWORD' nextcloud_db > /BACKUP/DB/NextcloudDB_`date +"%Y%m%d"`.sql

cd /BACKUP/DB
ls -t | tail -n +4 | xargs -r rm --


rsync -avx --delete /var/www/nextcloud/ /BACKUP/nextcloud_install/
rsync -avx --delete --exclude 'backup' /var/nextcloud_data/ /BACKUP/nextcloud_data/

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

echo "###### Finished backup on $(date) ######"


mail -s "BACKUP" name@domain.com < ${LOG}
Maggus
  • 21
  • 2

1 Answers1

0

Are you sure about the CRON string? For me this means "At every minute past hour 17".

Should be more like 0 17 * * *, right?

tpschmidt
  • 2,479
  • 2
  • 17
  • 30
  • 1
    I will try that out. Thank you very much. Any idea how to get information about the rsync status so that I can receive a mail that indicates if the job was successful or not? – Maggus Jul 16 '20 at 15:37
  • I guess rsync will also exit with a proper status code on error/success which you can check with `$?` (0 = success, 1 = error). This should be useful. – tpschmidt Jul 16 '20 at 16:04
  • I will give it a try. and post it here ;-) – Maggus Jul 16 '20 at 17:32