Exporting Snapshots from Glance

Exporting Snapshots from Glance

Exporting snapshots from glance is useful for offline/offsite archival backup/storage.  The glance API provides the tools to allow you to retrieve the snapshots stored in the database.  You should be familiar with the Using Glance article as many concepts covered there will be in use here.  

Supported Image Formats for Export

Before getting into the specific glance actions, it is key to understand the various disk image formats available for export because each one has different requirements.  Below are the specific image formats available when exporting. The snapshot image format is dictated by the format upon which the instance was based.

RAW

This is the raw unstructured disk format, a one-to-one match of what is stored on disk (including empty space).  This is the standard for Windows instances.

QCOW2

This is the standard format for QEMU-based emulation, with support for sparse data formats, saving disk space and network traffic.

AMI

This is the Amazon Machine Instance format for Linux images.  It consists of three separate files:

  • AMI - This file is a RAW copy of the Linux root filesystem of the instance
  • AKI - This file is a copy of the matching kernel (for example, vmlinuz-3.2.0-39)
  • ARI - This file is a copy of the corresponding compressed ramdisk (for example, initrd.img-3.2.0-39)

Using Glance API to Download Snapshots

Once you have a snapshot that you want to download, you'll want to verify a couple bits of information.  In this example, we'll work with an AMI.  

1) From the Dashboard or using the API, list the snapshot properties to find out the format and (in this case) the corresponding ARI and AKI:

$ glance image-show 4567i
+---------------------------------------+--------------------------------------+
| Property                              | Value                                |
+---------------------------------------+--------------------------------------+
| Property 'base_image_ref'             | 5                                    |
| Property 'image_location'             | snapshot                             |
| Property 'image_state'                | available                            |
| Property 'image_type'                 | snapshot                             |
| Property 'instance_type_ephemeral_gb' | 40                                   |
| Property 'instance_type_flavorid'     | 1                                    |
| Property 'instance_type_id'           | 1                                    |
| Property 'instance_type_memory_mb'    | 4096                                 |
| Property 'instance_type_name'         | m1.medium                            |
| Property 'instance_type_root_gb'      | 10                                   |
| Property 'instance_type_rxtx_factor'  | 1                                    |
| Property 'instance_type_swap'         | 0                                    |
| Property 'instance_type_vcpu_weight'  | None                                 |
| Property 'instance_type_vcpus'        | 2                                    |
| Property 'instance_uuid'              | 3428                                 |
| Property 'kernel_id'                  | 98t                                  |
| Property 'owner_id'                   | 2                                    |
| Property 'ramdisk_id'                 | 10r                                  |
| Property 'user_id'                    | 2                                    |
| checksum                              | b32b139a11ffab4d662614f33997e113     |
| container_format                      | ami                                  |
| created_at                            | 2013-06-28T17:42:15                  |
| deleted                               | False                                |
| disk_format                           | ami                                  |
| id                                    | 4567i                                |
| is_public                             | True                                 |
| min_disk                              | 0                                    |
| min_ram                               | 0                                    |
| name                                  | linux_snapshot                       |
| owner                                 | 2                                    |
| protected                             | False                                |
| size                                  | 999882752                            |
| status                                | active                               |
| updated_at                            | 2013-07-02T22:46:07                  |
+---------------------------------------+--------------------------------------+

Note that the disk and container formats are AMI, and because of that, you'll want to save the kernel_id and ramdisk_id values, because those will need to be downloaded as well.

2) Use the glance API image-download command to download the root disk, ramdisk, and kernel images using the saved IDs:

$ glance image-download 4567i --file linux_snapshot.ami
$ glance image-download 10r --file linux_snapshot.ari
$ glance image-download 98t --file linux_snapshot.aki

With those on local disk, you may then collect, archive, and move them as desired.

$ ls -l linux_snapshot.*
total 986944
-rw-r--r-- 1 user user   4956208 Aug  1 00:31 linux_snapshot.aki
-rw-r--r-- 1 user user 999882752 Aug  1 00:30 linux_snapshot.ami
-rw-r--r-- 1 user user   5781336 Aug  1 00:31 linux_snapshot.ari
$ tar -zcf linux_snapshot.tar.gz linux_snapshot.*
Have more questions? Submit a request
Powered by Zendesk