Introduced snapshot_id for restore

This commit is contained in:
Clemens 2023-03-10 15:19:09 +01:00
parent 5f5e061e36
commit f60f8c8adf
3 changed files with 11 additions and 22 deletions

View file

@ -44,16 +44,17 @@ function backup-fs-from-directory() {
function restore-directory() { function restore-directory() {
local directory="$1"; shift local directory="$1"; shift
local snapshot_id="${1:-latest}"; shift
if [ -z ${CERTIFICATE_FILE} ]; if [ -z ${CERTIFICATE_FILE} ];
then then
restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} unlock --cleanup-cache restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} unlock --cleanup-cache
rm -rf ${directory}* 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 else
restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} unlock --cleanup-cache --cacert ${CERTIFICATE_FILE} restic -v -r ${RESTIC_REPOSITORY}/${backup_file_path} unlock --cleanup-cache --cacert ${CERTIFICATE_FILE}
rm -rf ${directory}* 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 fi
} }

View file

@ -97,31 +97,34 @@ function backup-db-dump() {
} }
function restore-roles() { function restore-roles() {
local snapshot_id="${1:-latest}"; shift
if [ -z ${CERTIFICATE_FILE} ]; if [ -z ${CERTIFICATE_FILE} ];
then then
roles-unlock-command 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} \ psql -d template1 -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
--no-password --no-password
else else
roles-unlock-command --cacert ${CERTIFICATE_FILE} 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} \ psql -d template1 -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
--no-password --no-password
fi fi
} }
function restore-db() { function restore-db() {
local snapshot_id="${1:-latest}"; shift
if [ -z ${CERTIFICATE_FILE} ]; if [ -z ${CERTIFICATE_FILE} ];
then then
db-unlock-command 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} \ psql -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
--no-password --no-password
else else
db-unlock-command --cacert ${CERTIFICATE_FILE} 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} \ psql -d ${POSTGRES_DB} -h ${POSTGRES_SERVICE} -p ${POSTGRES_PORT} -U ${POSTGRES_USER} \
--no-password --no-password
fi fi

View file

@ -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