Hey Pascal,
The script has intelligence and keeps track of the guests state before backup.
If the guest was running when the backup was initiated then the guest will be started when the procedure completes.
However, if the guest was shut off when the backup was initiated, then the guest will not be started when the backup is finished.
Also make sure that the guest is defined in libvirt:
syntax: virsh define /path/to/dom/xml
example: virsh define /etc/libvirt/qemu/mbison.xml
Let me know if you have any other questions and I'll be glad to troubleshoot further.
hey Russel, first thanks for your answer. i create guest with the "virt-install" command. does this command define guest in libvirt ? what is the way to see if a guest is defined? when i do a virsh list --all i can see all my guest. when i use your script on a running guest, the backup works fine, but the guest is not re started. thanks again for your script and your answer.
Hey Russel,
something seems to be wrong with your script.
virt-back -p /root/backup/ -b vm132 Traceback (most recent call last): File "/usr/local/bin/virt-back", line 242, in if options.backup or options.backupall: backup( domList ) File "/usr/local/bin/virt-back", line 87, in backup tar.add( disklist[0] ) # we could loop and tar each disk in disklist IndexError: list index out of range
Creating the VM with "virt-back -v --create vm132" works like a charme. Also see
root@host ~ # virsh 'list'"
Id Name State
5 vm132 running
root@host ~ # virt-back --info-all --verbose
name: invoking name on vm132 name: name returned vm132 on vm132 info: invoking info on vm132 info: info returned [1, 524288L, 524288L, 1, 11680000000L] on vm132
ok, i see
origfile = disklist[0]
that only first drive is being backup.
Yes, my intention was to backup all images. I never got around to it...
I do many work on your script before : - I already implement multi-disk support - support for qcow2 snapshot to minimise the downtime. - usage "suspend" instead of "shutdown" - add option to restore a (previously backup) VM - add ability to migrate a VM (supend, transfer and re-up on another server)
have a look here if you want this full feature version : https://bitbucket.org/guilhemfr/virt-back
(I do pull-request for this...)
Hello,
Thanks for this utility. It is really useful.
I am using the script and have not had any success in limiting the number of retained backups. This ends up filling up my backup disk (a NAS drive mounted via NFS), so I need to figure out how to resolve it. Here is an example of the command I am using via cron job:
30 1 * * * /usr/local/bin/virt-back --quiet --backup --date --retention=2 -p /vmimages1/backups scre-ubuntu-log
The retention flag is being ignored. (Currently there are 4 backups stored, and if I don't delete them manually, they will stay there.) I am not seeing anything about the rotation in the logfile/syslog:
Sep 3 01:30:01 535-1201a-vm9 CRON[4486]: (root) CMD (/usr/local/bin/virt-back --quiet --backup --date --retention=2 -p /vmimages1/backups scre-ubuntu-log) Sep 3 01:30:02 535-1201a-vm9 virt-back: invoking shutdown on scre-ubuntu-log Sep 3 01:30:02 535-1201a-vm9 virt-back: waited 0 seconds for scre-ubuntu-log to shut off Sep 3 01:30:12 535-1201a-vm9 virt-back: waited 10 seconds for scre-ubuntu-log to shut off Sep 3 01:30:22 535-1201a-vm9 virt-back: waited 20 seconds for scre-ubuntu-log to shut off Sep 3 01:30:32 535-1201a-vm9 virt-back: waited 30 seconds for scre-ubuntu-log to shut off Sep 3 01:30:42 535-1201a-vm9 virt-back: waited 40 seconds for scre-ubuntu-log to shut off Sep 3 01:30:52 535-1201a-vm9 virt-back: waited 50 seconds for scre-ubuntu-log to shut off Sep 3 01:31:02 535-1201a-vm9 virt-back: invoking backup for scre-ubuntu-log Sep 3 01:31:02 535-1201a-vm9 virt-back: copying /vmimages1/img/scre-ubuntu-log.vmdk to /vmimages1/backups/scre-ubuntu-log.vmdk for scre-ubuntu-log Sep 3 01:32:46 535-1201a-vm9 virt-back: invoking create on scre-ubuntu-log Sep 3 01:32:50 535-1201a-vm9 virt-back: archiving files for scre-ubuntu-log to /vmimages1/backups/scre-ubuntu-log-2014-09-03.tar.gz Sep 3 01:32:50 535-1201a-vm9 virt-back: archiving /vmimages1/backups/scre-ubuntu-log.xml for scre-ubuntu-log Sep 3 01:32:50 535-1201a-vm9 virt-back: archiving /vmimages1/backups/scre-ubuntu-log.vmdk for scre-ubuntu-log Sep 3 01:52:58 535-1201a-vm9 virt-back: finished backup for scre-ubuntu-log
I would appreciate your help in resolving this. Thanks for this great utility.
Hey Jennifer,
Just a guess but I don't think the way I wrote the retention will work with the --date
option.
This is because the filenames are always unique. You must choose either to put dates into your filenames and find a different way to perform rotations, or use the --retention
flag and let virt-back
rotate the files.
Hello, getting this error:
root@cypdell1:/home/modias# ./virt-back --backup-all shutdown: invoking shutdown on oxygen shutdown: waited 0 seconds for oxygen to shut off shutdown: waited 10 seconds for oxygen to shut off backup: Create XML file with configuration of oxygen backup: invoking backup for oxygen backup: copy of /var/lib/libvirt/images/oxygen.img to /home/modias/oxygen.img Traceback (most recent call last): File "./virt-back", line 531, in files = backup(dom) File "./virt-back", line 134, in backup copytmpFile = join(options.backpath, basename(tmpfile)) File "/usr/lib/python2.7/posixpath.py", line 121, in basename i = p.rfind('/') + 1 AttributeError: 'NoneType' object has no attribute 'rfind'
i am running Ubuntu 14.04 LTS - the guest was running with a .img file under /lib/libvirt/images/os.img and a storage drive from a LVM
Hello Russell, i try your backup script, it seems to be very nice. But one thing is not very well. It use the normal gzip single threaded, that is very slow. I search your script, but python and I don't be friends ;) I don't find where you call gzip. Where can I change your script to use pigz? Thank You
Hello - is it possible to exclude one (or more) of the disk images associated with a VM? For instance, I have a VM that has two disk images associated with it - one is the OS/Applications and the other is Data. I only want to back up the Data image.
If this is not an option currently, please consider this a feature request. Thank you!
Just following up on this - not sure if you saw my initial comment regarding excluding certain disk images from backup. Thanks!