eslam-gomaa / virt-backup

Fully backup your KVM Virtual Machines
28 stars 2 forks source link

error in disk backup #3

Closed andreasc87 closed 3 years ago

andreasc87 commented 3 years ago

I have little to no experience with ruby, I just found your project to be exactly what I needed - Thank you 👍

I did however have some issues when trying to do a VM backup.

OS: Newly installed and fully updated Ubuntu 20.04 LTS server

I executed with the following command:


sudo ruby virt-backup.rb --backup \ --with-snapshots \ --original-vm win2k19 \ --compression best \ --save-dir /mnt/usbdisk/win2k19_Saturday/


I got the following output:


[ Warning ] (1) Missing disk/s found, Will NOT be backed up: => ["/var/lib/libvirt/images/win2k19.qcow2' index='1"]

[ INFO ] Current VM State: running [ INFO ] Pausing the VM [ INFO ] Getting checksum of the Files will be backed up - May take time based on size [ INFO ] Backing up VM: (win2k19), N of disks: (0) - May take time based on size => win2k19.checksum [OK] => win2k19.xml [OK] [ INFO ] Resuming the VM [ INFO ] Current VM State: running [ INFO ] Backup stored successfully in (/mnt/usbdisk/win2k19_Saturday/win2k19.zip)


For the fixing I added: STDERR.puts File.readlines(xml.path).grep(/source file=/).collect {|disk| disk.strip.gsub(/source file=/, '').gsub(/<'/,'').gsub("'/>", '')} to line 100 in functions.rb

This line also output "/var/lib/libvirt/images/win2k19.qcow2' index='1" without the ""

I the edited line 98 to to remove the stuff I did not want in there, which made it look like this: info[:disks] = File.readlines(xml.path).grep(/source file=/).collect {|disk| disk.strip.gsub(/<source file=/, '').gsub(/\/>/, '').gsub("'", '').gsub(/ index=1/, '')}

I know it is not pretty. Not even correct by any standards, but as I have never before today looked at a ruby script, I think it went alright. A proper ruby programmer like yourself could probablt easily figure out what went wrong.

Also, the first thing I tested was that the qcow2 file was infact where it looked for it, and it was.

the XML file for the VM in question


win2k19 13ce54b2-cf58-4f10-8c99-0e79b2fafe05 8388608 8388608 16 hvm destroy restart destroy /usr/bin/qemu-system-x86_64
andreasc87 commented 3 years ago

apparently it clipped the XML file. I will add it here as an attached file. win2k19.xml.txt

eslam-gomaa commented 3 years ago

Hello Andrea,

Thank you for letting me know

To give you a simple reply: the problem is somehow the following block in the XML had an extra String 'inxex=1' for example <source file='/var/lib/libvirt/images/win2k19.qcow2 index=1'/>

    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/win2k19.qcow2'/>
      <target dev='sda' bus='sata'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>

Not sure how, because it does not exist in the XML you've attached, also I've defined your XML on a test machine and the backup worked normally.


Anyway, it's not a problem

I modified line 98 , It's very close your modifications but matches any index number (there is no problem if the index part does not exist)

info[:disks] = File.readlines(xml.path).grep(/source file=/).collect {|disk| disk.strip.gsub(/source file=/, '').gsub(/<'/,'').gsub("'/>", '').gsub(/index=[0-9]+/, '')}

I'd like to thank you again, and please feed me back after your test

Eslam

andreasc87 commented 3 years ago

I swapped out the line I edited with the one you have now made, and that set me back to generating this error: [ Warning ] (1) Missing disk/s found, Will NOT be backed up: => ["/var/lib/libvirt/images/win2k19.qcow2' index='1"]

[ INFO ] Current VM State: running [ INFO ] Pausing the VM [ INFO ] Getting checksum of the Files will be backed up - May take time based on size [ INFO ] Backing up VM: (win2k19), N of disks: (0) - May take time based on size => win2k19.checksum [OK] => win2k19.xml [OK] [ INFO ] Resuming the VM [ INFO ] Current VM State: running [ INFO ] Backup stored successfully in (/mnt/usbdisk/win2k19_Sunday/win2k19.zip)

I have double checked that the XML i posted here is infact the correct one. There is no mentions of index=1 or anything else in said line.

eslam-gomaa commented 3 years ago

So, if that .gsub(/ index=1/, '') fixed your issue, may u try .gsub(/ index=[0-9]+/, '') ?

andreasc87 commented 3 years ago

give me a second.

andreasc87 commented 3 years ago

Still generating the same error. that made no changes

andreasc87 commented 3 years ago

I can use the index=[0-9]+ part. I've replaced my / index=1/ with / index=[0-9]+ and that worked, making the complete line looking like so: info[:disks] = File.readlines(xml.path).grep(/source file=/).collect {|disk| disk.strip.gsub(/<source file=/, '').gsub(/\/>/, '').gsub("'", '').gsub(/ index=[0-9]+/, '')}

andreasc87 commented 3 years ago

(perhaps that was what you wanted to me try all along? ) :)

eslam-gomaa commented 3 years ago

Actually, that's what I wanted to test :)

Glad that it worked, Thanks a lot

andreasc87 commented 3 years ago

Excellent & you're welcome. Thanks for spending the time. Have a good day.