Last active
November 26, 2018 20:55
-
-
Save mminer/d4a5a98d0abfab3805a937ad618bdc97 to your computer and use it in GitHub Desktop.
Back up Docker volumes to tar archives.
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
#!/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