Copying a VM between clusters

When you have set up OpenNebula with StorPool on two or more sites, you can copy a VM from one site to another by setting up multi-site cluster, or by exporting the VM and then importing it.

Using multi-site

StorPool provides a multi-site functionality (see Multi site) that can be used for connecting two or more clusters. The connection is done over TCP and requires the nodes to talk with each other. If needed, you can also create a VPN between the two clusters, and then set up the connection.

If you have your clusters connected this way you can move volumes and snapshots between the locations.

Transferring a VM

If setting up the VPN connection between the clusters is not an option, then you can do the following:

  1. Create a snapshot of the VM and export it as a raw image.

  2. Transfer the image to the other location and import it there.

The sections below provide details on how to do this. For convenience, the site from which you are exporting is referred to as ‘site A’, and the site to which you are importing is referred to as ‘site B’.

Exporting a snapshot

  1. Create the snapshot on site A.

  2. Connect via SSH to the OpenNebula controller on site A.

  3. Verify the image is available (vps-image-os08 in the example here):

    oneimage list
    ID USER GROUP NAME DATASTORE SIZE TYPE PER STAT RVMS
    110 ex-site oneadmin vps-image-os08 StorPool - 40G OS No rdy 0
    
  4. Find the StorPool volume corresponding to this image; let’s assume the volume is one-img-110.

  5. Attach the volume to one of the cluster nodes (for example, to node node01.example.com):

    storpool attach volume one-img-110 here
    

    This command will attach the volume in /dev/storpool/one-img-110.

  6. Create an archive:

    dd if=/dev/storpool/one-img-110 bs=1M iflag=direct status=progress | gzip --fast > one-img-110.gz.
    

Now you have the image exported as a regular archive in node01.example.com:/home/one-img-110.gz.

Importing a snapshot

  1. Transfer the archive you have created to site B.

  2. On Sunstone (the Web GUI) create a new image template as follows:

    • The image should be created as empty.

    • The size should be set to the same amount as the source image.

    • Use the same name as the one on site A (vps-image-os08 in the example here).

  3. Locate the StorPool volume for that image; let’s assume the volume is one-img-118.

  4. Attach the volume to a node:

    storpool attach volume one-img-118 here
    
  5. Copy the data to the volume:

    zcat one-img-110.gz | dd of=/dev/storpool/one-img-118 bs=1M oflag=direct iflag=fullblock status=progress
    
  6. After the copying completes you have to detach the volume:

    storpool detach volume one-img-118 here
    

And now you have a template one-img-118 in site B with the same name (vps-image-os08), which can be used to instantiate VMs.

More information

Attachments