Added a new configuration option, BACKUP_INTERVAL

This commit is contained in:
Fábio D. Batista 2015-09-10 16:46:45 -03:00
parent 1a27402970
commit ade7679b1e
2 changed files with 23 additions and 21 deletions

View File

@ -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: Usage:
``` docker run -it --rm \
docker run -it --rm \ -e AWS_ACCESS_KEY_ID=... -e AWS_SECRET_ACCESS_KEY=... -e BACKUP_INTERVAL=... \
-e ACCESS_KEY=... -e SECRET_KEY=... whatupdave/s3-volume s3://<BUCKET>/<PATH> whatupdave/s3-volume s3://<BUCKET>/<PATH>
```
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. 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).

25
watch
View File

@ -3,32 +3,30 @@
[[ "$TRACE" ]] && set -x [[ "$TRACE" ]] && set -x
function usage { function usage {
cat <<-EOF cat <<-EOF
Usage: $PROGNAME [OPTIONS] <local-path> <remote-path> Usage: $PROGNAME [OPTIONS] <local-path> <remote-path>
Sync s3 directory locally and backup changed files on exit Sync s3 directory locally and backup changed files on exit
--force-restore restore even if local directory is not empty --force-restore restore even if local directory is not empty
eg: $PROGNAME /data s3://bucket/dir eg: $PROGNAME /data s3://bucket/dir
EOF EOF
} }
function error_exit { function error_exit {
echo "${1:-"Unknown Error"}" 1>&2 echo "${1:-"Unknown Error"}" 1>&2
exit 1 exit 1
} }
PARSED_OPTIONS=$(getopt -n "$0" -o f --long "force-restore" -- "$@") PARSED_OPTIONS=$(getopt -n "$0" -o f --long "force-restore" -- "$@")
if [ $? -ne 0 ]; if [ $? -ne 0 ]; then
then
exit 1 exit 1
fi fi
eval set -- "$PARSED_OPTIONS" eval set -- "$PARSED_OPTIONS"
while true; while true; do
do
case "$1" in case "$1" in
-f|--force-restore) -f|--force-restore)
FORCE_RESTORE="true" FORCE_RESTORE="true"
shift;; shift;;
@ -44,9 +42,9 @@ REMOTE=$2
function restore { function restore {
if [ "$(ls -A $LOCAL)" ]; then if [ "$(ls -A $LOCAL)" ]; then
if [[ ${FORCE_RESTORE:false} == 'true' ]]; then if [[ ${FORCE_RESTORE:false} == 'true' ]]; then
error_exit "local directory is not empty" error_exit "local directory is not empty"
fi fi
fi fi
echo "restoring $REMOTE => $LOCAL" echo "restoring $REMOTE => $LOCAL"
@ -75,8 +73,9 @@ function final_backup {
function idle { function idle {
echo "ready" echo "ready"
while true; do while true; do
sleep 42 & sleep ${BACKUP_INTERVAL:-42} &
wait $! wait $!
[ -n "$BACKUP_INTERVAL" ] && backup
done done
} }