Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new script for transferring volume between servers #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,30 @@ This repository will contain different convenience scripts for docker I have gat

The purpose for this script is that I can easily create a clone of an existing docker data with
a new name. This will allow me to create a duplicate of an existing data volume I use in the
production environment of my blog for example and take that duplicate to my development version
production environment of my blog for example and take that duplicate to my development version
to ensure I have the latest production data also at development.

You can find more details in my blog post [Cloning Docker Data Volumes](https://www.guidodiepen.nl/2016/05/cloning-docker-data-volumes/)

## docker_clone_volume_across_servers.sh

The script relates to the above one, in addition, it adds the possibility to transfer named volume from one host machine to another.

It is worth noting, that :
* you should have running docker daemon and have ssh available on both hosts;
* you ought to have access to root;
* you might want be ensured that your destination containers are stopped before copying the volume.

Refer to [stackoverflow topic](https://stackoverflow.com/questions/42973347/how-to-copy-docker-volume-from-one-machine-to-another).

### to do
check if target volume has already existed (or not needed, cauz user merely should understand circumstances)

## docker_get_data_volume_info.sh

The purpose for this script is that I can easily get a list of details for all data volumes
that are currently present. The information that is provided to the user as output is per
data volume the current size of the data volume and a list of stopped or running containers
The purpose of this script is that I can easily get a list of details for all data volumes
that are currently present. The information that is provided to the user as output is per
data volume the current size of the data volume and a list of stopped or running containers
that have a link to this data volume, including the image corresponding to the container.
The script allows me to easily see if there are some data volumes on my disk that are taking
up a lot of space and are not needed anymore.
Expand Down
47 changes: 47 additions & 0 deletions docker_clone_volume_across_servers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 - '"