Openstack - Cinder Backup/Restore

## What's this?

* 1. Cinder volume の Backup
* 2-1. 新しい Cinder volume を作成し、そこへ Backup から Restore
* 2-2. Backup から 元の Cinder volume へ Restore


## Initial state

#### Cinder list

    # cinder list
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
    |                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable | Attached to |
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
    | 5175d6be-735c-411e-be21-85015c332d99 | available | admin_vol01  |  1   |     None    |  false   |             |
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+

    # cinder show admin_vol01
    +--------------------------------+--------------------------------------+
    |            Property            |                Value                 |
    +--------------------------------+--------------------------------------+
    |          attachments           |                  []                  |
    |       availability_zone        |                 nova                 |
    |            bootable            |                false                 |
    |           created_at           |      2015-02-17T03:32:50.000000      |
    |      display_description       |                                      |
    |          display_name          |             admin_vol01              |
    |           encrypted            |                False                 |
    |               id               | 5175d6be-735c-411e-be21-85015c332d99 |
    |            metadata            |                  {}                  |
    |     os-vol-host-attr:host      |                  node-17             |
    | os-vol-mig-status-attr:migstat |                 None                 |
    | os-vol-mig-status-attr:name_id |                 None                 |
    |  os-vol-tenant-attr:tenant_id  |   a8085d1871f847bdb906ef4a28d1bd48   |
    |              size              |                  1                   |
    |          snapshot_id           |                 None                 |
    |          source_volid          |                 None                 |
    |             status             |              available               |
    |          volume_type           |                 None                 |
    +--------------------------------+--------------------------------------+

#### Cinder backup list

    # cinder backup-list
    +----+-----------+--------+------+------+--------------+-----------+
    | ID | Volume ID | Status | Name | Size | Object Count | Container |
    +----+-----------+--------+------+------+--------------+-----------+
    +----+-----------+--------+------+------+--------------+-----------+


## Backup Cinder Volume

#### Backup

    # cinder backup-create --display-name admin_vol01_backup admin_vol01
    +-----------+--------------------------------------+
    |  Property |                Value                 |
    +-----------+--------------------------------------+
    |     id    | 71bd2ee4-a657-4f79-a842-bb7ed80b7774 |
    |    name   |          admin_vol01_backup          |
    | volume_id | 5175d6be-735c-411e-be21-85015c332d99 |
    +-----------+--------------------------------------+


#### Check the backup

    # cinder backup-list
    +--------------------------------------+--------------------------------------+-----------+--------------------+------+--------------+-----------+
    |                  ID                  |              Volume ID               |   Status  |        Name        | Size | Object Count | Container |
    +--------------------------------------+--------------------------------------+-----------+--------------------+------+--------------+-----------+
    | 71bd2ee4-a657-4f79-a842-bb7ed80b7774 | 5175d6be-735c-411e-be21-85015c332d99 | available | admin_vol01_backup |  1   |     None     |  backups  |
    +--------------------------------------+--------------------------------------+-----------+--------------------+------+--------------+-----------+

    # cinder backup-show 71bd2ee4-a657-4f79-a842-bb7ed80b7774
    +-------------------+--------------------------------------+
    |      Property     |                Value                 |
    +-------------------+--------------------------------------+
    | availability_zone |                 nova                 |
    |     container     |               backups                |
    |     created_at    |      2015-02-17T05:13:05.000000      |
    |    description    |                 None                 |
    |    fail_reason    |                 None                 |
    |         id        | 71bd2ee4-a657-4f79-a842-bb7ed80b7774 |
    |        name       |          admin_vol01_backup          |
    |    object_count   |                 None                 |
    |        size       |                  1                   |
    |       status      |              available               |
    |     volume_id     | 5175d6be-735c-411e-be21-85015c332d99 |
    +-------------------+--------------------------------------+




## Create new Cinder volume and Restore from the backup to it

#### Initial State

    # cinder list
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
    |                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable | Attached to |
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
    | 5175d6be-735c-411e-be21-85015c332d99 | available | admin_vol01  |  1   |     None    |  false   |             |
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+

    # cinder backup-list
    +--------------------------------------+--------------------------------------+-----------+--------------------+------+--------------+-----------+
    |                  ID                  |              Volume ID               |   Status  |        Name        | Size | Object Count | Container |
    +--------------------------------------+--------------------------------------+-----------+--------------------+------+--------------+-----------+
    | 71bd2ee4-a657-4f79-a842-bb7ed80b7774 | 5175d6be-735c-411e-be21-85015c332d99 | available | admin_vol01_backup |  1   |     None     |  backups  |
    +--------------------------------------+--------------------------------------+-----------+--------------------+------+--------------+-----------+

#### Create new Cinder volume

    # cinder create --display-name admin_vol11 --availability-zone nova 1
    +---------------------+--------------------------------------+
    |       Property      |                Value                 |
    +---------------------+--------------------------------------+
    |     attachments     |                  []                  |
    |  availability_zone  |                 nova                 |
    |       bootable      |                false                 |
    |      created_at     |      2015-02-17T05:44:20.376763      |
    | display_description |                 None                 |
    |     display_name    |             admin_vol11              |
    |      encrypted      |                False                 |
    |          id         | 18390e57-1a5b-4f60-95ad-43fc7b7bc3ea |
    |       metadata      |                  {}                  |
    |         size        |                  1                   |
    |     snapshot_id     |                 None                 |
    |     source_volid    |                 None                 |
    |        status       |               creating               |
    |     volume_type     |                 None                 |
    +---------------------+--------------------------------------+

    # cinder list
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
    |                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable | Attached to |
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
    | 18390e57-1a5b-4f60-95ad-43fc7b7bc3ea | available | admin_vol11  |  1   |     None    |  false   |             |
    | 5175d6be-735c-411e-be21-85015c332d99 | available | admin_vol01  |  1   |     None    |  false   |             |
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+

#### Restore from the backup to the new Cinder volume

* Start to restore

````
    # cinder backup-restore --volume-id 18390e57-1a5b-4f60-95ad-43fc7b7bc3ea 71bd2ee4-a657-4f79-a842-bb7ed80b7774
````

* Restoring

````
    # cinder list
    +--------------------------------------+------------------+--------------+------+-------------+----------+-------------+
    |                  ID                  |      Status      | Display Name | Size | Volume Type | Bootable | Attached to |
    +--------------------------------------+------------------+--------------+------+-------------+----------+-------------+
    | 18390e57-1a5b-4f60-95ad-43fc7b7bc3ea | restoring-backup | admin_vol01  |  1   |     None    |  false   |             |
    | 5175d6be-735c-411e-be21-85015c332d99 |     available    | admin_vol01  |  1   |     None    |  false   |             |
    +--------------------------------------+------------------+--------------+------+-------------+----------+-------------+
````

* Complete

````
    # cinder list
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
    |                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable | Attached to |
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
    | 18390e57-1a5b-4f60-95ad-43fc7b7bc3ea | available | admin_vol01  |  1   |     None    |  false   |             |
    | 5175d6be-735c-411e-be21-85015c332d99 | available | admin_vol01  |  1   |     None    |  false   |             |
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
````

#### Rename Cinder volume

    # cinder rename 18390e57-1a5b-4f60-95ad-43fc7b7bc3ea admin_vol11

    # cinder list
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
    |                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable | Attached to |
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
    | 18390e57-1a5b-4f60-95ad-43fc7b7bc3ea | available | admin_vol11  |  1   |     None    |  false   |             |
    | 5175d6be-735c-411e-be21-85015c332d99 | available | admin_vol01  |  1   |     None    |  false   |             |
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+



## Restore to original volume from the backup

#### Initial state

    # cinder list
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
    |                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable | Attached to |
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
    | 5175d6be-735c-411e-be21-85015c332d99 | available | admin_vol01  |  1   |     None    |  false   |             |
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+

    # cinder backup-list
    +--------------------------------------+--------------------------------------+-----------+--------------------+------+--------------+-----------+
    |                  ID                  |              Volume ID               |   Status  |        Name        | Size | Object Count | Container |
    +--------------------------------------+--------------------------------------+-----------+--------------------+------+--------------+-----------+
    | 71bd2ee4-a657-4f79-a842-bb7ed80b7774 | 5175d6be-735c-411e-be21-85015c332d99 | available | admin_vol01_backup |  1   |     None     |  backups  |
    +--------------------------------------+--------------------------------------+-----------+--------------------+------+--------------+-----------+


#### Restore from the backup to original Cinder volume

* Start to restore

````
    # cinder backup-restore --volume-id 5175d6be-735c-411e-be21-85015c332d99 71bd2ee4-a657-4f79-a842-bb7ed80b7774
````

* Restoring

````
    # cinder list
    +--------------------------------------+------------------+--------------+------+-------------+----------+-------------+
    |                  ID                  |      Status      | Display Name | Size | Volume Type | Bootable | Attached to |
    +--------------------------------------+------------------+--------------+------+-------------+----------+-------------+
    | 5175d6be-735c-411e-be21-85015c332d99 | restoring-backup | admin_vol01  |  1   |     None    |  false   |             |
    +--------------------------------------+------------------+--------------+------+-------------+----------+-------------+
````

* Complete

````
    # cinder list
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
    |                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable | Attached to |
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
    | 5175d6be-735c-411e-be21-85015c332d99 | available | admin_vol01  |  1   |     None    |  false   |             |
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
````



## Delete backup

#### Initial state

    # cinder backup-list
    +--------------------------------------+--------------------------------------+-----------+--------------------+------+--------------+-----------+
    |                  ID                  |              Volume ID               |   Status  |        Name        | Size | Object Count | Container |
    +--------------------------------------+--------------------------------------+-----------+--------------------+------+--------------+-----------+
    | 71bd2ee4-a657-4f79-a842-bb7ed80b7774 | 5175d6be-735c-411e-be21-85015c332d99 | available | admin_vol01_backup |  1   |     None     |  backups  |
    +--------------------------------------+--------------------------------------+-----------+--------------------+------+--------------+-----------+

#### Backup delete

    # cinder backup-delete 71bd2ee4-a657-4f79-a842-bb7ed80b7774

#### Check

    # cinder backup-list
    +----+-----------+--------+------+------+--------------+-----------+
    | ID | Volume ID | Status | Name | Size | Object Count | Container |
    +----+-----------+--------+------+------+--------------+-----------+
    +----+-----------+--------+------+------+--------------+-----------+


## Environment

* Openstack : Juno
* Ceph : Firefly

## Reference

[Cinder Backup/Restore][link-01]
[Cinder Backup/Restore between AZ][link-02]
[Cinder Backup/Restore between Region][link-03]
[Cinder Snapshot/Restore][link-04]

[link-01]:http://qiita.com/idzzy/items/ac163d0ce7cc9f036031
[link-02]:http://qiita.com/idzzy/items/caaa83de00abe78095e2
[link-03]:http://qiita.com/idzzy/items/fef77c7853eb6f6b1479
[link-04]:http://qiita.com/idzzy/items/cfb568e83e2645e3f32e