8.8. Creating an Instance Snapshot
You can create a snapshot of a running instance. You may wish to do this for backup purposes or for creating a base image to create other instances from, after applying some customization.
As an example, you may want every instance to have a user called
projectuser. Create that user in the virtual machine and then create a snapshot. That snapshot can be used as the base for new instances.
Start by applying some sort of customization to the virtual machine. These commands could be used to create a user and set its password:
vm$useradd projectuservm$passwd projectuser
Now create a snapshot of that running instance:
$nova image-create <instanceid> "snapshot 1"
The snapshot is complete when its status in
nova image-list changes from SAVING to ACTIVE.
$nova image-list+--------------------------------------+------------+--------+--------+ | ID | Name | Status | Server | +--------------------------------------+------------+--------+--------+ | 17a34b8e-c573-48d6-920c-b4b450172b41 | RHEL 6.2 | ACTIVE | | | 84420f08-1e4b-499a-837a-5c6c1b9903d0 | snapshot 1 | SAVING | ...... | +--------------------------------------+------------+--------+--------+$nova image-list+--------------------------------------+------------+--------+--------+ | ID | Name | Status | Server | +--------------------------------------+------------+--------+--------+ | 17a34b8e-c573-48d6-920c-b4b450172b41 | RHEL 6.2 | ACTIVE | | | 84420f08-1e4b-499a-837a-5c6c1b9903d0 | snapshot 1 | ACTIVE | ...... | +--------------------------------------+------------+--------+--------+
Once the snapshot's status is active, you can start up a new instance using this image:
$nova boot --image 84420f08-1e4b-499a-837a-5c6c1b9903d0 --flavor 2 --key_name oskey \snapshot-instance+------------------------+--------------------------------------+ | Property | Value | +------------------------+--------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-STS:power_state | 0 | | OS-EXT-STS:task_state | scheduling | | OS-EXT-STS:vm_state | building | | accessIPv4 | | | accessIPv6 | | | adminPass | QASX3r8jKzVd | | config_drive | | | created | 2012-05-18T13:49:07Z | | flavor | m1.small | | hostId | | | id | ac9e6a9f-58c3-47c3-9b4c-485aa421b8a8 | | image | snapshot 1 | | key_name | oskey | | metadata | {} | | name | snapshot-instance | | progress | 0 | | status | BUILD | | tenant_id | 05816b0106994f95a83b913d4ff995eb | | updated | 2012-05-18T13:49:08Z | | user_id | 1d59c0bfef9b4ea9ab63e2a058e68ae0 | +------------------------+--------------------------------------+$nova list+--------------------------------------+-------------------+--------+------------------+ | ID | Name | Status | Networks | +--------------------------------------+-------------------+--------+------------------+ | 0e4011a4-3128-4674-ab16-dd1b7ecc126e | rhel | ACTIVE | demonet=10.0.0.2 | | ac9e6a9f-58c3-47c3-9b4c-485aa421b8a8 | snapshot-instance | BUILD | demonet=10.0.0.4 | | b8d5c952-f2fc-4556-83f2-57c79378d867 | rhel2 | ACTIVE | demonet=10.0.0.3 | +--------------------------------------+-------------------+--------+------------------+
Finally, test that the new instance contains the expected customizations made earlier in this exercise. If you followed the example, the instance should have a user named
projectuser.
$ssh -i oskey.priv root@10.0.0.4
vm$su projectuser