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

33 lines
903 B
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
# files
2020-12-12 16:30:45 +00:00
rm -rf /var/backups/*
2020-12-12 18:02:41 +00:00
restic -r $RESTIC_REPOSITORY/files restore latest --target /var/backups/
2020-12-12 15:02:24 +00:00
# db
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}\";"
restic -r ${RESTIC_REPOSITORY}/db restore latest --target test-stdin
psql -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
--no-password < test-stdin/stdin
}
2020-12-12 16:30:45 +00:00
source /usr/local/lib/functions.sh
2020-12-12 15:02:24 +00:00
main