Skip to content

Instantly share code, notes, and snippets.

@berguner
Forked from kapcom01/nextcloud-snap-backup.sh
Created January 12, 2021 15:36
Show Gist options
  • Save berguner/9a7dc550a522faf592e25bf9832a324d to your computer and use it in GitHub Desktop.
Save berguner/9a7dc550a522faf592e25bf9832a324d to your computer and use it in GitHub Desktop.
#! /bin/bash
user=manolis
backups=/home/manolis/backups
if [[ $EUID > 0 ]]
then echo "Please run as root"
exit
fi
# maintenance mode on
nextcloud.occ maintenance:mode --on
# if there is no backups directory then create it
if [ ! -d $backups ]
then
mkdir $backups
chown $user:$user $backups
fi
bakdir=$backups/backup-$(date +%Y%m%d)
# config
echo "Backing up config file..."
rsync -Aax /snap/nextcloud/current/htdocs/config/config.php $bakdir/
# database
echo "Backing up database..."
nextcloud.mysqldump > $bakdir/sqlbkp.bak
# nextcloud-data
echo "Backing up data..."
rsync -Aax /var/snap/nextcloud/common/nextcloud/data/ $bakdir/nextcloud-data/
# owner manolis:manolis
chown -R $user:$user $bakdir
# maintenance mode off
nextcloud.occ maintenance:mode --off
echo "Backup finished."
echo "When restoring, don't forget to set the correct permissions."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment