Created
July 2, 2018 05:58
-
-
Save YourFriendCaspian/abfa88a9b299d3a19fc5cd4201c16caa to your computer and use it in GitHub Desktop.
Backup script for Nextcloud on the Odroid-C2
This file contains hidden or 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 | |
# Credit and special thanks to Carsten Rieger from https://www.c-rieger.de/ | |
# for creating this script. | |
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on | |
BACKUP_STORE=/backup_work_dir | |
ARCHIVE_STORE=/home/ubuntuusername/backup_dir | |
CURRENT_TIME_FORMAT="%w" | |
echo "START: $(date)" | |
FOLDERS_TO_BACKUP=( | |
"/root/" | |
"/etc/fail2ban/" | |
"/etc/letsencrypt/" | |
"/etc/mysql/" | |
"/etc/nginx/" | |
"/etc/php/" | |
"/etc/ssh/" | |
"/etc/pam.d/" | |
"/etc/ssl/" | |
"/var/www/" | |
) | |
ARCHIVE_FILE="$ARCHIVE_STORE/ncserver_$(date +$CURRENT_TIME_FORMAT).tar.gz" | |
cd $BACKUP_STORE | |
for FOLDER in ${FOLDERS_TO_BACKUP[@]} | |
do | |
if [ -d "$FOLDER" ]; | |
then | |
echo "Copying $FOLDER..." | |
rsync -AaRx --delete $FOLDER $BACKUP_STORE | |
else | |
echo "Skipping $FOLDER (since it does not exist)" | |
fi | |
done | |
cp /etc/fstab $BACKUP_STORE/etc/ | |
mysqldump --single-transaction -h localhost -unextcloud -pnextcloud nextcloud > $BACKUP_STORE/ncdb_`date +"%w"`.sql | |
mysql -e "SELECT table_schema 'DB',round(sum(data_length+index_length)/1024/1024,4) 'Size (MB)' from information_schema.tables group by table_schema;" | |
mkdir -p $(dirname $ARCHIVE_FILE) | |
tar -cpzf $ARCHIVE_FILE . | |
echo "Serverbackup size: $(stat --printf='%s' $ARCHIVE_FILE | numfmt --to=iec)" | |
rm $BACKUP_STORE/*.sql | |
tar -cpzf $ARCHIVE_STORE/ncdata_`date +"%w"`.tar.gz -C /var/nc_data . | |
echo "Databackup size: $(stat --printf='%s' $ARCHIVE_STORE/ncdata_`date +"%w"`.tar.gz | numfmt --to=iec)" | |
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --off | |
echo "END: $(date)" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment