Backup nextcloud

https://www.c-rieger.de/nextcloud-installation-guide/#sechs

Create a shellscript and let cron handle your regulary backups automatically

Creat a shellscript

Create the backup.sh file

sudo -i
mkdir -p /work/nextcloud_backup
vi ~/backup.sh

and paste the following lines

#!/bin/bash
CURRENT_TIME_FORMATE="%Y-%m-%d_%H-%M-%S"
BACKUP_FOLDER=/work/nextcloud_backup
FOLDERS_TO_BACKUP=(
  "/var/www/"
  "/etc/apticron/"
  "/etc/php/"
  "/etc/nginx/"
  "/etc/fail2ban/"
  "/etc/postfix/"
  "/etc/letsencrypt/"
  "/etc/ssl/"
  )
ARCHIVE_FILE="/home/<your_user>/bkup/nextcloud_backup_$(date +$CURRENT_TIME_FORMATE).tar.gz"
echo "START: $(date +$CURRENT_TIME_FORMATE)"
cd $BACKUP_FOLDER
for FOLDER in ${FOLDERS_TO_BACKUP[@]}
do
if [ -d "$FOLDER" ];
then
echo " Copying $FOLDER..."
rsync -AaRx --delete $FOLDER $BACKUP_FOLDER
else
echo " Skipping $FOLDER since it does not exist"
fi
done
echo " Creating SQL Dump..."
mysqldump --lock-tables -unextcloud_db_user -pnextcloud_db_password nextcloud_db --add-drop-table --allow-keywords --complete-insert --quote-names > $BACKUP_FOLDER/nextcloud_backup.sql
echo " Creating archive $ARCHIVE_FILE..."
mkdir -p $(dirname $ARCHIVE_FILE)
tar -czf $ARCHIVE_FILE .
echo " Size of archive: $(stat --printf='%s' $ARCHIVE_FILE | numfmt --to=iec)"
echo " Cleaning up..."
rm $BACKUP_FOLDER/nextcloud_backup.sql
echo "END: $(date +$CURRENT_TIME_FORMATE)"
echo "----------------------------------------"
mail -s "nextcloud Backup - $(date +$CURRENT_TIME_FORMATE)" your@email.com < /home/user/bkup/cron.log
exit 0

Create a cron-job

sudo -i
sudo crontab -u root -e

<- edit crontab-file

55 23 * * * /root/backup.sh >> /home/next/bkup/cron.log

Make the script executable

sudo -i
chmod +x ~/backup.sh