Last active
April 4, 2018 16:04
-
-
Save poeli/620cc55aa34ac65f5efca2da9c126a2b to your computer and use it in GitHub Desktop.
Restore a single volume from a tar archive to a container
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 | |
# Restore a single volume from a tar archive to a Docker container | |
NEW_CONTAINER_NAME=$1 | |
BACKUPTAR=$2 | |
usage() { | |
echo "Usage: $0 [container 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 $NEW_CONTAINER_NAME ] | |
then | |
echo "Error: missing container name parameter." | |
usage | |
fi | |
docker run --rm --volumes-from $NEW_CONTAINER_NAME -v $TARDIR:/backup busybox tar xvf /backup/$TARFN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment