Last active
September 24, 2019 09:58
-
-
Save duynguyenhoang/554f45618a2cd774f82156920e01f284 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| # This script allows you to backup a single volume from a container | |
| # Data in given volume is saved in the current directory in a tar archive. | |
| CONTAINER_NAME=$1 | |
| VOLUME_NAME=$2 | |
| usage() { | |
| echo "Usage: $0 [container name] [volume name]" | |
| exit 1 | |
| } | |
| 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 | |
| sudo docker run --rm --volumes-from $CONTAINER_NAME -v $(pwd):/backup busybox tar cvf /backup/backup.tar $VOLUME_NAME |
This file contains hidden or 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 | |
| # This script allows you to restore a single volume from a container | |
| # Data in restored in volume with same backupped path | |
| NEW_CONTAINER_NAME=$1 | |
| usage() { | |
| echo "Usage: $0 [container name]" | |
| exit 1 | |
| } | |
| if [ -z $NEW_CONTAINER_NAME ] | |
| then | |
| echo "Error: missing container name parameter." | |
| usage | |
| fi | |
| sudo docker run --rm --volumes-from $NEW_CONTAINER_NAME -v $(pwd):/backup busybox tar xvf /backup/backup.tar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment