Skip to content

Instantly share code, notes, and snippets.

@colincoghill
Created November 27, 2014 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colincoghill/9f535f46d8b060edbab8 to your computer and use it in GitHub Desktop.
Save colincoghill/9f535f46d8b060edbab8 to your computer and use it in GitHub Desktop.
docker backup script
#!/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