How to restore VM

Hi,

In my environment, system datastores are placed locally in the nodes therefore if one node fails, I will loose al my persistent virtual machines runing on it.

In order to avoid this lost of information if a node crashes or if the VM is deleted accidentally, I have scheduled a backup script of my VMs on every node even if they are running or stopped. I’m copying the last deployment.X file and the disk.0 file as well to an external nfs repository.

Is there any procedure to “register” my VM backup in opennebula if it has been accidentally deleted or the node has crashed?

Thanks a lot.

Hi!

Nobody has had the need of restoring a virtual machine in the OpenNebula ?

Any help will be welcome!

Thanks a lot.

Hi,

If you are using persistent images, you should restore the files in the IMAGE datastore from the backups with same file names and issue recover with “delete-recreate” (in sunstone it is at the bottom of the drop-down where the migrate commands are: “Recover”, then in the select box use delete-recreate). In this case the VM will be recreated with same MAC address. It is possible to do delete and then deploy from same VM template but then the VM will have different MAC address if it is not set to static somehow. The bold key here is that the images are of type PERSISTENT!

Hope this helps.

Best regards,
Anton Todorov

Hi Anton,

Thanks a lot and it may be a good approach if the virtual machine already exists in sunstone.

What I’d like to know is the restore procedure of a VM that does not longer exists in sunstone/opennebula database. I mean: once I have restored the files in a system datastore (my VMs are linked clones), how can I make it appear in sunstone?

Thanks in advance!

Hi oscar,

I think it is possible with some manual work. The VM definition is still available in the database but in “DONE” state. You can try editing the database records and change both vm_pool.body(replace <STATE>6</STATE> with <STATE>9</STATE>) and set vm_pool.state to 9 (9 is the UNDEPLOYED state) for the given VM. You must stop the opennebula service during the database changes because oned is caching the data.

I’ve made the following helper script to deal with the database:

Example usage session:

VMID=106
VMSTATE=9
DBUSER=oneadmin
DBPASS=password
DBHOST=127.0.0.1
DBNAME=opennebula 
systemctl stop opennebula
./summon.py $VMID $VMSTATE mysql:$DBUSER:$DBPASS:$DBHOST:$DBNAME
systemctl start opennebula

As this is a basic example it is possible to not work on your setup but you can use it as inspiration to develop own solution though.

Best Regards,
Anton Todorov

Hi Anton,

In my enviornment my images datastore are NFS (qcow2) shared. But my system datastores are not shared (ssh). When I execute undeploy, opennebula tries to copy the qcow2 disk (linked clone) placed on kvm nodes to the opennebula server filesystem and this raises an error in my environment.

¿What do you think about setting the status to “POWEROFF”?

Thanks a lot.

Hm. It should work. You need to create the VM home in the hypervisor though. It should be something like

# on the KVM host
su - oneadmin -c mkdir -p /var/lib/one/datastores/$SYSTEM_DS/$VMID/

# this should be done manually!
# create proper symlinks to the right IMAGE disks or files restored from backups...

# then on the front-end
SYSTEM_DS=0
VMID=106
VMSTATE=8
DBUSER=oneadmin
DBPASS=password
DBHOST=127.0.0.1
DBNAME=opennebula 
systemctl stop opennebula
./summon.py $VMID $VMSTATE mysql:$DBUSER:$DBPASS:$DBHOST:$DBNAME
systemctl start opennebula

The POWEROFF state is ‘8’ (changed in the above example).

Then, if everything is ok, when you resume the VM the checkpoint ISO disk and the domain XML will be recreated and the VM started.

Best Regards,
Anton Todorov

Hi Anton, I will try out your procedure.

Meanwhile I’d like to ask for this approach:

If I force the system datastore of opennebula server to be the backup file system where I copy the offline backup of my virtual machines (with a simple symbolic link) the first approach you have posted (State=9) may work. ¿Isn’t it?

It is, If I run “onevm deploy”, will opennebula copy the VM from the opennebula server system datastore to any available opennebula node system datastore?

Thanks a lot for your time.

Best approach is to do some tests with a disposable VMs until you have clear procedure :wink:

Best Regards,
Anton

Yes… I agree. I will make some tests and I’ll let you know.

Thanks a lot!