Updated

Snapshots

What are Snapshots?

A snapshot is a mechanism that allows you to create a new image from a running instance. This mainly serves two purposes:

  1. As a backup mechanism: save the main disk of your instance to an image and later boot a new instance from this image with the saved data.
  2. As a templating mechanism: customise a base image and save it to use as a template for new instances.

Simply put, you can create snapshots of instances that are configured just the way you want them! No more manually configuring each new instance. You can simply create more instances from the snapshot or you can save them as a backup.

How to create snapshots

There are two ways to create snapshots using OCS. The first way is through ocs.oneqode.com on your browser.

Using the browser

On ocs.oneqode.com, log in and find “Cloud” on the left main navigation bar and then find “Instances”. From there, click on the running instance you would like to create a snapshot of.
Creating A Snapshot
Then, click on “Snapshots” on the menu and “Create Snapshot”. A window will pop up.
Creating A Snapshot 2
Finally, pick a name for the Snapshot and then click “create”.
Creating A Snapshot 3
OCS will then queue snapshot job to be completed.

Using the CLI

Note: Make sure you have already installed the python openstack client and have an existing running instance.

  1. Shut down the source VM before you take the snapshot to ensure that all data is flushed to disk. If necessary, list the instances to view the instance name.
$ openstack server list
+--------------------------------------+------------------+--------+-------------------------+----------+---------+
| ID                                   | Name             | Status | Networks                | Image    | Flavor  |
+--------------------------------------+------------------+--------+-------------------------+----------+---------+
| b4a783c0-bf1f-47a8-beeb-b04bfb050b54 | smol_test_server | ACTIVE | Public01=127.0.0.1      | Centos 7 | xe.tiny |
+--------------------------------------+------------------+--------+-------------------------+----------+---------+
  1. Use the openstack server stop command to shut down the instance.
    Put your instance id or name in place of “yourInstanceIDHere”.
$ openstack server stop yourInstanceIDHere
  1. Refreshing the server list shows that the instance status has changed to “SHUTOFF”.
$ openstack server list
+--------------------------------------+------------------+---------+-------------------------+----------+---------+
| ID                                   | Name             | Status  | Networks                | Image    | Flavor  |
+--------------------------------------+------------------+---------+-------------------------+----------+---------+
| b4a783c0-bf1f-47a8-beeb-b04bfb050b54 | smol_test_server | SHUTOFF | Public01=127.0.0.1      | Centos 7 | xe.tiny |
+--------------------------------------+------------------+---------+-------------------------+----------+---------+
  1. Use the openstack server image create command to take a snapshot.
    Put your instance id or name in place of “yourInstanceID”.
    Put your desired name for the snapshot in place of “yourSnapshotName”.
$ openstack server image create --name yourSnapshotName yourInstanceID

If snapshot operations routinely fail because the user token times out while uploading a large disk image, consider configuring nova to use Service User Tokens.

  1. Use the openstack image list command to check the status until the status is ACTIVE:
$ openstack image list
+--------------------------------------+---------------------------+--------+
| ID                                   | Name                      | Status |
+--------------------------------------+---------------------------+--------+
| b4a783c0-bf1f-47a8-beeb-b04bfb050b54 | smol_test_server          | active |
+--------------------------------------+---------------------------+--------+

Download the snapshot as an image

  1. Get the image ID:
$ openstack image list
+--------------------------------------+---------------------------+--------+
| ID                                   | Name                      | Status |
+--------------------------------------+---------------------------+--------+
| b4a783c0-bf1f-47a8-beeb-b04bfb050b54 | smol_test_server          | active |
+--------------------------------------+---------------------------+--------+
  1. Download the snapshot by using the image ID that was returned in the previous step:
$ openstack image save --file snapshot.raw b4a783c0-bf1f-47a8-beeb-b04bfb050b54

Note: The openstack image save command requires the image ID and cannot use the image name. Check there is sufficient space on the destination file system for the image file.

  1. Make the image available to the new environment, either through HTTP or direct upload to a machine (scp).

Import the snapshot to the new environment

In the new project or cloud environment, import the snapshot:
Replace ‘yourInstanceSnapshot’ with the name of the snapshot you saved.

$ openstack image create --container-format bare --disk-format qcow2 \
  --file snapshot.raw yourInstanceSnapshot

Boot a new instance from the snapshot

In the new project or cloud environment, use the snapshot to create the new instance:
Replace ‘yourNewInstance’ with your desired instance name.
Replace ‘yourFlavorHere’ with your desired flavor.

$ openstack server create --flavor yourFlavorHere --image yourInstanceSnapshot yourNewInstance

Use “openstack flavor list” to see available flavors.

Proudly Australian 🦘