Working with volume snapshots

Cinder volume snapshots provide a way to nondisruptively copy a volume; allowing for in-situ volume backups to be taken. It also enables more advanced backup features and provides the ability to boot an instance from a given snapshot or from a point in time.

In this section, we will show you how to create a snapshot, mount a volume based off a snapshot, refresh a snapshot, and delete a given snapshot.

Getting ready

To work with Cinder volume snapshots, you will need the following:

  • The openstack command-line client
  • An openrc file with appropriate credentials for the environment
  • The name or ID of the volume to delete

How to do it…

To create a snapshot, the volume must be first detached from an instance:

  1. First, list your current volumes:
    How to do it…

    Tip

    If the volume you wish to snapshot has a status of in-use, you will need to detach it using the instructions in the Detaching volumes from an instance recipe earlier in this chapter.

  2. As our volume is the correct state of available, we will proceed to create a snapshot of the volume using the openstack volume snapshot create command:
    openstack volume snapshot create
        --volume cookbook.volume
        cookbook.snapshot
    

    This will produce an output like the following, showing a state of creating:

    How to do it…
  3. Once the snapshot is complete, you can reattach the original volume using the Attaching volumes to an instance recipe, in this chapter and continue operations.
  4. If using snapshots as part of an ongoing test / validation process, or part of a backup scheme, you may want to update the snapshot with fresh data. To do this, we use the cinder snapshot-reset-state, which produces no output if successful:
    openstack volume snapshot list -c ID -c Name -c Status -f table
    cinder snapshot-reset-state cookbook.snapshot
    

    Tip

    Note the use of the cinder command-line tool, as opposed to openstack.

  5. You are unable to use a snapshot directly; to use a snapshot as a volume to attach to an instance, you first need to create a new volume based off this snapshot. To do this, carry out the following:
    openstack volume create
        --snapshot cookbook.snapshot
        newcookbook.volume
    

    This will produce the following output. Note snapshot_id that was used and the fact that we didn't specify a size:

    How to do it…
  6. We can confirm that our new cookbook volume, based off the snapshot, is now available by viewing the volume list again:
    openstack volume list –c Name –c ID –c Status –f table
    

    This produces a list of our volumes and their state:

    How to do it…
  7. Finally, you will want to delete snapshots at some point. To do this, use the openstack volume snapshot delete command as follows:
    openstack volume snapshot delete cookbook.snapshot
    

    Confirm with openstack volume snapshot list the list the remaining snapshots available.

How it works…

Cinder volume snapshots provide a flexible way to clone volumes for snapshot type backups, attaching to other instances, and more. The cinder snapshot commands we used here, specifically openstack volume snapshot create, openstack volume snapshot list, cinder snapshot-reset-state, and openstack volume snapshot delete, instruct cinder to work with the storage driver to perform snapshot specific actions—create, list, update, and delete, respectively. The specific implementation of snapshot depends on the underlying driver.

Also note that you cannot use a snapshot directly with an instance. You must first create a new volume based on the snapshot of your choice. This has the following syntax:

openstack volume create
    --snapshot snapshot_name_or_id
    new_volume_name
..................Content has been hidden....................

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