Backup scripts

Signed-off-by: Simó Albert i Beltran <sim6@bona.gent>
Simó Albert i Beltran 2022-02-12 06:56:44 +01:00
parent 077cd77e07
commit 2d3d0ba0a9
2 changed files with 65 additions and 0 deletions

35
sysadm/dd-backup Executable file
View File

@ -0,0 +1,35 @@
#!/bin/bash -e
# bash needed to trap ERR
BACKUP_SERVER="${BACKUP_SERVER-$(hostname)@192.168.100.2}"
trap maintenance_disable SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM ERR
maintenance_disable(){
docker-compose exec -T isard-apps-moodle php7 admin/cli/maintenance.php --disable
docker-compose exec -T -u www-data isard-apps-nextcloud-app php occ maintenance:mode --off
docker-compose run isard-apps-wordpress-cli wp maintenance-mode deactivate
}
cd /opt/src/digitaldemocratic/
docker-compose exec -T isard-apps-moodle php7 admin/cli/maintenance.php --enable
docker-compose exec -T -u www-data isard-apps-nextcloud-app php occ maintenance:mode --on
docker-compose run isard-apps-wordpress-cli wp maintenance-mode activate
mkdir -p /opt/digitaldemocratic/db_dump
docker-compose exec -T isard-apps-postgresql pg_dumpall -U admin > /opt/digitaldemocratic/db_dump/postgres.sql
docker-compose exec -T isard-apps-mariadb sh -c 'mysqldump -p"$MYSQL_ROOT_PASSWORD" --all-databases --all-tablespaces' > /opt/digitaldemocratic/db_dump/mariadb.sql
docker-compose exec -T isard-apps-redis redis-cli SAVE
docker-compose exec -T isard-apps-redis cat dump.rdb > /opt/digitaldemocratic/db_dump/redis.rdb
rsync -aHAX --del /opt/digitaldemocratic/ $BACKUP_SERVER:opt_digitaldemocratic/
rsync -aHAX --del /opt/src/ $BACKUP_SERVER:opt_src/
date +"%Y-%m-%d_%H:%M:%S" | ssh $BACKUP_SERVER tee backup_date
maintenance_disable

30
sysadm/dd-borg Executable file
View File

@ -0,0 +1,30 @@
#!/bin/sh -e
BACKUP_SERVER="${BACKUP_SERVER-dd-backups@backup.digitaldemocratic.net}"
BORG_PASSCOMMAND="${BORG_PASSCOMMAND-cat $HOME/.borg-passphrase}"
wait_backup(){
if ! [ -f /home/$1/backup_date ]
then
exit
fi
current_date="$(date +"%Y-%m-%d")"
while ! [ "$current_date" = "$(cut -b1-10 /home/$1/backup_date)" ]
do
sleep 60
if [ "$current_date" != "$(date +"%Y-%m-%d")" ]
then
echo "No backup for $1 at $current_date" >&2
exit 1
fi
done
export BORG_PASSCOMMAND
borg create ssh://$BACKUP_SERVER/~/$1.borg::$(cat /home/$1/backup_date) /home/$1
borg prune -d7 -w4 -m12 -y5 ssh://$BACKUP_SERVER/~/$1.borg
}
for item in $(ls /home)
do
wait_backup $item &
done