Created
November 27, 2014 18:28
-
-
Save colincoghill/9f535f46d8b060edbab8 to your computer and use it in GitHub Desktop.
docker backup script
This file contains 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/sh | |
# Given a container name, find the exposed volumes in the container | |
# and back them up into a tgz | |
# backup_container graphite_data backup.tgz | |
CONT=$1 | |
OUTFILE=$2 | |
if [ -z "${CONT}" ]; then | |
echo "Usage: " | |
echo | |
echo " backup_container <NAME> [<BACKUPFILE.TGZ>]" | |
echo | |
echo "eg. backup_container graphite_data graphite_data_backup.tgz" | |
echo | |
echo "If BACKUPFILE not given, will send to stdout" | |
exit 0 | |
fi | |
VOLS=`docker inspect --format='{{range $k, $v := .Volumes}}{{$k}} {{end}}' ${CONT}` | |
PARENT=`docker inspect --format='{{.Config.Image}}' ${CONT}` | |
CMD="docker run --rm --volumes-from=${CONT} ${PARENT} tar -zc ${VOLS}" | |
if [ ! -z "${OUTFILE}" ]; then | |
exec $CMD > ${OUTFILE} | |
else | |
exec $CMD | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment