Skip to content

Instantly share code, notes, and snippets.

@fabiomontefuscolo
Created September 13, 2017 04:43
Show Gist options
  • Save fabiomontefuscolo/66ef8f6f611803ab7886c8fabbeb27db to your computer and use it in GitHub Desktop.
Save fabiomontefuscolo/66ef8f6f611803ab7886c8fabbeb27db to your computer and use it in GitHub Desktop.
#!/bin/bash
AWS_CLI="/usr/local/bin/aws"
BUCKET="backup.montefuscolo.com.br"
BASE_REGEX='\/storage\/volumes'
CONTAINERS=$(
docker ps --format "{{ .Image }}\t{{ .Names }}" \
| awk '/^(montefuscolo|registry.montefuscolo.com.br)\//{ print $2 }'
)
TPL_BINDS='{{ range $i, $r := .HostConfig.Binds }}
{{ $r }}{{ end }}'
stack=""
for container in $CONTAINERS;
do
paths=$(
docker inspect --format "$TPL_BINDS" $container \
| awk -F: "/${BASE_REGEX}/"'{ print $1 }'
)
stack="${paths}
${stack}";
done
for path in $stack;
do
$AWS_CLI s3 sync \
"$path" "s3://${BUCKET}/${path#/}";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment