Commit a62253a9 authored by CarlosEDP's avatar CarlosEDP
Browse files

Moved scripts to management repo

parent 2304b257
#!/bin/bash
if [[ $1 == '-a' ]]; then
VOLUMES=$(docker volume ls -q)
elif [[ $1 ]]; then
if `docker volume ls -q |grep -w $1` ; then
VOLUMES=$1
else
echo "Volume $1 does not exist."
exit
fi
else
echo "No parameter passed, provide a volume name or '-a' to backup all volumes."
exit
fi
for i in $VOLUMES; do
echo Backup volume: $i
export DOCKER_VOLUME=$i
docker run -d \
--name=backup-$i \
--rm \
-v $DOCKER_VOLUME:/$DOCKER_VOLUME:ro \
-v /mnt/1TB-WDred/Backups/:/backup \
alpine \
tar -czpf /backup/$DOCKER_VOLUME-$(date +%Y%m%d_%H%M%S).tar.gz $DOCKER_VOLUME
done
#!/bin/bash
if [ $# -eq 0 ]
then
echo "Please supply the backup file in the format: "
echo "restore_docker_volume.sh /path/backup_file-20001212_000000.tar.gz"
echo " "
exit
fi
pathToFile=$(pwd $(dirname $1))
fileName=$(basename $1)
VOLUME=$(echo $fileName | sed 's/\(.*\)-[0-9]*_[0-9]*\.tar\.gz/\1/')
# Check if docker volume exists
if docker volume ls -q | grep -q $VOLUME ; then
read -p "Volume already exists, overwrite all files? [yn] " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi
else
echo "Creating volume $VOLUME"
#docker volume create $VOLUME
fi
echo Restore volume: $VOLUME
docker run -d \
--name=restore-$VOLUME \
--rm \
-v $pathToFile/:/source:ro \
-v $VOLUME:/$VOLUME \
alpine \
tar zvxf /source/$fileName -C /source --strip-components 1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment