Snapshotting an instance

Snapshotting an instance will create a Glance image of the instance at the point in time the snapshot was taken. This image can then be used to deploy additional instances of a given application, or as a bootable backup of the instance.

Getting ready

In order to create a snapshot of an instance, you require the following information:

  • The openstack command-line client
  • The openrc file containing appropriate credentials
  • The name of the instance

How to do it…

The following commands are used to create an instance snapshot:

  1. First, we list the existing images with the following command:
    openstack image list -c Name -c Status
    

    This will bring back a list of images like the following:

    How to do it…
  2. Now list the running instances with the following command:
    openstack server list -c Name -c Status
    

    This gives an output like the following:

    How to do it…
  3. To create the snapshot, issue the following command (note the optional shell expansion command we're using to timestamp the name of the snapshot):
    openstack server image create
        --name cookbook.test_snapshot-$(date +"%FT%H%M%S")
        cookbook.test
    

    This brings an output like the following:

    How to do it…
  4. We can verify that the snapshot was created with the following command. Note that we limited the screenshot to just show our snapshotted image:
    openstack image list
    

    This gives an output that will show our snapshotted image:

    How to do it…

How it works…

Instance snapshots create a Glance image of the running instance. The snapshot can be used for backup, redistribution, or part of a continuous deployment pipeline as a build artifact. The images created with openstack server image create --name [snapshot_name] [instance] are bootable. You have a large degree of flexibility in how they are used.

There's more…

Instance snapshots are rather powerful. While a full exploration of the possibilities are beyond the scope of this book, the following example shows you what can be achieved using this feature: an easy way to back up all running instances.

To snapshot every instance, use the following command:

for instance in $(openstack server list -f value -c ID); do {
    openstack server image create 
      --name "${instance}"-$(date +"%FT%H%M%S") ${instance}
}; done

Tip

Warning: Snapshotting every instance is not recommended for larger environments. In addition to being time consuming, it can also consume a rather large amount of storage used by Glance, as snapshots are not sparsely created like those of the original QCOW2 image you may have used

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.218.19