first draft of docker volume management script

This commit is contained in:
Frieder Schlesier 2018-06-08 19:57:21 +02:00
parent 9aff6691aa
commit 9fc2541b3c
3 changed files with 49 additions and 0 deletions

26
bin/dvbackup Normal file
View File

@ -0,0 +1,26 @@
#!/bin/bash
# https://stackoverflow.com/questions/26331651/how-can-i-backup-a-docker-container-with-its-data-volumes/26339869#26339869
# 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/$CONTAINER_NAME_$VOLUME_NAME.tar $VOLUME_NAME

20
bin/dvrestore Normal file
View File

@ -0,0 +1,20 @@
#!/bin/bash
# https://stackoverflow.com/questions/26331651/how-can-i-backup-a-docker-container-with-its-data-volumes/26339869#26339869
# This script allows you to restore a single volume from a container
# Data in restored in volume with same backupped path
CONTAINER_NAME=$1
VOLUME_NAME=$2
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 $CONTAINER_NAME -v $(pwd):/backup busybox tar xvf /backup/$CONTAINER_NAME_$VOLUME_NAME.tar

3
bin/move-dockervol Normal file
View File

@ -0,0 +1,3 @@
docker run --rm \
-v <SOURCE_DATA_VOLUME_NAME>:/from \
alpine ash -c "cd /from ; tar -cf - . " | ssh <TARGET_HOST> 'docker run --rm -i -v <TARGET_DATA_VOLUME_NAME>:/to alpine ash -c "cd /to ; tar -xpvf - " '