parent
c29c285f99
commit
35526cee7c
|
@ -1,11 +1,13 @@
|
|||
docker-s3-volume
|
||||
==============
|
||||
|
||||
Docker container that creates a data volume from a path on 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=... s3-volume s3://<BUCKET>/<PATH>
|
||||
-e ACCESS_KEY=... -e SECRET_KEY=... 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.
|
19
run.sh
19
run.sh
|
@ -1,14 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
function usage {
|
||||
echo "Usage: $PROGNAME <local-path> <remote-path>" 1>&2
|
||||
echo " eg: $PROGNAME /data s3://bucket/dir" 1>&2
|
||||
}
|
||||
|
||||
function error_exit {
|
||||
echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
|
||||
echo "${1:-"Unknown Error"}" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
@ -35,10 +33,20 @@ function restore {
|
|||
function backup {
|
||||
echo "backup $LOCAL => $REMOTE"
|
||||
if ! s3cmd --access_key="$ACCESS_KEY" --secret_key="$SECRET_KEY" sync --delete-removed "$LOCAL/" "$REMOTE/"; then
|
||||
error_exit "backup failed"
|
||||
echo "backup failed" 1>&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function final_backup {
|
||||
echo "backup $LOCAL => $REMOTE"
|
||||
while ! s3cmd --access_key="$ACCESS_KEY" --secret_key="$SECRET_KEY" sync --delete-removed "$LOCAL/" "$REMOTE/"; do
|
||||
echo "backup failed" 1>&2
|
||||
sleep 1
|
||||
done
|
||||
exit 0
|
||||
}
|
||||
|
||||
function idle {
|
||||
echo "ready"
|
||||
while true; do
|
||||
|
@ -49,8 +57,7 @@ function idle {
|
|||
|
||||
restore
|
||||
|
||||
trap backup SIGHUP SIGINT SIGTERM
|
||||
trap final_backup SIGHUP SIGINT SIGTERM
|
||||
trap "backup; idle" USR1
|
||||
|
||||
idle
|
||||
|
||||
|
|
Loading…
Reference in New Issue