Skip to content

Instantly share code, notes, and snippets.

@bdurand
Created September 19, 2018 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdurand/d29f82961da42756ca2ded67ac7712f1 to your computer and use it in GitHub Desktop.
Save bdurand/d29f82961da42756ca2ded67ac7712f1 to your computer and use it in GitHub Desktop.
#!/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