Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add restore confirmation #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,22 +35,23 @@ services:
- Run `docker exec <container name> 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]
> DATA LOSS! All database objects will be dropped and re-created.

### ... from latest backup
```sh
docker exec <container name> sh restore.sh
docker exec -i <container name> sh restore.sh
```

> [!NOTE]
> If your bucket has more than a 1000 files, the latest may not be restored -- only one S3 `ls` command is used

### ... from specific backup
```sh
docker exec <container name> sh restore.sh <timestamp>
docker exec -i <container name> sh restore.sh <timestamp>
```

# Development
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions src/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down