From 568888952fc1c3f72e51c2e5d1dd4dfdb978139d Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 11 Nov 2021 13:03:19 +0100 Subject: [PATCH 1/5] Optimized performance of backup script --- docker-volume-recover.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/docker-volume-recover.sh b/docker-volume-recover.sh index 241faf4..28c169b 100644 --- a/docker-volume-recover.sh +++ b/docker-volume-recover.sh @@ -1,6 +1,17 @@ #!/bin/bash # @param $1 Volume-Name +# @param $2 Hash-Name volume_name="$1" -backup_path="$2" -docker volume create "$volume_name" -docker run --rm -v "$volume_name:/recover/" -v "$backup_path:/backup/" "kevinveenbirkenbach/alpine-rsync" sh -c "rsync -avv /backup/ /recover/" +backup_hash="$2" +backup_path="/Backups/$backup_hash/docker-volume-backup/latest/$volume_name" +if docker volume inspect; then + echo "Volume $volume_name allready exists" + else + echo "Create volume $volume_name" + docker volume create "$volume_name" +fi +if [ ! -d "$backup_path" ]; then + echo "ERROR: $backup_path doesn't exist" + exit 1 +fi +docker run --rm -v "$volume_name:/recover/" -v "$backup_path:/backup/" "kevinveenbirkenbach/alpine-rsync" sh -c "rsync -avv --delete /backup/ /recover/" From d49b21229046c9ab55d6fd19596e711a7653af52 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 11 Nov 2021 13:17:02 +0100 Subject: [PATCH 2/5] Solved bugs --- docker-volume-recover.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docker-volume-recover.sh b/docker-volume-recover.sh index 28c169b..d169c75 100644 --- a/docker-volume-recover.sh +++ b/docker-volume-recover.sh @@ -4,7 +4,10 @@ volume_name="$1" backup_hash="$2" backup_path="/Backups/$backup_hash/docker-volume-backup/latest/$volume_name" -if docker volume inspect; then +echo "Inspect volume $volume_name" +docker volume inspect "$volume_name" +exit_status_volume_inspect=$? +if [ $exit_status_volume_inspect -eq 0 ]; then echo "Volume $volume_name allready exists" else echo "Create volume $volume_name" From ebab64549d6e9001cc95b78f05b50be1ea65a763 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 11 Nov 2021 13:33:14 +0100 Subject: [PATCH 3/5] Added hint for backup practices --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d70adc2..ff915d3 100644 --- a/README.md +++ b/README.md @@ -55,3 +55,4 @@ This setup script is not optimized yet for performance. Please optimized this sc ## More information - https://blog.ssdnodes.com/blog/docker-backup-volumes/ - https://www.baculasystems.com/blog/docker-backup-containers/ +- https://stackoverflow.com/questions/26331651/how-can-i-backup-a-docker-container-with-its-data-volumes From 403108ee3410363a0cd989f9f4f3423deb1d2c2b Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 11 Nov 2021 13:47:17 +0100 Subject: [PATCH 4/5] Solved path bug and optimized readme.md --- README.md | 27 +++++---------------------- docker-volume-recover.sh | 2 +- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index ff915d3..c0e0b21 100644 --- a/README.md +++ b/README.md @@ -9,18 +9,20 @@ It is part of the following scheme: ![backup scheme](https://www.veen.world/wp-content/uploads/2020/12/server-backup-768x567.jpg) Further information you will find [in this blog post](https://www.veen.world/2020/12/26/how-i-backup-dedicated-root-servers/). -## Backup +## Backup all volumes Execute: ```bash ./docker-volume-backup.sh ``` -## Recover +## Recover one volume Execute: ```bash -./docker-volume-recover.sh {{volume_name}} {{backup_path}} + +bash ./docker-volume-recover.sh "{{volume_name}}" "$(sha256sum /etc/machine-id | head -c 64)" + ``` ## Debug @@ -29,25 +31,6 @@ To checkout what's going on in the mount container type in the following command ```bash docker run -it --entrypoint /bin/sh --rm --volumes-from {{container_name}} -v /Backups/:/Backups/ kevinveenbirkenbach/alpine-rsync ``` -## Manual Backup -rsync -aPvv '***{{source_path}}***/' ***{{destination_path}}***"; - -## Test -Delete the volume. - -```bash -docker rm -f container-name -docker volume rm volume-name -``` - -Recover the volume: - -```bash -docker volume create volume-name -docker run --rm -v volume-name:/recover/ -v ~/backup/:/backup/ "kevinveenbirkenbach/alpine-rsync" sh -c "rsync -avv /backup/ /recover/" -``` - -Restart the container. ## Optimation This setup script is not optimized yet for performance. Please optimized this script for performance if you want to use it in a professional environment. diff --git a/docker-volume-recover.sh b/docker-volume-recover.sh index d169c75..1466421 100644 --- a/docker-volume-recover.sh +++ b/docker-volume-recover.sh @@ -3,7 +3,7 @@ # @param $2 Hash-Name volume_name="$1" backup_hash="$2" -backup_path="/Backups/$backup_hash/docker-volume-backup/latest/$volume_name" +backup_path="/Backups/$backup_hash/docker-volume-backup/latest/$volume_name/raw" echo "Inspect volume $volume_name" docker volume inspect "$volume_name" exit_status_volume_inspect=$? From cb5e5fc6ed170c515eb99da7b73a465c8b8a66ae Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 12 Nov 2021 12:46:21 +0100 Subject: [PATCH 5/5] Added further information concerning backups --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c0e0b21..8031b33 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ docker run -it --entrypoint /bin/sh --rm --volumes-from {{container_name}} -v /B This setup script is not optimized yet for performance. Please optimized this script for performance if you want to use it in a professional environment. ## More information +- https://docs.docker.com/storage/volumes/ - https://blog.ssdnodes.com/blog/docker-backup-volumes/ - https://www.baculasystems.com/blog/docker-backup-containers/ - https://stackoverflow.com/questions/26331651/how-can-i-backup-a-docker-container-with-its-data-volumes +- https://netfuture.ch/2013/08/simple-versioned-timemachine-like-backup-using-rsync/