From 1a7f8abc3e9f669e9532da3d8f8e60cb9971387f Mon Sep 17 00:00:00 2001 From: nevafuse Date: Tue, 3 Jul 2018 10:39:07 -0400 Subject: [PATCH] Create docker_gzip_volume.sh --- docker_gzip_volume.sh | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 docker_gzip_volume.sh diff --git a/docker_gzip_volume.sh b/docker_gzip_volume.sh new file mode 100644 index 0000000..f099589 --- /dev/null +++ b/docker_gzip_volume.sh @@ -0,0 +1,44 @@ +!/bin/bash + +#Author: Guido Diepen + +#Convenience script that can help me to easily create a gzip 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 destination exists +if [ ! -d "$2" ] +then + echo "The destination \"$2\" doesn't exist" + exit +fi + +echo "Copying data from source volume \"$1\" to destination volume \"$2\"..." +docker run --rm \ + -i \ + -t \ + -v $1:/from \ + -v $2:/to \ + alpine ash -c "cd /from ; tar zcvf \"/to/$1`date +%Y%m%d%H%M`.gz\" ."