In this tutorial, we will show you how you can migrate an instance with ephemeral storage from one OpenStack provider to another OpenStack provider using snapshots. There are several ways of migrating instances and probably even some forms of doing this without any downtime, but this tutorial describes one of the most basic and easiest ways of doing it, using the OpenStack CLI tools.
Note: This tutorial was tested on Fuga Cloud Release 1 and Release 2 using the OpenStack CLI tools client version 3.17.0
TIP: We recommend using a small Linux cloud instance on the destination platform with the OpenStack CLI tools installed. This way you can make full use of the fast connections of the cloud platforms instead of downloading it to your local machine. This really speeds up the process.
Prerequisites:
- 2 active OpenStack accounts
- OpenStack CLI tools installed
- A cloud instance (that you would like to migrate)
- OpenStack credentials (open.rc files) from both OpenStack providers.
Step 1 Creating a Snapshot
Before creating a snapshot, shut down the instance to ensure no data is lost in transit. This to prevent data corruption.
You can view the instance name of your instance, using the following command:
openstack server list
Let’s shut down your instance, so that we can take a snapshot.
openstack server stop <instance_name>
Now we are going to create a snapshot of your instance using the following command:
openstack server image create <instance_name> --name <name_your_snapshot>
You can check the status of your snapshot
openstack image list
If the status is Active your snapshot is completed
STEP 2 Download your snapshot
We need the image ID of the snapshot that you’ve just made. We can look up the image ID with the following command.
openstack image list
After you have your image ID, it’s time to download your snapshot.
openstack image save --file snapshot.raw <your_image_id>
STEP 3 Uploading your snapshot
Make sure you are logged in to the correct OpenStack provider with your CLI tools
source <your_openrc.sh>
Upload your snapshot that you’ve just downloaded using the following command
openstack image create --container-format bare --disk-format qcow2 --file <image_file_path> <name_your_snapshot>
After the upload of your image snapshot is complete, you should see your snapshot in the list
openstack image list
Step 4 Boot your snapshot in the new cloud
The Snapshot has a minimum of required disk and RAM, so be sure to use a flavor that is the same or a bit bigger than the one you used before. Even though the snapshot image can be small in size, the image needs at least the allocated disk space and RAM of the original instance.
We will need to specify a couple of thing like our, flavor, network, security group, and key pair that we want to use. You can look it up using the following commands:
Check the list of available flavors using the following command:
openstack flavor list
Check your available networks
openstack network list
Your security groups
openstack security group list
Your key pairs
openstack keypair list
Now for launching your instance we can use the following command:
$ openstack server create --flavor <flavor> --network <network_name> --security-group <name_of_sc> --image <snapshot_name> --key-name <keypair_name> <name_your_instance>
You can check the status of your newly launched server
openstack server list
Conclusion
You now learned how you can download and upload instances using snapshots and launch the instance into a different OpenStack cloud provider by using the CLI tools.
TIP: After you have taken a snapshot of your instance you can turn the instance back on so that your application is still available. When your snapshot is running in the other cloud, you could then create a temporary database freeze, make a DB dump and restore it to the new instance. Change your DNS to the new IP and your good to go. This way the amount of downtime can be reduced by quite a bit.