add backup and restore scripts

This commit is contained in:
Jan Krebs 2020-11-19 16:01:11 +01:00
parent bcd04af38b
commit 556eb5abf3
2 changed files with 18 additions and 0 deletions

View file

@ -0,0 +1,6 @@
set -o pipefail
# backup database dump
pg_dump -d $(cat ${POSTGRES_DB_FILE}) -h $POSTGRES_SERVICE -p $POSTGRES_PORT -U $(cat ${POSTGRES_USER_FILE}) --no-password --serializable-deferrable --clean --no-privileges | \
restic -r $RESTIC_REPOSITORY --verbose backup --stdin --tag DB_Backup
# backup nextcloud filesystem
restic -r $RESTIC_REPOSITORY backup /var/backups/ --tag Nextcloud_Filesystem

View file

@ -0,0 +1,12 @@
# Restore Nextcloud Filesystem
# Reads restore snapshot_ID from first CLI Argument
restic -r $RESTIC_REPOSITORY restore $1 --target /
# Delete DB
psql -d template1 -h $POSTGRES_SERVICE -p $POSTGRES_PORT -U $(cat ${POSTGRES_USER_FILE}) --no-password -c "DROP DATABASE \"cloud\";"
# Create DB again
psql -d template1 -h $POSTGRES_SERVICE -p $POSTGRES_PORT -U $(cat ${POSTGRES_USER_FILE}) --no-password -c "CREATE DATABASE \"cloud\";"
# create folder from db backup
restic -r $RESTIC_REPOSITORY restore $2 --target test-stdin-$2
# read folder and restore db entries
psql -d $(cat ${POSTGRES_DB_FILE}) -h $POSTGRES_SERVICE -p $POSTGRES_PORT -U $(cat ${POSTGRES_USER_FILE}) --no-password < test-stdin-$2