diff --git a/README.md b/README.md index cbd8efb..3c76928 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/restore.sh b/restore.sh index 2f0faca..d9c20fa 100644 --- a/restore.sh +++ b/restore.sh @@ -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 @@ -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"