docker-convenience-scripts/docker_clone_volume.sh
Harm Verhagen 688a6a8545 Fix docker_clone_volume.sh to preserve hard-links
When using docker_clone_volume.sh,  I found that when copying a volume with influxdb data,
the clones image was bigger than the original.

cause: alpine base image contains a cp version (busybox) which  does _not_ preserve
hardlinks, even with the -a option.

This is fixed by using an ubuntu base image instead of alpine.

downside: ubuntu image is larger than alpine.

Source volume:

 influxdb_data               380.2 MB

Before:

 influxdb_data.bak           443.5 MB

After:

 influxdb_data.ubuntu.bak    380.2 MB
2023-02-17 08:43:58 +01:00

51 lines
1.1 KiB
Bash
Executable File

#!/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\"..."
docker run --rm \
-i \
-t \
-v $1:/from \
-v $2:/to \
ubuntu bash -c "cd /from ; cp -av . /to"