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..a4ce702 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] @@ -41,7 +43,7 @@ services: ### ... from latest backup ```sh -docker exec sh restore.sh +docker exec -i sh restore.sh ``` > [!NOTE] @@ -49,7 +51,7 @@ docker exec sh restore.sh ### ... from specific backup ```sh -docker exec sh restore.sh +docker exec -i sh restore.sh ``` # Development 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..ad7f219 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 "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." + exit 1 + fi +fi + s3_uri_base="s3://${S3_BUCKET}/${S3_PREFIX}" if [ -z "$PASSPHRASE" ]; then