From ade7679b1e76687dc7b3c83cf6a78a67b3bdecbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fa=CC=81bio=20D=2E=20Batista?= Date: Thu, 10 Sep 2015 16:46:45 -0300 Subject: [PATCH] Added a new configuration option, BACKUP_INTERVAL --- README.md | 19 +++++++++++-------- watch | 25 ++++++++++++------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 7f8bdee..5098886 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,16 @@ -docker-s3-volume -============== +# docker-s3-volume -Creates a Docker container that is restored and backed up to a directory on s3. You could use this to run short lived processes that work with and persist data to and from S3. +Creates a Docker container that is restored and backed up to a directory on s3. +You could use this to run short lived processes that work with and persist data to and from S3. Usage: -``` -docker run -it --rm \ - -e ACCESS_KEY=... -e SECRET_KEY=... whatupdave/s3-volume s3:/// -``` + docker run -it --rm \ + -e AWS_ACCESS_KEY_ID=... -e AWS_SECRET_ACCESS_KEY=... -e BACKUP_INTERVAL=... \ + whatupdave/s3-volume s3:/// -This pulls down the contents of a directory on S3. If the container is stopped or sent a `USR1` signal, it will backup the modified local contents to S3. \ No newline at end of file +This pulls down the contents of a directory on S3. If the container is stopped or sent a `USR1` signal, +it will backup the modified local contents to S3. + +If you supply a `BACKUP_INTERVAL` environment variable, a backup will be issued each interval. The value can +be specified in seconds, minutes, hours or days (adding `s`, `m`, `h` or `d` as suffix). diff --git a/watch b/watch index d5aa72f..af4632c 100755 --- a/watch +++ b/watch @@ -3,32 +3,30 @@ [[ "$TRACE" ]] && set -x function usage { - cat <<-EOF +cat <<-EOF Usage: $PROGNAME [OPTIONS] Sync s3 directory locally and backup changed files on exit --force-restore restore even if local directory is not empty eg: $PROGNAME /data s3://bucket/dir - EOF +EOF } function error_exit { - echo "${1:-"Unknown Error"}" 1>&2 - exit 1 + echo "${1:-"Unknown Error"}" 1>&2 + exit 1 } PARSED_OPTIONS=$(getopt -n "$0" -o f --long "force-restore" -- "$@") -if [ $? -ne 0 ]; -then +if [ $? -ne 0 ]; then exit 1 fi eval set -- "$PARSED_OPTIONS" -while true; -do +while true; do case "$1" in - -f|--force-restore) + -f|--force-restore) FORCE_RESTORE="true" shift;; @@ -44,9 +42,9 @@ REMOTE=$2 function restore { if [ "$(ls -A $LOCAL)" ]; then - if [[ ${FORCE_RESTORE:false} == 'true' ]]; then - error_exit "local directory is not empty" - fi + if [[ ${FORCE_RESTORE:false} == 'true' ]]; then + error_exit "local directory is not empty" + fi fi echo "restoring $REMOTE => $LOCAL" @@ -75,8 +73,9 @@ function final_backup { function idle { echo "ready" while true; do - sleep 42 & + sleep ${BACKUP_INTERVAL:-42} & wait $! + [ -n "$BACKUP_INTERVAL" ] && backup done }