mirror of
https://github.com/gdiepen/docker-convenience-scripts.git
synced 2025-01-18 10:08:55 +00:00
Added initial version of docker_clone_volume.sh
Convenience script that can help me to easily create a clone of a given data volume. The script is mainly useful if you are using named volumes
This commit is contained in:
parent
0744932730
commit
73ce677b3f
50
docker_clone_volume.sh
Normal file
50
docker_clone_volume.sh
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#Author: Guido Diepen
|
||||||
|
|
||||||
|
#Convenience script that can help me to easily create a clone of a given
|
||||||
|
#data volume. The script is mainly useful if you are using named volumes
|
||||||
|
|
||||||
|
|
||||||
|
#First check if the user provided all needed arguments
|
||||||
|
if [ "$1" = "" ]
|
||||||
|
then
|
||||||
|
echo "PLease provide a source volume name"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$2" = "" ]
|
||||||
|
then
|
||||||
|
echo "PLease provide a destination volume name"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
#Check if the source volume name does exist
|
||||||
|
docker volume inspect $1 > /dev/null 2>&1
|
||||||
|
if [ "$?" != "0" ]
|
||||||
|
then
|
||||||
|
echo "The source volume \"$1\" does not exist"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
#Now check if the destinatin volume name does not yet exist
|
||||||
|
docker volume inspect $2 > /dev/null 2>&1
|
||||||
|
|
||||||
|
if [ "$?" = "0" ]
|
||||||
|
then
|
||||||
|
echo "The destination volume \"$2\" already exists"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
echo "Creating destination volume \"$2\"..."
|
||||||
|
docker volume create --name $2
|
||||||
|
echo "Copying data from source volume \"$1\" to destination volume \"$2\"..."
|
||||||
|
echo docker run --rm \
|
||||||
|
-i \
|
||||||
|
-t \
|
||||||
|
-v $2:/from \
|
||||||
|
-v $1:/to \
|
||||||
|
alpine ash -c "cd /to ; cp -a /from/* ."
|
Loading…
Reference in New Issue
Block a user