initial commit

This commit is contained in:
Dave Newman 2014-08-30 12:16:23 -07:00
commit c29c285f99
6 changed files with 140 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.vagrant

13
Dockerfile Normal file
View File

@ -0,0 +1,13 @@
FROM ubuntu:14.04
MAINTAINER Dave Newman <dave@assembly.com>
RUN apt-get update && apt-get -y -q install git python-setuptools python-dateutil python-magic
RUN git clone https://github.com/s3tools/s3cmd.git /s3cmd
RUN cd /s3cmd && python setup.py install
ADD s3cfg /.s3cfg
ADD run.sh run.sh
VOLUME /data
ENTRYPOINT [ "./run.sh", "/data" ]

11
README.md Normal file
View File

@ -0,0 +1,11 @@
docker-s3-volume
==============
Docker container that creates a data volume from a path on s3.
Usage:
```
docker run -it --rm \
-e ACCESS_KEY=... -e SECRET_KEY=... s3-volume s3://<BUCKET>/<PATH>

21
Vagrantfile vendored Normal file
View File

@ -0,0 +1,21 @@
Vagrant.configure('2') do |config|
config.vm.box = "phusion/ubuntu-14.04-amd64"
config.vm.provision :shell, inline: <<SCRIPT
apt-get update
apt-get -y install docker.io
ln -sf /usr/bin/docker.io /usr/local/bin/docker
chmod 777 /var/run/docker.sock
sed -i '$acomplete -F _docker docker' /etc/bash_completion.d/docker.io
SCRIPT
# for speeds
config.vm.network :private_network, ip: "192.168.50.9"
config.vm.synced_folder ".", "/vagrant", type: "nfs"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
end

56
run.sh Executable file
View File

@ -0,0 +1,56 @@
#!/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
exit 1
}
if [ $# != "2" ]; then
usage
error_exit "not enough arguments"
fi
PROGNAME=$0
LOCAL=$1
REMOTE=$2
function restore {
if [ "$(ls -A $LOCAL)" ]; then
error_exit "local directory is not empty"
fi
echo "restoring $REMOTE => $LOCAL"
if ! s3cmd --access_key="$ACCESS_KEY" --secret_key="$SECRET_KEY" sync "$REMOTE/" "$LOCAL/"; then
error_exit "restore failed"
fi
}
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"
fi
}
function idle {
echo "ready"
while true; do
sleep 42 &
wait $!
done
}
restore
trap backup SIGHUP SIGINT SIGTERM
trap "backup; idle" USR1
idle

38
s3cfg Executable file
View File

@ -0,0 +1,38 @@
[default]
access_key =
bucket_location = US
cloudfront_host = cloudfront.amazonaws.com
cloudfront_resource = /2010-07-15/distribution
default_mime_type = binary/octet-stream
delete_removed = False
dry_run = False
encoding = UTF-8
encrypt = False
follow_symlinks = False
force = False
get_continue = False
gpg_command = /usr/local/bin/gpg
gpg_decrypt = %(gpg_command)s -d --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_encrypt = %(gpg_command)s -c --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_passphrase =
guess_mime_type = True
host_base = s3.amazonaws.com
host_bucket = %(bucket)s.s3.amazonaws.com
human_readable_sizes = False
list_md5 = False
log_target_prefix =
preserve_attrs = True
progress_meter = True
proxy_host =
proxy_port = 0
recursive = False
recv_chunk = 4096
reduced_redundancy = False
secret_key =
send_chunk = 4096
simpledb_host = sdb.amazonaws.com
skip_existing = False
socket_timeout = 300
urlencoding_mode = normal
use_https = False
verbosity = WARNING