forked from gdiepen/docker-convenience-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker_clone_volume_across_servers.sh
More file actions
executable file
·47 lines (38 loc) · 1.14 KB
/
docker_clone_volume_across_servers.sh
File metadata and controls
executable file
·47 lines (38 loc) · 1.14 KB
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
46
47
#!/bin/bash
# The script repeates docker_clone_volume.sh
# Thanks to maddin25 who provides solution in
# https://stackoverflow.com/questions/42973347/how-to-copy-docker-volume-from-one-machine-to-another
# The script is mainly useful if you are using named volumes and
# on both hosts you should have running docker diemon
# and have access to root, obviously.
# arg: $1: source volume name
# arg: $2: target host
# arg: $3: target volume name
#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 target host (e.g. 1.1.1.1)"
exit
fi
if [ "$3" = "" ]
then
echo "Please provide a target 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
docker run --rm \
-v $1:/from alpine ash -c \
"cd /from ; tar -czf - . " | \
ssh $2 \
"docker run --rm -i -v \"$3\":/to alpine ash -c 'cd /to ; tar -xpvzf - '"