forked from ITISFoundation/osparc-simcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_clone_volume.bash
executable file
·45 lines (36 loc) · 1.21 KB
/
docker_clone_volume.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# Taken from https://github.com/gdiepen/docker-convenience-scripts (⭐)
# wget https://raw.githubusercontent.com/gdiepen/docker-convenience-scripts/master/docker_clone_volume.sh
#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\"..."
docker run --rm \
--interactive \
--tty \
--volume "$1":/from \
--volume "$2":/to \
alpine ash -c "cd /from ; cp -av . /to"