Created
September 13, 2017 04:43
-
-
Save fabiomontefuscolo/66ef8f6f611803ab7886c8fabbeb27db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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