System-Backup/system-backup

58 lines
1.7 KiB
Plaintext
Raw Normal View History

2021-01-06 21:08:40 +01:00
#!/bin/bash
2021-01-07 00:09:29 +01:00
# Show help page
2021-01-06 21:08:40 +01:00
if [ "$1" = "-h" ]
then
2021-01-07 00:09:29 +01:00
echo "system-backup <option>"
2021-01-06 21:08:40 +01:00
echo
echo "If no options are specified it will use default"
echo
echo "Options:"
echo
2021-01-07 00:09:29 +01:00
#echo "-d [USB Dir]"
echo
2021-01-06 21:08:40 +01:00
echo
exit 0
fi
2021-01-07 00:09:29 +01:00
# if [ "$1" = "-d" ]
# then
# sudo mount "$2"
# sudo mkdir -p $backup_dir"/nextcloud"
# sudo mkdir $backup_dir"/mysql"
# sudo mkdir $backup_dir"/gitea"
# sudo screen -dmS backup -t backup rsync -Aav --progress $nextcloud_dir/ $backup_dir"/nextcloud"
# else
# sudo mount /dev/sdb0
# sudo mkdir /mnt/USB/Backup-whole-System/
# sudo screen -dmS backup -t backup
# fi
2021-01-06 22:33:41 +01:00
2021-01-07 00:09:29 +01:00
# Initialize variables
backup_dir="/mnt/USB/Backup/"$(date +'%Y/%m/%d')
backup_dir_remote="/media/backup/"$(date +'%Y/%m/%d')
nextcloud_dir="/var/www/nextcloud"
gitea_dir="/var/"
remote_ip="192.168.178.48"
# Back the fuck up bro...
# Shuting down services for backup
cd $nextcloud_dir
sudo -u www-data php occ maintenance:mode --on
sudo apache2 stop
sudo mysqldump --single-transaction nextcloud > /tmp/mysqldump/nextcloud.sql
cd /usr/local/bin
sudo -u git ./gitea dump -c /etc/gitea/app.ini
sudo ssh backup@$remote_ip sudo mkdir -p $backup_dir_remote
sudo screen -dmS backup -t backup bash -c "rsync -Aavr --progress -e ssh $nextcloud_dir backup-user@$remote_ip:$backup_dir_remote/nextcloud;
rsync -Aavr --progress -e ssh $gitea_dir backup-user@$remote_ip:$backup_dir_remote/gitea;
rsync -Aavr --progress -e ssh /tmp/nextcloud.sql backup-user@$remote_ip:$backup_dir_remote/mysql/;
rsync -Aavr --progress -e ssh /tmp/gitea.sql backup-user@$remote_ip:$backup_dir_remote/mysql/"
#To-Do
# gitea dump permissions
# rsync test
# cleanup
# starting back up