add export volume script

pull/12/head
Alexey Ukhov 2020-03-24 14:49:51 +07:00
rodzic 1e9a58a799
commit 197c65cdec
1 zmienionych plików z 34 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,34 @@
#!/usr/bin/env bash
# Author: Alexey Ukhov <alex@ukhov.ru>
SCRIPTSRC=`readlink -f "$0" || echo "$0"`
SCRIPT_PATH=`dirname "$SCRIPTSRC" || echo .`
#First check if the user provided all needed arguments
if [ "$1" = "" ]
then
echo "Please provide a source 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
BACKUP_FOLDER=${2:-backup}
if [ ! -d "${BACKUP_FOLDER}" ]
then
echo "Create backup folder '${BACKUP_FOLDER}'"
mkdir -p ${BACKUP_FOLDER}
fi
NOW=$(date +"%Y-%m-%d-%H-%M-%S")
BACKUP_FILE=${BACKUP_FOLDER}/$1_${NOW}.tar.gz
echo "Export volume '$1' into file '${BACKUP_FILE}'"
docker run --rm -v $1:/from alpine ash -c 'cd /from && tar -cOzf - .' > ${BACKUP_FILE}