ansible/roles/unhb_backup_scripts/templates/restic-backup_unhb2.sh.j2

32 lines
980 B
Django/Jinja
Executable file

#!/bin/bash
source /opt/scripts/restic/restic.env
source /opt/scripts/restic/restic_db_passwords.env
#We will have to find out whether or not we need to initialize the repo. A non-zero exit code indicates that it has not yet been initialized.
restic snapshots
if [ "$?" -eq "0" ]
then
echo "Repo is already initialized, no need to do that."
else
echo "We need to initialize the repo first." && restic init
fi
echo "Now dumping databases, this might take a while..."
set -x
docker exec -t pretix_pg-sql.server2 pg_dumpall -c -U prtxdb > /opt/db_dumps/db-dump-pretix_db.sql
source /opt/scripts/restic/restic_db_passwords.env
docker exec -t engel_sql.server2 sh -c "exec mysqldump --all-databases -uroot --password=$MARIADB_PASSWORD_ENGELSYSTEM" > /opt/db_dumps/db-dump-engelsystem_db.sql
set +x
restic backup --host="{{ inventory_hostname }}" --verbose \
/etc \
/home \
/opt \
/root \
/srv \
/var/lib/docker/volumes/ \
/var/www
echo "done! :)"