dguerri / LibVirtKvm-scripts

Libvirt/KVM scripts - online forward incremental backup for libvirt/KVM virtual machines
GNU General Public License v3.0
72 stars 25 forks source link

Consolidating a not running domain results in a Backup of its single files #24

Closed tobiasrodehutskors closed 8 years ago

tobiasrodehutskors commented 9 years ago

I created some live backups of a virtual machine and afterwards wanted to consolidate them into a single image. I turned the VM off and used the following command:

sudo ./fi-backup.sh -c -d t64web
[INF] libVirt version '1.2.8' support is experimental
[DEB] /usr/bin/qemu-img version '2.1.0' is supported
[DEB] QEMU/KVM version '2.1.0' is supported
[DEB] Domains NOTRUNNING:  t64web
[DEB] Domains RUNNING: 
[DEB] Backing up: cp -up  /
[DEB] Parent block device: '/var/lib/libvirt/images/t64web.bimg-20151029-083223'
[DEB] Backing up: cp -up /var/lib/libvirt/images/t64web.bimg-20151029-083223 /
[DEB] Next file in backing file chain: '/var/lib/libvirt/images/t64web.qcow2'
[DEB] Parent block device: '/var/lib/libvirt/images/t64web.qcow2'
[DEB] Backing up: cp -up /var/lib/libvirt/images/t64web.qcow2 /
[DEB] Next file in backing file chain: ''
[DEB] All 3 block files for 't64web': /var/lib/libvirt/images/t64web.bimg-20151029-083332 : /var/lib/libvirt/images/t64web.bimg-20151029-083223 /var/lib/libvirt/images/t64web.bimg-20151029-083223 /var/lib/libvirt/images/t64web.qcow2

I expected that consolidation for not running domains works the same way as for running domains. Nevertheless, that is currently not the case. Instead the script started to back up the image files to the root folder /. I had a quick tool into the script and it seems that it simply backups all domains which are currently not running. I think this should be fixed.

I am using version 2.1.0 which I pulled from the master branch on Oct. 29th.

$ ./fi-backup.sh -V
fi-backup version 2.1.0
AJRepo commented 9 years ago

Virsh requires that a domain be running for consolidation. If you try consolidating a non-running domain, virsh will give the error:

error: Requested operation is not valid: domain is not running

Having a backup script start offline domains (which are probably off for a reason) in order to do work on them is not recommended.

The only "solution" then would be to specify that consolidation only works with running domains.

AJRepo commented 9 years ago

See Pull Request #25

dguerri commented 9 years ago

Thanks @AJRepo, awesome work!

In a next release we could think about introducing an additional flag for offline images backup. Having the backup performed always, regardless of the mode specified by the user, could be a bit confusing. Alternatively we could just exit with an error if -c is used.

Let's wait for @tobiasrodehutskors to give your patch a go and then we can merge.

AJRepo commented 9 years ago

I was thinking along the same lines. Also since someone could have a domain named "all" , perhaps replace matching logic $DOMAIN=="all" with flags that indicate full backup and type. E.g. -a||--all --all-running --all-shutoff, --all-paused