Last active
April 4, 2018 16:04
-
-
Save poeli/adaa11cab1a7b99c2a19da110a30b4b1 to your computer and use it in GitHub Desktop.
Backup a single volume from a container to a tar archive
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/bash | |
# Backup a single volume from a Docker container to a tar archive. | |
CONTAINER_NAME=$1 | |
VOLUME_NAME=$2 | |
BACKUPTAR=$3 | |
usage() { | |
echo "Usage: $0 [container name] [volume name] ([backup.tar])" | |
exit 1 | |
} | |
if [ -z $BACKUPTAR ] | |
then | |
BACKUPTAR="backup.tar" | |
fi | |
TARDIR=$(dirname "${BACKUPTAR}") | |
TARFN=$(basename "${BACKUPTAR}") | |
if [[ $TARDIR != /* ]] | |
then | |
TARDIR="$(pwd)/$TARDIR" | |
fi | |
if [ -z $CONTAINER_NAME ] | |
then | |
echo "Error: missing container name parameter." | |
usage | |
fi | |
if [ -z $VOLUME_NAME ] | |
then | |
echo "Error: missing volume name parameter." | |
usage | |
fi | |
docker run --rm --volumes-from $CONTAINER_NAME -v $TARDIR:/backup busybox tar cvf /backup/$TARFN $VOLUME_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment