diff --git a/infrastructure/docker/image/resources/file-functions.sh b/infrastructure/docker/image/resources/file-functions.sh index d5aadb9..76a709d 100644 --- a/infrastructure/docker/image/resources/file-functions.sh +++ b/infrastructure/docker/image/resources/file-functions.sh @@ -44,16 +44,17 @@ function backup-fs-from-directory() { function restore-directory() { local directory="$1"; shift + local snapshot_id="${1:-latest}"; shift if [ -z ${CERTIFICATE_FILE} ]; then restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} unlock --cleanup-cache rm -rf ${directory}* - restic -v -r $RESTIC_REPOSITORY/${backup_file_path} restore latest --target ${directory} + restic -v -r $RESTIC_REPOSITORY/${backup_file_path} restore ${snapshot_id} --target ${directory} else restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} unlock --cleanup-cache --cacert ${CERTIFICATE_FILE} rm -rf ${directory}* - restic -v -r $RESTIC_REPOSITORY/${backup_file_path} restore latest --target ${directory} --cacert ${CERTIFICATE_FILE} + restic -v -r $RESTIC_REPOSITORY/${backup_file_path} restore ${snapshot_id} --target ${directory} --cacert ${CERTIFICATE_FILE} fi } \ No newline at end of file diff --git a/infrastructure/docker/image/resources/pg-functions.sh b/infrastructure/docker/image/resources/pg-functions.sh index 2ea4e80..7f8a6bf 100644 --- a/infrastructure/docker/image/resources/pg-functions.sh +++ b/infrastructure/docker/image/resources/pg-functions.sh @@ -97,31 +97,34 @@ function backup-db-dump() { } function restore-roles() { - + local snapshot_id="${1:-latest}"; shift + if [ -z ${CERTIFICATE_FILE} ]; then roles-unlock-command - restic -r ${RESTIC_REPOSITORY}/${backup_pg_role_path} dump latest stdin | \ + restic -r ${RESTIC_REPOSITORY}/${backup_pg_role_path} dump ${snapshot_id} stdin | \ psql -d template1 -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \ --no-password else roles-unlock-command --cacert ${CERTIFICATE_FILE} - restic -r ${RESTIC_REPOSITORY}/${backup_pg_role_path} dump latest stdin --cacert ${CERTIFICATE_FILE} | \ + restic -r ${RESTIC_REPOSITORY}/${backup_pg_role_path} dump ${snapshot_id} stdin --cacert ${CERTIFICATE_FILE} | \ psql -d template1 -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \ --no-password fi } function restore-db() { + local snapshot_id="${1:-latest}"; shift + if [ -z ${CERTIFICATE_FILE} ]; then db-unlock-command - restic -r ${RESTIC_REPOSITORY}/${backup_pg_database_path} dump latest stdin | \ + restic -r ${RESTIC_REPOSITORY}/${backup_pg_database_path} dump ${snapshot_id} stdin | \ psql -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \ --no-password else db-unlock-command --cacert ${CERTIFICATE_FILE} - restic -r ${RESTIC_REPOSITORY}/${backup_pg_database_path} dump latest stdin --cacert ${CERTIFICATE_FILE} | \ + restic -r ${RESTIC_REPOSITORY}/${backup_pg_database_path} dump ${snapshot_id} stdin --cacert ${CERTIFICATE_FILE} | \ psql -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \ --no-password fi diff --git a/infrastructure/docker/image/resources/restic-snapshots.sh b/infrastructure/docker/image/resources/restic-snapshots.sh deleted file mode 100755 index ca889ce..0000000 --- a/infrastructure/docker/image/resources/restic-snapshots.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -o pipefail - -function main() { - file_env AWS_ACCESS_KEY_ID - file_env AWS_SECRET_ACCESS_KEY - - restic -r ${RESTIC_REPOSITORY}/files snapshots -} - -source /usr/local/lib/functions.sh -source /usr/local/lib/file-functions.sh - -main