OpenStack: Create Instance Snapshot to backup or migrate Instance

openstack: create instance snapshot to migrate or restore instance
OpenStack Snapshots can be utilized to backup Instance before some critical changes are made on Instance OS or to migrate Instance to the new OpenStack Cloud.
In this tutorial we will create snapshot from existing Instance to launch it in different Cloud, but you can also create snapshot just to backup the Instance and restore it’s state later in the same Cloud, if needed.

Steps:

1. Create the Instance Snapshot

Source Project Tenant Keystone file:

[root@oldcontroller ~]# source /root/keystonerc_tuxfixer
[root@oldcontroller ~(keystone_tuxfixer)]# 

Locate the source Instance and power it off:

[root@oldcontroller ~(keystone_tuxfixer)]# nova list
+--------------------------------------+------------------+--------+------------+-------------+-----------------------+
| ID                                   | Name             | Status | Task State | Power State | Networks              |
+--------------------------------------+------------------+--------+------------+-------------+-----------------------+
| 52f61d29-fae8-40f7-974d-f9660e39fcf7 | CentOS7_instance | ACTIVE | -          | Running     | priv_net=192.168.20.5 |
+--------------------------------------+------------------+--------+------------+-------------+-----------------------+

Stop the Instance:

[root@oldcontroller ~(keystone_tuxfixer)]# nova stop CentOS7_instance
Request to stop server CentOS7_instance has been accepted.

Verify, that the Instance is powered off:

[root@oldcontroller ~(keystone_tuxfixer)]# nova list
+--------------------------------------+------------------+---------+------------+-------------+-----------------------+
| ID                                   | Name             | Status  | Task State | Power State | Networks              |
+--------------------------------------+------------------+---------+------------+-------------+-----------------------+
| 52f61d29-fae8-40f7-974d-f9660e39fcf7 | CentOS7_instance | SHUTOFF | -          | Shutdown    | priv_net=192.168.20.5 |
+--------------------------------------+------------------+---------+------------+-------------+-----------------------+

Create Instance Snapshot (this will create Glance Image based on the Instance):

[root@oldcontroller ~(keystone_tuxfixer)]# nova image-create --poll CentOS7_instance CentOS7_instance_snapshot
Server snapshotting... 100% complete
Finished

Verify, if the Image was created succesfully (Snapshot Image status should be ACTIVE):

[root@oldcontroller ~(keystone_tuxfixer)]# nova image-list
+--------------------------------------+---------------------------+--------+--------------------------------------+
| ID                                   | Name                      | Status | Server                               |
+--------------------------------------+---------------------------+--------+--------------------------------------+
| 66a1da0e-5c0a-41b5-a8a4-f5714eaf600a | CentOS7_instance_snapshot | ACTIVE | 52f61d29-fae8-40f7-974d-f9660e39fcf7 |
| a6dd85fa-dbc0-429f-a2ce-1698a1d6b41b | centos7_gen_cl_img        | ACTIVE |                                      |
| f0e6da8f-4472-4444-8b26-b44f04b37146 | cirros                    | ACTIVE |                                      |
+--------------------------------------+---------------------------+--------+--------------------------------------+

Download the Snapshot Image using Snapshot’s ID:

[root@oldcontroller ~(keystone_tuxfixer)]# glance image-download --file /tmp/CentOS7_snapshot.qcow2 66a1da0e-5c0a-41b5-a8a4-f5714eaf600a

2. Transfer Snapshot to the new OpenStack Cloud

Transfer snapshot qcow2 image file to the new OpenStack installation (for example from old Controller node to the new Controller node):

[root@oldcontroller ~(keystone_tuxfixer)]# scp /tmp/CentOS7_snapshot.qcow2 root@newcontroller:/tmp/CentOS7_snapshot.qcow2

On new Cloud Controller node source admin keystone file:

[root@newcontroller ~]# source /root/keystonerc_admin
[root@newcontroller ~(keystone_admin)]# 

On new Cloud Controller node import the snapshot file to the public images:

[root@newcontroller ~(keystone_admin)]# glance --os-image-api-version 1 image-create --container-format bare --disk-format qcow2 --is-public True --file /tmp/CentOS7_snapshot.qcow2 --name CentOS7_snapshot_image

Verify newly created image on the new Cloud Controller node:

[root@newcontroller ~(keystone_admin)]# glance image-list
+--------------------------------------+------------------------+
| ID                                   | Name                   |
+--------------------------------------+------------------------+
| f7b3d360-2862-430e-9423-c8ed563c4e77 | CentOS7_snapshot_image |
+--------------------------------------+------------------------+

Boot new Instance from new snapshot image (source your tenant user keystone file):

[root@newcontroller ~]# source /root/keystonerc_tuxfixer
[root@newcontroller ~(keystone_tuxfixer)]# nova boot --flavor m1.small --nic net-id=beac6101-91d4-4917-b5ee-c7116f4a76c5 --image CentOS7_snapshot_image CentOS7_new_instance

Note: downloaded Instance snapshot qcow2 image file can also be imported to KVM environment and launched as ordinary Virtual Machine, since OpenStack hypervisors are based on KVM, so there is a bilateral compatibility between OpenStack and KVM environment.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.