Skip to content

Commit

Permalink
fix typo in restore
Browse files Browse the repository at this point in the history
  • Loading branch information
Leen15 committed Apr 9, 2024
1 parent e85d434 commit 4b58eea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ RESTORE_FILE_PATH=

Flowing environment variables can be set to change the functionality:
```
BACKUP_CRON_SCHEDULE=* * * * *
BACKUP_TGT_DIR=/backup/ // always with trailing slash at the end!
BACKUP_SRC_DIR=/data/ // always with trailing slash at the end!
BACKUP_FILE_NAME=backup
Expand All @@ -45,7 +44,7 @@ Restoring a backup from S3 bucket can be done independently or in combination wi
> Latest backup is considered the newest file inside `BACKUP_S3_BUCKET` and its subdirectories with a `*.gz` extension.
#### Restore and backup
This functionality will find the latest backup and restore it on `BACKUP_SRC_DIR`. It will then start the backup cron job. This is mainly intended for environments where the backed up directory may move between machines.
This functionality will find the latest backup and restore it on `BACKUP_SRC_DIR`. This is mainly intended for environments where the backed up directory may move between machines.

Imagine you are backing up the data directory of a docker container running a database. If an automatic process (like ECS scheduler) stops the database container and starts is on a new machine, you dont want to have an empty database. In this case this image will restore the last backed up status of database and will also backu it up in future when new changes have happened.

Expand Down
6 changes: 3 additions & 3 deletions restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
if [ -z "$RESTORE_FILE_PATH" ]; then
echo "finding last backup..."
# find last object in bucket
LAST_OBJ=`/usr/bin/aws s3 ls s3://${BACKUP_S3_BUCKET}/ --recursive | grep ".gz" | sort | tail -n 1 | awk '{print $4}'`
else
LAST_OBJ=`/usr/local/bin/aws s3 ls s3://${BACKUP_S3_BUCKET}/ --recursive --region ${AWS_DEFAULT_REGION} | grep ".gz" | sort | tail -n 1 | awk '{print $4}'`
else
echo "restoring requested backup..."
LAST_OBJ=$RESTORE_FILE_PATH
fi
Expand All @@ -16,7 +16,7 @@ echo "backup file to resotre: s3://${LAST_OBJ}"

echo "downloading backup from S3..."

/usr/bin/aws s3 cp s3://${LAST_OBJ} ${BACKUP_TGT_DIR}
/usr/local/bin/aws s3 cp s3://${LAST_OBJ} ${BACKUP_TGT_DIR} --region ${AWS_DEFAULT_REGION}

echo "backup download finished"

Expand Down

0 comments on commit 4b58eea

Please sign in to comment.