parent
c29c285f99
commit
35526cee7c
|
@ -1,11 +1,13 @@
|
||||||
docker-s3-volume
|
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:
|
Usage:
|
||||||
|
|
||||||
```
|
```
|
||||||
docker run -it --rm \
|
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
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
function usage {
|
function usage {
|
||||||
echo "Usage: $PROGNAME <local-path> <remote-path>" 1>&2
|
echo "Usage: $PROGNAME <local-path> <remote-path>" 1>&2
|
||||||
echo " eg: $PROGNAME /data s3://bucket/dir" 1>&2
|
echo " eg: $PROGNAME /data s3://bucket/dir" 1>&2
|
||||||
}
|
}
|
||||||
|
|
||||||
function error_exit {
|
function error_exit {
|
||||||
echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
|
echo "${1:-"Unknown Error"}" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,10 +33,20 @@ function restore {
|
||||||
function backup {
|
function backup {
|
||||||
echo "backup $LOCAL => $REMOTE"
|
echo "backup $LOCAL => $REMOTE"
|
||||||
if ! s3cmd --access_key="$ACCESS_KEY" --secret_key="$SECRET_KEY" sync --delete-removed "$LOCAL/" "$REMOTE/"; then
|
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
|
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 {
|
function idle {
|
||||||
echo "ready"
|
echo "ready"
|
||||||
while true; do
|
while true; do
|
||||||
|
@ -49,8 +57,7 @@ function idle {
|
||||||
|
|
||||||
restore
|
restore
|
||||||
|
|
||||||
trap backup SIGHUP SIGINT SIGTERM
|
trap final_backup SIGHUP SIGINT SIGTERM
|
||||||
trap "backup; idle" USR1
|
trap "backup; idle" USR1
|
||||||
|
|
||||||
idle
|
idle
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue