Skip to content

Instantly share code, notes, and snippets.

@mminer
Last active November 26, 2018 20:55
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 mminer/d4a5a98d0abfab3805a937ad618bdc97 to your computer and use it in GitHub Desktop.
Save mminer/d4a5a98d0abfab3805a937ad618bdc97 to your computer and use it in GitHub Desktop.
Back up Docker volumes to tar archives.
#!/usr/bin/env bash
usage() {
cat <<EOF
Usage: $0 VOLUME [VOLUME ...]
Back up Docker volumes to tar archives.
EOF
}
if (( $# < 1 )); then
usage
exit 1
fi
for volume in "$@"; do
docker run --rm --volume ${volume}:/data:ro --volume=$(pwd):/backup ubuntu \
tar cf "/backup/${volume}.tar" /data \
&& echo "Backed up volume ${volume} to ${volume}.tar"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment