First commit

This commit is contained in:
Adrián Parilli 2021-08-19 14:54:18 -04:00
commit baac5e4378
2 changed files with 109 additions and 0 deletions

23
Dockerfile Normal file
View File

@ -0,0 +1,23 @@
FROM debian:bullseye-slim
ARG source="https://github.com/abbbi/virtnbdbackup"
LABEL container.name="virtnbdbackup-docker"
LABEL container.source.description="Backup utiliy for Libvirt kvm / qemu with Incremental backup support via NBD"
LABEL container.description="virtnbdbackup and virtnbdrestore (plus depedencies) to run on hosts with libvirt >= 6.0.0"
LABEL container.source=$source
LABEL container.version="0.22"
LABEL maintainer="Adrián Parilli <a.parilli@staffwerke.de>"
# Deploys dependencies and pulls sources, installing virtnbdbackup and removing unnecessary content:
RUN \
apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates git python3-all python3-libnbd python3-libvirt python3-lz4 python3-setuptools python3-tqdm qemu-utils && \
git clone $source.git && \
cd virtnbdbackup && python3 setup.py install && cd .. && \
apt-get purge -y git ca-certificates && apt-get -y autoremove --purge && apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /virtnbdbackup
# Default folder:
WORKDIR /

86
README.md Normal file
View File

@ -0,0 +1,86 @@
# virtnbdbackup-docker
*"Backup utility for libvirt, using the latest changed block tracking features. Create thin provisioned full and incremental backups of your kvm/qemu virtual machines."*
(Refer to the [original source code](https://github.com/abbbi/virtnbdbackup) first, for better understanding, help and get familiar with syntax.)
## Overwiew:
Virtnbdbackup-docker is intended for scenarios where isn't viable for SysAdmins to provide a full python3 environment plus up-to-date dependencies (old distros); or when this is totally impossible due to system constraints (inmutable / embedded rootfs, docker oriented OSes, etc.)
This image includes 'virtnbdbackup' and 'virtnbdrestore' utils installed, along with required dependecies, and currently is being built from `debian:bullseye-slim` as base.
By now, it has been successfully rested on UnRaid, and should work the same on many other distros as much as below requirements can be accomplished.
## Requirements:
- Docker Engine. See [Docker Documentation](https://docs.docker.com/get-docker/) for further instructions
- libvirt >=6.0.0 (Qemu version seems to be not important, since this image carries 'qemu-utils' for internal processing.)
- To have read the [source code](https://github.com/abbbi/virtnbdbackup) and do the modifications mentioned so this tool will work on your VMs.
## The key to make it work, it's to determine correct bind mounts:
- Virtnbdbackup needs to access libvirt's socket in order to work correctly, and attempts this via `/var/run/libvirt`
In almost all mainstream distros of nowadays, such as Debian, RedHat, Archlinux and the countless distros based on these `/var/run` is a symlink to `/run`, so the correct bind mount should be: `-v /run:/run`.
But in certain cases (such as UnRaid) `/run` and `/var/run` are different folders. In this case you need to bind mount with `-v /var/run:/run` (and sometimes also with `-v /var/lock:/run/lock`) in order to run this container correctly.
(If you get in trouble with this and you get timeouts or errors, *read source FAQ* and then create a persistent contiainer as described below to debug the behaviour from inside.)
- Virtnbdbackup creates sockets for backup/restoration tasks at /var/tmp. Ensure to mimic this with `-v /var/tmp:/var/tmp`
- Finally, for clearness with all the commands you will input, it's convenient to mimic backup and restoration bind mounts at both endpoints, such as `-v /mnt/backups:/mnt/backups` and so on.
## Usage Examples:
### Full Backup:
`docker run --rm \`
`-v /run:/run -v /var/tmp:/var/tmp -v /mnt/backups:/mnt/backups \`
`docker-virtnbdbackup \`
`virtnbdbackup -d <domain-name> -l full -o /mnt/-backups/<domain-name>`
### Incremental Backup:
`docker run --rm \`
`-v /run:/run -v /var/tmp:/var/tmp -v /mnt/backups:/mnt/backups \`
`docker-virtnbdbackup \`
`virtnbdbackup -d <domain-name> -l inc -o /mnt/-backups/<domain-name>`
### Backup restoration (to a determined location):
`docker run --rm \`
`-v /run:/run -v /var/tmp:/var/tmp -v /mnt/backups:/mnt/backups \`
`docker-virtnbdbackup \`
`virtnbdrestore -i /mnt/-backups/<domain-backup> -a restore -o /mnt/restored`
Where /mnt/restored is just an example of folder in your system where virtnbdrestore will rebuild all qcow2 images based on backups, since will create images with names corresponding with its internal block device name, such as 'hdc'.
### Persistent container:
In above examples, container will be removed as soon the invoked command has been executed. This is the optimal behaviour when you intend to automatize operations (such as incremental backups.)
In addition, you can set a persistent container with all necessary bind mounts with:
`docker create --name <container-name>`
`-v /var/tmp:/var/tmp -v /run:/run -v /mnt/backups:/mnt/backups -v /mnt/restored:/mnt/restored' \`
`docker-virtnbdbackup \`
`/bin/bash`
And attach to its Shell with: `docker start -i <container-name>` to perform manual backups/restorations, or for debugging purposes.