Files
lokale-scripte/rsync-nextcloud/rsync-nextcloud.sh
T
2020-03-27 08:33:41 +01:00

52 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
# this one makes a copy of the whole /var/www/html from sbz
#
# to recover nextcloud data see: https://docs.nextcloud.com/server/13/admin_manual/maintenance/restore.html
#
# rsync args:
# -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
# -r, --recursive recurse into directories
# -l, --links When symlinks are encountered, recreate the symlink on the destination.
# -h, --human-readable Output numbers in a more human-readable format.
PORT="42523"
KEY="./sbz_keyless"
USER_AT_HOST="rob@spaceboyz.net"
## path where home-rob container is mouted into host (on SBZ)
SBZ_MOUNT_PATH=/home/rob/tmp_mnt
## path of the nextcloud instance (on SBZ)
NEXTCLOUD_PATH=/var/www/html/nextcloud
# rsync source -> destination
SOURCE_PATH=/var/www/
DEST_PATH_FILES=/mnt/bfds/rob/backup/server/spaceboyz.net/var_www
# path of the database backups
DEST_PATH_DB=/mnt/bfds/rob/backup/server/spaceboyz.net/mariadb
# mount my lxc container into my home on sbz
ssh -p $PORT -i $KEY $USER_AT_HOST "sudo mount /dev/mapper/vms-home--rob $SBZ_MOUNT_PATH"
# put nextcloud into maintenance, outside the home-rob container
ssh -p $PORT -i $KEY $USER_AT_HOST "sudo sed -i \"s|'maintenance' => false|'maintenance' => true|g\" $SBZ_MOUNT_PATH$NEXTCLOUD_PATH/config/config.php"
# rsync download from sbz
rsync -arlh -e "ssh -p $PORT -i $KEY" $USER_AT_HOST:${SBZ_MOUNT_PATH}${SOURCE_PATH} ${DEST_PATH_FILES}
# turn off nextcloud maintenance, outside the home-rob container
ssh -p $PORT -i $KEY $USER_AT_HOST "sudo sed -i \"s|'maintenance' => true|'maintenance' => false|g\" $SBZ_MOUNT_PATH$NEXTCLOUD_PATH/config/config.php"
# umount my container
ssh -p $PORT -i $KEY $USER_AT_HOST "sudo umount $SBZ_MOUNT_PATH"
### Get all databases
cd $DEST_PATH_DB
curl https://rob.spaceboyz.net/backup_all_databases_cMxNrCTVLBPrNo6qaonojeejCvCepekwssh/dump_all_databases.php
wget https://rob.spaceboyz.net/backup_all_databases_cMxNrCTVLBPrNo6qaonojeejCvCepekwssh/dumps.zip