Topic: https://russell.ballestrini.net/virt-back-a-python-libvirt-backup-utility-for-kvm-xen-virtualbox/
hide preview

What's next? verify your email address for reply notifications!

Pascal-rb 13y, 4d ago

Hello, i'm trying your script to backup guest. I thought when the backup was done the script restarted the guest but it is not the case. could you give me information? thanks for your script bye

hide preview

What's next? verify your email address for reply notifications!

russell 13y, 3d ago

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.

hide preview

What's next? verify your email address for reply notifications!

Pascal-rb 13y, 3d ago

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.

remark link
hide preview

What's next? verify your email address for reply notifications!

russell 13y, 3d ago

Could you try a test for me?

Could you shut off your guest and then try to start it using virt-back?

shutdown

virsh shutdown

start

virt-back --verbose --create

If this doesn't work there might be something wrong...

hide preview

What's next? verify your email address for reply notifications!

Pascal-rb 12y, 361d ago

Hey Russel, it was a mistake from me. i let the script in my home directory. after i put it in /usr/local/bin, it works thanks for your answers and your script

hide preview

What's next? verify your email address for reply notifications!

Tobias-rb 12y, 354d ago

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

hide preview

What's next? verify your email address for reply notifications!

George-rb 12y, 275d ago

Hi Russell,

I was able to successfully backup my VM using your script, but I can't figure out how to restore it. I just rebuild my system and need your help!

Thx

remark link
hide preview

What's next? verify your email address for reply notifications!

russell 12y, 268d ago

I have written a procedure for restoring a system from a virt-back guest backup.

http://russell.ballestrini.net/virt-back-restoring-from-backups/

I hope this guide will help.

hide preview

What's next? verify your email address for reply notifications!

Lenny-rb 12y, 115d ago

Thanx! How to select for saving not all disks of VM? And what's the difference between an snapshot and ordinary backup?

hide preview

What's next? verify your email address for reply notifications!

Lenny-rb 12y, 115d ago

ok, i see: "A snapshot volume only stores the delta (changes) since it was created. This is convenient for a point-in-time, well, snapshot, but if your original data is lost, you can't restore from a snapshot. " What about first question?

hide preview

What's next? verify your email address for reply notifications!

Lenny-rb 12y, 114d ago

ok, i see

origfile = disklist[0]

that only first drive is being backup.

remark link
hide preview

What's next? verify your email address for reply notifications!

russell 12y, 113d ago

Yes, my intention was to backup all images. I never got around to it...

remark link parent
hide preview

What's next? verify your email address for reply notifications!

Guilhem-Lettron-rb 11y, 356d ago

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...)

hide preview

What's next? verify your email address for reply notifications!

russell 12y, 49d ago

virt-back can now backup all attached disk images.

Install the latest version today.

https://bitbucket.org/russellballestrini/virt-back/changeset/b2bc219d6c6a

hide preview

What's next? verify your email address for reply notifications!

James-rb-1SP 12y, 38d ago

Excellent script. Works like a charm.

I will make very good use of it.

Great work!

hide preview

What's next? verify your email address for reply notifications!

Dustin-Lambert-rb-LIN 11y, 234d ago

This is awesome; These types of things should just be included out of the box.

Thanks for sharing!

hide preview

What's next? verify your email address for reply notifications!

himuraken-rb 11y, 214d ago

Excellent tool, thanks for making it! I have looked around but I dont seem to find anyway to increase the number of backups to retain. Any tips?

remark link
hide preview

What's next? verify your email address for reply notifications!

russell 11y, 213d ago

himuraken, Today is your lucky day. I have implemented a retention flag for setting the amount of backups to keep when rotating. Please use the latest version of virt-back.

-a amount, --retention=amount backups to retain [default: 3]

hide preview

What's next? verify your email address for reply notifications!

himuraken-rb 11y, 214d ago

In fact, I did a vim /usr/local/bin/virt-back and found: if path.isfile( tarpath ): # if file exists, rotate 3 versions

Can I just increment rotate 3 to the number of revisions desired?

Thanks!

hide preview

What's next? verify your email address for reply notifications!

Dustin-Lambert-rb 11y, 176d ago

It would be great if the script would accept a shutdown time limit before it destroys the domain. I always have to increase it in the source.

Thanks again!

hide preview

What's next? verify your email address for reply notifications!

Jennifer-Mehl-rb 9y, 244d ago

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.

remark link
hide preview

What's next? verify your email address for reply notifications!

russell 9y, 244d ago

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.

remark link parent
hide preview

What's next? verify your email address for reply notifications!

Jennifer-Mehl-rb 9y, 244d ago

OK, thanks, I'll try removing the date option and see if retention works then. Thanks for the quick reply. Will let you know if that works.

remark link parent
hide preview

What's next? verify your email address for reply notifications!

Jennifer-Mehl-rb 9y, 242d ago

Removing the --date option worked. Thanks!

hide preview

What's next? verify your email address for reply notifications!

Marc-rb 9y, 175d ago

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

remark link
hide preview

What's next? verify your email address for reply notifications!

russell 9y, 173d ago

You have an LVM partition on the hypervisor mounted on the guest? Virt-back doesn't support that configuration.

hide preview

What's next? verify your email address for reply notifications!

ich-wer-sonst-rb 9y, 145d ago

Virt-backup without tar.gz at the end?

500Gb VM needs more like 5 hours to USB 3.0 disk

remark link
hide preview

What's next? verify your email address for reply notifications!

russell 9y, 104d ago

If you don't want to zip the 500G file, use this flag.

  -g, --no-gzip         do not gzip the resulting tar file

hide preview

What's next? verify your email address for reply notifications!

Björn-rb 8y, 295d ago

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

remark link
hide preview

What's next? verify your email address for reply notifications!

russell 8y, 95d ago

https://bitbucket.org/russellballestrini/virt-back/src/2f3b7a422097966ec2246ea59ced28fe8cb3707d/virt-back?at=default&fileviewer=file-view-default#virt-back-153

hide preview

What's next? verify your email address for reply notifications!

Jennifer-Mehl-rb 8y, 275d ago

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!

remark link
hide preview

What's next? verify your email address for reply notifications!

Jennifer-Mehl-rb 8y, 243d ago

Just following up on this - not sure if you saw my initial comment regarding excluding certain disk images from backup. Thanks!

remark link parent
hide preview

What's next? verify your email address for reply notifications!

russell 8y, 235d ago

Hi Jennifer, I saw your comments, virt-back will always attempt to backup all disk images related to a particular guest. Excluding disk / devices is currently not supported.

remark link parent
hide preview

What's next? verify your email address for reply notifications!

Jennifer-Mehl-rb 8y, 163d ago

Thanks for the answer on that. I would appreciate if the ability to exclude specific disk images would be supported in a future version. Thanks for this great utility.

hide preview

What's next? verify your email address for reply notifications!

Sven-rb 8y, 190d ago

Thanks for sharing this script! Works like a charm!

hide preview

What's next? verify your email address for reply notifications!

aaron-rb 8y, 47d ago

Hello! One of the VMs does not start after the backup. How to turn on debug logging level? Thanks!

hide preview

What's next? verify your email address for reply notifications!