This commit is contained in:
Kevin Veen-Birkenbach 2022-01-21 19:05:00 +01:00
commit d5d3a4d575
2 changed files with 25 additions and 25 deletions

View File

@ -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,30 +31,14 @@ 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.
## 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://gist.github.com/spalladino/6d981f7b33f6e0afe6bb
- 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/

View File

@ -1,6 +1,20 @@
#!/bin/bash
# @param $1 Volume-Name
# @param $2 Hash-Name
volume_name="$1"
backup_path="$2"
backup_hash="$2"
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=$?
if [ $exit_status_volume_inspect -eq 0 ]; then
echo "Volume $volume_name allready exists"
else
echo "Create volume $volume_name"
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/"
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/"