Skip to content

Instantly share code, notes, and snippets.

@Refhi
Forked from kapcom01/nextcloud-snap-backup.sh
Last active October 10, 2024 12:14
Show Gist options
  • Save Refhi/d212303dad4d561b1f1aef7a3d86759e to your computer and use it in GitHub Desktop.
Save Refhi/d212303dad4d561b1f1aef7a3d86759e to your computer and use it in GitHub Desktop.
Nextcloud 13 snap backup script
#! /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."
@sinbadsalmon
Copy link

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