Skip to content

Commit

Permalink
Merge pull request #9 from stex79/master
Browse files Browse the repository at this point in the history
Added TARGET variable to specify backup destination
  • Loading branch information
peterrus authored Nov 27, 2020
2 parents e99eaf5 + 33bbd55 commit e1ec140
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The container is configured via a set of environment variables:
- CRON_SCHEDULE: Check out [crontab.guru](https://crontab.guru/) for some examples:
- BACKUP_NAME: A name to identify your backup among the other files in your bucket, it will be postfixed with the current timestamp (date and time)
- S3_STORAGE_CLASS: (Optional, defaults to 'STANDARD') S3 storage class, see [aws cli documentation](https://docs.aws.amazon.com/cli/latest/reference/s3/cp.html) for options
- TARGET: (Optional, defaults to '/data') Specifies the target location to backup. Useful for sidecar containers and to filter files. Examples with multiple targets: TARGET="/var/log/*.log /var/lib/mysql/*.dmp"

All environment variables prefixed with 'AWS_' are directly used by [awscli](https://aws.amazon.com/cli/) that this image heavily relies on.

Expand Down Expand Up @@ -63,3 +64,4 @@ services:
# Contributors
- [jayesh100](https://github.com/jayesh100)
- [ifolarin](https://github.com/ifolarin)
- [stex79](https://github.com/stex79)
11 changes: 10 additions & 1 deletion dobackup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ S3_STORAGE_CLASS=${S3_STORAGE_CLASS:-STANDARD}
# generate file name for tar
FILE_NAME=/tmp/$BACKUP_NAME-`date "+%Y-%m-%d_%H-%M-%S"`.tar.gz

# Check if TARGET variable is set
if [[ -z ${TARGET} ]];
then
echo "variable TARGET is not set we use default value"
TARGET=/data
else
echo "variable TARGET is set"
fi

echo "creating archive"
tar -zcvf $FILE_NAME /data
tar -zcvf $FILE_NAME $TARGET
echo "uploading archive to S3 [$FILE_NAME, storage class - $S3_STORAGE_CLASS]"
aws s3 cp --storage-class $S3_STORAGE_CLASS $FILE_NAME $S3_BUCKET_URL
echo "removing local archive"
Expand Down

0 comments on commit e1ec140

Please sign in to comment.