Created
September 19, 2018 21:25
-
-
Save bdurand/d29f82961da42756ca2ded67ac7712f1 to your computer and use it in GitHub Desktop.
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/sh | |
if [ "$2" == "" ]; then | |
>&2 echo "Usage: $0 backup|restore volume_name" | |
exit 1 | |
fi | |
if [ "$1" == "backup" ]; then | |
docker run -it --rm -v $2:/volume -v `pwd`:/backup alpine tar -cjf /backup/$2.tar.bz2 -C /volume ./ | |
elif [ "$1" == "restore" ]; then | |
if [ -e "$2.tar.bz2" ]; then | |
docker run -it --rm -v $2:/volume -v `pwd`:/backup alpine sh -c "rm -rf /volume/* /volume/..?* /volume/.[!.]* ; tar -C /volume/ -xjf /backup/$2.tar.bz2" | |
else | |
>&2 echo "$2.tar.bz2 does not exist in the current directory" | |
exit 1 | |
fi | |
else | |
>&2 echo "first argument must be either backup or restore" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment