From 28a70e0eff3394cd4bd7fd79751bd7f98980e39a Mon Sep 17 00:00:00 2001 From: Leon Date: Wed, 14 Aug 2024 14:36:31 +0200 Subject: [PATCH 1/3] Add `CONFIRM_RESTORE` check --- Dockerfile | 1 + README.md | 2 ++ docker-compose.yaml | 1 + src/restore.sh | 9 +++++++++ 4 files changed, 13 insertions(+) diff --git a/Dockerfile b/Dockerfile index 16915d7..94519e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,6 +21,7 @@ ENV S3_S3V4 'no' ENV SCHEDULE '' ENV PASSPHRASE '' ENV BACKUP_KEEP_DAYS '' +ENV CONFIRM_RESTORE 'no' ADD src/run.sh run.sh ADD src/env.sh env.sh diff --git a/README.md b/README.md index 67e2f99..0abc740 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ services: SCHEDULE: '@weekly' # optional BACKUP_KEEP_DAYS: 7 # optional PASSPHRASE: passphrase # optional + CONFIRM_RESTORE: 'no' # optional S3_REGION: region S3_ACCESS_KEY_ID: key S3_SECRET_ACCESS_KEY: secret @@ -34,6 +35,7 @@ services: - Run `docker exec sh backup.sh` to trigger a backup ad-hoc. - If `BACKUP_KEEP_DAYS` is set, backups older than this many days will be deleted from S3. - Set `S3_ENDPOINT` if you're using a non-AWS S3-compatible storage provider. +- If `CONFIRM_RESTORE` is set to `'yes'`, a confirmation prompt will be displayed before restoring from a backup. ## Restore > [!CAUTION] diff --git a/docker-compose.yaml b/docker-compose.yaml index 16ac481..9d5afae 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -17,6 +17,7 @@ services: SCHEDULE: '@weekly' # optional BACKUP_KEEP_DAYS: 7 # optional PASSPHRASE: passphrase # optional + CONFIRM_RESTORE: 'no' # optional S3_REGION: S3_ACCESS_KEY_ID: S3_SECRET_ACCESS_KEY: diff --git a/src/restore.sh b/src/restore.sh index 3040146..e3c75bb 100644 --- a/src/restore.sh +++ b/src/restore.sh @@ -5,6 +5,15 @@ set -o pipefail source ./env.sh +if [ "$CONFIRM_RESTORE" = "yes" ]; then + echo "Are you sure you want to restore the database? This will overwrite the current database. (yes/no)" + read confirm + if [ "$confirm" != "yes" ]; then + echo "Restore cancelled." + exit 1 + fi +fi + s3_uri_base="s3://${S3_BUCKET}/${S3_PREFIX}" if [ -z "$PASSPHRASE" ]; then From d96d32891e75d0999807521c3fd31825378c35be Mon Sep 17 00:00:00 2001 From: Leon Date: Wed, 14 Aug 2024 14:46:12 +0200 Subject: [PATCH 2/3] Add docker exec flag `-i` to restore command in the README The `-i` flag is necessary to interact with the restore script's confirmation prompt --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0abc740..a4ce702 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ services: ### ... from latest backup ```sh -docker exec sh restore.sh +docker exec -i sh restore.sh ``` > [!NOTE] @@ -51,7 +51,7 @@ docker exec sh restore.sh ### ... from specific backup ```sh -docker exec sh restore.sh +docker exec -i sh restore.sh ``` # Development From deaa69925c13d4b6fe95331e73677d2f45f09a44 Mon Sep 17 00:00:00 2001 From: Leon Date: Wed, 14 Aug 2024 14:50:01 +0200 Subject: [PATCH 3/3] Make the restore confirmation message more clear --- src/restore.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/restore.sh b/src/restore.sh index e3c75bb..ad7f219 100644 --- a/src/restore.sh +++ b/src/restore.sh @@ -6,7 +6,7 @@ set -o pipefail source ./env.sh if [ "$CONFIRM_RESTORE" = "yes" ]; then - echo "Are you sure you want to restore the database? This will overwrite the current database. (yes/no)" + echo "DATA LOSS! Are you sure you want to restore the database? This will overwrite the current database. (yes/no)" read confirm if [ "$confirm" != "yes" ]; then echo "Restore cancelled."