Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tihomircolev/612524d4e4fc8453efad6e28778a3fce to your computer and use it in GitHub Desktop.
Save tihomircolev/612524d4e4fc8453efad6e28778a3fce 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