abbbi / virtnbdbackup

Backup utility for Libvirt / qemu / kvm supporting incremental and differential backups + instant recovery (agentless).
http://libvirtbackup.grinser.de/
GNU General Public License v3.0
330 stars 46 forks source link

Add support for remote backup #65

Closed abbbi closed 2 years ago

abbbi commented 2 years ago

Current version already supports qemu URI's, but nbd communication is still based on local unix sockets. If the qemu uri specified is remote based (qemu+tcp) virtnbdbackup/virtnbdrestore could setup an nbd server listening on a tcp socket and read data directly from started nbd service. This would allow to install virtnbdbackup on one central "backup server" and backup multiple remote systems without having to install the utility on each of them.

./virtnbdbackup -U qemu+tcp://192.168.161.163/system -d vm1 -o $(mktemp -d) --user root@remotehost--password <password>
[2022-07-19 21:39:43] INFO nbdhelper - waitForServer [sda]: Waiting until NBD server on socket [/var/tmp/virtnbdbackup.1893571] is up.
[2022-07-19 21:39:44] INFO nbdhelper - waitForServer [sda]: Waiting for NBD Server, Retry: 0
[2022-07-19 21:39:44] ERROR virtnbdbackup - main [MainThread]: Unable to backup Disk: NBD endpoint: /var/tmp/virtnbdbackup.1893571: connection failed: Unable to connect nbd server: nbd_connect_unix: connect: No such file or directory (ENOENT)

As first step, regular non-encrypted tcp communication should be implemented. In the next step. have a look about nbd+tls.

1) check if uri if specified and includes qemu+tcp 2) if so, find out specified IP and create backup xml with additional

<server name="<ip>" port="10809"/>

setting (or hostname returned by libvirt.getHostname())

2) use libnbd connect_uri to establish remote nbd connection.

abbbi commented 2 years ago

POC via nbd over TCP more or less working in remote1 branch, but needs more work. How to handle file copy of virtual machine files like nvram etc? Backup via qemu+ssh also works:

./virtnbdbackup -U qemu+ssh://root@10.0.0.2.2/system -d vm1 -o $(mktemp -d) 
[2022-07-21 12:43:09] INFO common - printVersion [MainThread]: Version: 0.80 Arguments: ./virtnbdbackup -U qemu+ssh://root@192.168.161.163/system -d vm1 -o /tmp/tmp.pJMhA7OooX
[2022-07-21 12:43:09] INFO virtnbdbackup - main [MainThread]: Backup level: [copy]
[2022-07-21 12:43:09] INFO libvirthelper - _connect [MainThread]: Connected to remote host: [libivirt.local], local host: [dev]
[2022-07-21 12:43:09] INFO virtnbdbackup - main [MainThread]: Libvirt library version: 6000000
[2022-07-21 12:43:09] INFO libvirthelper - getDomainDisks [MainThread]: Skipping attached [cdrom] device: [sdb].
[2022-07-21 12:43:09] INFO libvirthelper - getDomainDisks [MainThread]: Skipping attached [floppy] device: [fda].
[2022-07-21 12:43:09] INFO virtnbdbackup - main [MainThread]: Domain has 1 disks attached which support changed block tracking.
[2022-07-21 12:43:09] INFO virtnbdbackup - main [MainThread]: Concurrent backup processes: [1]
[2022-07-21 12:43:09] INFO libvirthelper - redefineCheckpoints [MainThread]: Loading checkpoint list from: [/tmp/tmp.pJMhA7OooX/checkpoints]
[2022-07-21 12:43:09] INFO virtnbdbackup - handleCheckpoints [MainThread]: Checkpoint handling.
[2022-07-21 12:43:09] INFO virtnbdbackup - main [MainThread]: Temporary scratch file target directory: /var/tmp
[2022-07-21 12:43:09] INFO virtnbdbackup - main [MainThread]: Starting backup job.
[2022-07-21 12:43:09] WARNING libvirthelper - fsFreeze [MainThread]: Guest agent is not responding: QEMU guest agent is not connected
[2022-07-21 12:43:10] INFO nbdhelper - version [sda]: libnbd version: 1.6.1
[2022-07-21 12:43:10] INFO nbdhelper - waitForServer [sda]: Waiting until NBD server at [nbd://libvirt.local:10809/sda] is up.
[2022-07-21 12:43:11] INFO nbdhelper - getBlockInfo [sda]: Using Maximum Block size supported by NBD server: [33554432]
[2022-07-21 12:43:11] INFO nbdhelper - waitForServer [sda]: Connection to NBD backend succeeded.
[2022-07-21 12:43:11] INFO virtnbdbackup - backupDisk [sda]: Got 7 extents to backup.
[2022-07-21 12:43:11] INFO virtnbdbackup - backupDisk [sda]: 52428800 bytes disk size

next step would be: implement a file copy wrapper using paramiko which lets us copy remote additional vm files from the remotesystem to the local backup system.

abbbi commented 2 years ago

Remote backup/restore implemented,.. now some testing and code cleanup is required!