dda-backup/infrastrucure/docker/image/resources/restore.sh

42 lines
1.2 KiB
Bash
Raw Normal View History

2020-12-04 17:10:24 +00:00
#!/bin/bash
2020-12-12 18:02:41 +00:00
set -o pipefail
2020-12-12 15:02:24 +00:00
function main() {
file_env AWS_ACCESS_KEY_ID
file_env AWS_SECRET_ACCESS_KEY
file_env POSTGRES_DB
file_env POSTGRES_PASSWORD
file_env POSTGRES_USER
2020-12-12 18:02:41 +00:00
file_env RESTIC_PASSWORD
2020-12-12 15:02:24 +00:00
2020-12-13 11:49:12 +00:00
# create new db
2020-12-12 15:02:24 +00:00
psql -d template1 -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
--no-password -c "DROP DATABASE \"${POSTGRES_DB}\";"
psql -d template1 -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
--no-password -c "CREATE DATABASE \"${POSTGRES_DB}\";"
2020-12-12 20:01:33 +00:00
2020-12-13 11:49:12 +00:00
# restore roles
restic -v -r ${RESTIC_REPOSITORY}/pg-role dump latest stdin | \
psql -d template1 -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
--no-password
# restore db
restic -v -r ${RESTIC_REPOSITORY}/pg-database dump latest stdin | \
psql -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
--no-password
2020-12-12 20:01:33 +00:00
2020-12-13 11:49:12 +00:00
# files
rm -rf /var/backups/*
restic -v -r $RESTIC_REPOSITORY/files restore latest --target /var/backups/
2020-12-12 15:02:24 +00:00
2020-12-13 11:49:12 +00:00
# adjust trusted domains
php /var/www/html/occ config:system:set trusted_domains 1 --value=cloud.test.meissa-gmbh.de
2020-12-12 15:02:24 +00:00
}
2020-12-12 16:30:45 +00:00
source /usr/local/lib/functions.sh
2020-12-12 15:02:24 +00:00
main