From 5da4970b2095b9f0d51ca5c5bdd55bc24994e3f4 Mon Sep 17 00:00:00 2001 From: drivebyer Date: Mon, 11 Mar 2024 16:00:29 +0800 Subject: [PATCH] update PG logical backup --- arm64/images/logical-backup/actions.sh | 3 +++ arm64/images/logical-backup/restore.sh | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100755 arm64/images/logical-backup/restore.sh diff --git a/arm64/images/logical-backup/actions.sh b/arm64/images/logical-backup/actions.sh index fddee03aa..687729659 100755 --- a/arm64/images/logical-backup/actions.sh +++ b/arm64/images/logical-backup/actions.sh @@ -10,6 +10,9 @@ action=${1:-"dump"} if [ "$action" = "delete" ]; then echo "Delete backup..." /bin/bash /delete.sh +elif [ "$action" = "restore" ]; then + echo "Restore backup..." + /bin/bash /restore.sh else echo "Dump backup to remote..." /bin/bash /dump.sh diff --git a/arm64/images/logical-backup/restore.sh b/arm64/images/logical-backup/restore.sh new file mode 100755 index 000000000..af03e7f6f --- /dev/null +++ b/arm64/images/logical-backup/restore.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -xe + +echo "Downloading backup from S3..." +rclone config create s3 s3 endpoint ${S3_ENDPOINT} access_key_id ${S3_ACCESS_KEY_ID} secret_access_key ${S3_SECRET_ACCESS_KEY} +rclone copy s3:${BAK_FILE_PATH} / +gunzip /$(basename $BAK_FILE_PATH) +echo "Restore backup to database..." +export PGPASSWORD=$PG_PASS +psql -h $PG_HOST -p $PG_PORT -U $PG_USER < /$(basename $BAK_FILE_PATH .gz) + +echo "Restore completed!" \ No newline at end of file