-
-
Save Refhi/d212303dad4d561b1f1aef7a3d86759e to your computer and use it in GitHub Desktop.
Nextcloud 13 snap backup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin | |
user=refhi | |
backups=/home/refhi/backups | |
if [[ $EUID > 0 ]] | |
then echo "Please run as root" | |
exit | |
fi | |
# maintenance mode on | |
nextcloud.occ maintenance:mode --on | |
snap restart nextcloud.php-fpm # nextcloud 13 snap version require this... | |
# 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) | |
bakdir=$backups | |
# config | |
echo "Backing up config files, app files, database files..." | |
rsync -Aax /var/snap/nextcloud/current/ $bakdir/current/ | |
# database | |
echo "Backing up database..." | |
nextcloud.mysqldump > $bakdir/sqlbkp.bak | |
# nextcloud-data | |
echo "Backing up data... without previews" | |
rsync -Aax --exclude=/appdata_*/preview /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 | |
snap restart nextcloud.php-fpm # nextcloud 13 snap version require this... | |
echo "Backup finished." | |
echo "When restoring, don't forget to set the correct permissions." |
Thanks for this, incredibly useful! I've used this as a base and added in creating an encrypted archive of the backup folder. Then I upload that encrypted archive to my backup storage on an ftp server.
I will fork and paste the script in once I've removed all the sensitive information - any comments welcome!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tried to make a sturdy backup script for nextcloud 13 snap
It makes 3 main things :
For restoration I use this (which does not require a database restoration, but saving the sqlbkp.bak seems safer anyway) :