# Contribution: OpenNebula backup script for QCOW2 datastores

**URL:** <https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368>\
**Category:** Integration Support\
**Created:** [December 3, 2017, 12:09am UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368 "2017-12-03T00:09:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![feldsam](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/feldsam/32/4441_2.png) [@feldsam](https://forum.opennebula.io/u/feldsam)\
**Post date:** [December 3, 2017, 12:09am UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/1 "2017-12-03T00:09:50Z")

</div>

Hello, I just release script for backing up QCOW2 datastores with live snapshot support.

> **[GitHub - OpenNebula/addon-image-backup: OpenNebula backup script for QCOW2 datastores](https://github.com/OpenNebula/addon-image-backup)**
>
> OpenNebula backup script for QCOW2 datastores

---

<div class="post-metadata">

**Author:** ![feldsam](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/feldsam/32/4441_2.png) [@feldsam](https://forum.opennebula.io/u/feldsam)\
**Post date:** [March 9, 2018, 9:21pm UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/2 "2018-03-09T21:21:01Z")

</div>

Hi all, addon was updated with new features and fixes.

Actual version 1.2.0

Changes since first version:

- Live snapshotting added fallback in case that FS freeze fails
- Fix backup persistent used images if VM is not in ACTIVE state
- new option -k --insecure for use rsync with weakest but fastest SSH encryption
- other rsync options adjustments to improve speed
- new option -n --netcat for use netcat instead of rsync to transfer main image (\*.snap dirs still use rsync)
- extended -i --image option to support multiple image IDs separated by comma

> **[OpenNebula/addon-image-backup](https://github.com/OpenNebula/addon-image-backup/releases)**
>
> OpenNebula backup script for QCOW2 datastores. Contribute to OpenNebula/addon-image-backup development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![uli](https://avatars.discourse-cdn.com/v4/letter/u/ccd318/32.png) [@uli](https://forum.opennebula.io/u/uli)\
**Post date:** [April 10, 2018, 8:12am UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/3 "2018-04-10T08:12:20Z")

</div>

Hallo Kristian,

thanks a lot for this contribution. I believe this is a very important piece for the OpenNebula project.

I did some tests and found a problem with this addon in my setup.  
In general I followed the standard installation instructions to install OpenNebula 5.4.10 on CentOS 7. The only difference is that I installed the Enterprise version of qemu-kvm (Package qemu-kvm-ev) in order to have access to some features not present in the standard package.  
Besides this everything is according standard instructions.  
The point is that in this setup libvirt is not enabled for tcp connections (I get a connection refused when your script tries to create the snapshot by running virsh). And to enable libvirt for tcp with proper authentication adds some complexity to my setup.

Question:  
I understand that the virsh command is anyhow executed locally on the remote kvm node. Your are using  
virsh -c qemu+tcp://localhost/system … for snapshot and blockcommit.  
And I found out that  
virsh -c qemu:///system … works in my setup without any other changes in my setup.  
Do you see a possibility to change the virsh command in one-image-backup.js to virsh -c qemu:///system?

Thanks and Best Regards  
Uli

---

<div class="post-metadata">

**Author:** ![feldsam](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/feldsam/32/4441_2.png) [@feldsam](https://forum.opennebula.io/u/feldsam)\
**Post date:** [April 10, 2018, 8:19am UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/4 "2018-04-10T08:19:47Z")

</div>

Hello @uli, thank you for praise. I forgot mention this in docs. I am using tuned KVM driver. Look on [KVM Driver docs - Tuning & Extending](https://docs.opennebula.org/5.4/deployment/open_cloud_host_setup/kvm_driver.html#tuning-extending)

EDIT: Of course, I can add it to config.

---

<div class="post-metadata">

**Author:** ![uli](https://avatars.discourse-cdn.com/v4/letter/u/ccd318/32.png) [@uli](https://forum.opennebula.io/u/uli)\
**Post date:** [April 10, 2018, 10:16am UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/5 "2018-04-10T10:16:42Z")

</div>

Ok, thanks. That link to the Tuning Guide makes it very clear, although I have some security related doubts with this setup (non-authenticated and non-encrypted). Network isolation should be bullet proof. Just my opinion…

Anyway I would appreciate it if you can add it to the config. Keep up the good work!

---

<div class="post-metadata">

**Author:** ![feldsam](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/feldsam/32/4441_2.png) [@feldsam](https://forum.opennebula.io/u/feldsam)\
**Post date:** [April 11, 2018, 6:58am UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/6 "2018-04-11T06:58:01Z")

</div>

Hi all, I just released version 1.4.1.

Changes since version 1.2.0

New features:

- new config option libvirtUri to configure custom hypervisor connection URI
- new option -S --start-image \<image\_id\> image id to start backup from

Other changes:

- rsync use inplace option because we use custom tmp files
- don’t update images backup info in opennebula when dry run is used
- removed netcat option from backup.sh script due to experimental nature of that feature
- backup main images to tmp file and after copy replace original one

---

<div class="post-metadata">

**Author:** ![uli](https://avatars.discourse-cdn.com/v4/letter/u/ccd318/32.png) [@uli](https://forum.opennebula.io/u/uli)\
**Post date:** [April 11, 2018, 4:22pm UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/7 "2018-04-11T16:22:11Z")

</div>

Hi Kristian,

thanks a lot for the quick update. I may have another feature request, if I may ask.  
Similar to the -i option I would love to see a --datastore option to include all images from the datastores in a comma separated listed.  
This is similiar to the way we handle “protected” and “unprotected” datastores in our vSphere environment, because we do not want to backup all images. The placement of vm-image decides if it is backuped or not.

Thanks  
Uli

---

<div class="post-metadata">

**Author:** ![feldsam](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/feldsam/32/4441_2.png) [@feldsam](https://forum.opennebula.io/u/feldsam)\
**Post date:** [April 14, 2018, 10:25am UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/8 "2018-04-14T10:25:34Z")

</div>

Hello, I pushed updated version to develop branch. Please test it. If all goes ok, them I’ll publish new release.

> **[OpenNebula/addon-image-backup](https://github.com/OpenNebula/addon-image-backup/tree/develop#list-of-options)**
>
> OpenNebula backup script for QCOW2 datastores. Contribute to OpenNebula/addon-image-backup development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![uli](https://avatars.discourse-cdn.com/v4/letter/u/ccd318/32.png) [@uli](https://forum.opennebula.io/u/uli)\
**Post date:** [April 17, 2018, 4:36am UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/9 "2018-04-17T04:36:02Z")

</div>

Yesterday I tested the develop branch with the -a (datastores) option and your addon backuped all images from the specified datastores. Brilliant!

One last idea came to my mind to further enhance the addon:  
Backup all datastores and images with a specific label (e.g. ‘protected’). This logic would be simple and similar to your ansible inventory script and would give users much more control over the backup in sunstone.  
But for now I am already very happy with the datastores option. Thanks Kristian!

---

<div class="post-metadata">

**Author:** ![feldsam](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/feldsam/32/4441_2.png) [@feldsam](https://forum.opennebula.io/u/feldsam)\
**Post date:** [April 17, 2018, 6:30pm UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/11 "2018-04-17T18:30:36Z")

</div>

New release 1.6.1!

Changes since version 1.4.1:

New features:

- new option `-a --datastore` to backup from specific datastore(s)
- new option `-l --label` to backup image(s) and/or datastore(s) by specific label(s)

Other changes:

- code enhancements

---

<div class="post-metadata">

**Author:** ![uli](https://avatars.discourse-cdn.com/v4/letter/u/ccd318/32.png) [@uli](https://forum.opennebula.io/u/uli)\
**Post date:** [April 18, 2018, 6:28am UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/12 "2018-04-18T06:28:34Z")

</div>

I can confirm both options are working in our environment (also with nested labes like “images/protected”).  
Great addon.

---

<div class="post-metadata">

**Author:** ![Snowman](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Snowman](https://forum.opennebula.io/u/Snowman)\
**Post date:** [April 19, 2018, 7:54am UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/13 "2018-04-19T07:54:22Z")

</div>

Hi @feldsam ,  
I just want to ensure myself that I understand how your addon works. I wonder how your script will backup my VM images. I have image type DATABLOCK with “Persistent” setting set to “no”, this image is used by VMs as OS/DATA disk.

VM disk image looks like this :  
qemu-img info 0  
image: 0  
file format: qcow2  
virtual size: 10G (10737418240 bytes)  
disk size: 9.7G  
cluster\_size: 65536  
backing file: /var/lib/one/datastores/103/cdfd110a37e569165315b96f913293a2  
Format specific information:  
compat: 1.1  
lazy refcounts: false  
refcount bits: 16  
corrupt: false

Can you explain please if VM will be snapshoted, than backed up and block commited, or not ?  
Thanks.

---

<div class="post-metadata">

**Author:** ![feldsam](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/feldsam/32/4441_2.png) [@feldsam](https://forum.opennebula.io/u/feldsam)\
**Post date:** [April 19, 2018, 10:55am UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/14 "2018-04-19T10:55:33Z")

</div>

Hello, in OpenNebula there are two types of images, as you already know:

- non-persistent
- persistent

### Non-persistent

You can deploy many VMs using same non-persistent image. On the background, oned creates new qcow2 image which have backing image of that non-persistent one. That new image is deployed to system datastore.  
When you terminate VM instance, that image deployed to system datastore will be deleted. So from nature of this functionality, VMs deployed from non-persistent images have character of instances of base image and should not persist data and should not be backuped. This is ideal for applications, which can run several times at once for horizontal scaling. These instances usually connects to same shared database server and/or shared file server (nfs) to persist data. When VM instance need to persist data, them there should be attached persistent datablock or VM should be instatiated as persistent.

### Persistent

Persistent image can be attached to only one VM and changes made in VM instance persists after undeploys/terminates. This images are backuped and also, if attached to running VM, live snapshoted.

---

<div class="post-metadata">

**Author:** ![Snowman](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Snowman](https://forum.opennebula.io/u/Snowman)\
**Post date:** [April 19, 2018, 3:20pm UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/15 "2018-04-19T15:20:14Z")

</div>

This is kind of pitty because I use these non-persistent images for all VMs. **In my environment after undeploy action machine goes to shutdown and than undeployed state (it free up resources on node) but disks or machine image files stays on hypervisor datastore untouched, so it could be backed-up.** (this behaviour is not the same as you described - dunno why) I use GlusterFS (via libgfapi) to access disk images. Termination state deletes VM and related files of course.

So to use your script I have to make all disks of all VMs persistent. (now images are presented as non-persistent images backed by image from image datastore). Do you think this is good approach or I should rewrite your script in the way it will backup also non-persistent images with same logic as persistent ?

Thanks for any suggestions in advance.

---

<div class="post-metadata">

**Author:** ![feldsam](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/feldsam/32/4441_2.png) [@feldsam](https://forum.opennebula.io/u/feldsam)\
**Post date:** [April 19, 2018, 3:39pm UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/16 "2018-04-19T15:39:27Z")

</div>

Hmm, also name “non-persistent” have character of “temporary” disk, where data doesn’t matter. Base images are of course backuped, but not non-persistent part of attached image.

I think, that every VM, which have data, that needs to be persistent, have to use persistent images. On instantiate tab, you can select “instantiate as persistent”, or you can already instatiated non-persistent VMs “save as” and make them persistent. When you need terminate VM, them you should delete also VM Template with All disks, so you free up space.

Of cource, I can add new option to backup also non persistent VMs, but from nature of non-persistent vs persistent feature, you should decide rework your setup.

---

<div class="post-metadata">

**Author:** ![Snowman](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Snowman](https://forum.opennebula.io/u/Snowman)\
**Post date:** [April 19, 2018, 3:43pm UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/17 "2018-04-19T15:43:04Z")

</div>

I will do some research and let you know, because probably this is related to GlusterFS and OpenNebula driver for Gluster itself. This is probably why my non-persistent VMs and their images stayed untouched after undeploy operation.

Anyway thanks for help for now 🙂

EDIT: Also non-persistent images as I am using them saving space on storage because base system is not copied multiple times for every VM, it can also be “super cached” to some hot-tier cache because multiple VMs using same file to work (base image)

---

<div class="post-metadata">

**Author:** ![uli](https://avatars.discourse-cdn.com/v4/letter/u/ccd318/32.png) [@uli](https://forum.opennebula.io/u/uli)\
**Post date:** [April 20, 2018, 7:58am UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/18 "2018-04-20T07:58:35Z")

</div>

From the official documentation ([https://docs.opennebula.org/5.4/operation/vm\_management/vm\_instances.html](https://docs.opennebula.org/5.4/operation/vm_management/vm_instances.html)):  
“Undeploy -\> The VM is shut down. The VM disks are transfered to the system datastore. The VM can be resumed later.”

I understand that undeployed VMs still hold their “non-persistent” data. But as soon as you terminate a VM with non-persistent disks all changed data (to the base image) is lost.

---

<div class="post-metadata">

**Author:** ![atodorov\_storpool](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/atodorov_storpool/32/5327_2.png) [@atodorov\_storpool](https://forum.opennebula.io/u/atodorov_storpool)\
**Post date:** [April 20, 2018, 8:25am UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/19 "2018-04-20T08:25:17Z")

</div>

Undeploy and Terminate are two separate actions. The transaction of the states is as follow

Undeploy: --\> [epilog] --\> [undeployed]  
Terminate: --\> [epilog] --\> [done]

---

<div class="post-metadata">

**Author:** ![feldsam](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/feldsam/32/4441_2.png) [@feldsam](https://forum.opennebula.io/u/feldsam)\
**Post date:** [April 20, 2018, 9:13am UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/20 "2018-04-20T09:13:10Z")

</div>

@uli u a right, I updated my prev post.

---

<div class="post-metadata">

**Author:** ![mptek](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@mptek](https://forum.opennebula.io/u/mptek)\
**Post date:** [July 8, 2018, 2:14pm UTC](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368/21 "2018-07-08T14:14:51Z")

</div>

First of all thank you @feldsam for your work.  
I think that a backup mech on opennebula is a must.  
When i first use ON i’ve searched for hours an integrated backup.  
Integration with sunstone will be the next step 😉.

**I support the question of “Snowman Martin”.**

I’m using ON like a cloud ISP and in this situation all VM are non persistent.  
My customer create VM from a template, use it for months or years and then terminate VM.  
In the last case the non persistent disk is deleted.  
**But in between non-persistent disk are to be backupped and ARE IN USE.**  
In this situation the process of “snapshot(+quiesce)+backup+blockcommit” are IMHO necessary.

Or i’m using ON wrong 🤔?

Thank you very much in advance.  
Mirko

[Next page](https://forum.opennebula.io/t/contribution-opennebula-backup-script-for-qcow2-datastores/5368.md?page=2)
