Backup docker volumn script:
Script 1: backup.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 CONTAINER_NAME=$1 VOLUME_PATH=$2 usage () { echo "Usage: $0 [container name] [volume path]" exit 1 }if [ -z $CONTAINER_NAME ]then echo "Error: missing container name parameter." usagefi if [ -z $VOLUME_PATH ]then echo "Error: missing volume path parameter." usagefi sudo docker run --rm --volumes-from $CONTAINER_NAME -v $(pwd ):/backup busybox tar cvf /backup/backup.tar $VOLUME_PATH
Script 2: restore.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 NEW_CONTAINER_NAME=$1 usage () { echo "Usage: $0 [container name]" exit 1 }if [ -z $NEW_CONTAINER_NAME ]then echo "Error: missing container name parameter." usagefi sudo docker run --rm --volumes-from $NEW_CONTAINER_NAME -v $(pwd ):/backup busybox tar xvf /backup/backup.tar
Reference: -
https://stackoverflow.com/questions/26331651/how-can-i-backup-a-docker-container-with-its-data-volumes