Skip to content

Instantly share code, notes, and snippets.

@poeli
Last active April 4, 2018 16:04
Show Gist options
  • Save poeli/620cc55aa34ac65f5efca2da9c126a2b to your computer and use it in GitHub Desktop.
Save poeli/620cc55aa34ac65f5efca2da9c126a2b to your computer and use it in GitHub Desktop.
Restore a single volume from a tar archive to a container
#!/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