Sometimes you need to move the data that is stored on a block volume between Oracle Cloud Infrastructure regions. In this case, you can use cross-region block volume backup copy.
Unfortunately, you can’t use this method with boot volumes. If you need to transfer your instance or image between regions, use one of the methods outlined in this post, depending on the configuration of your instance.
In this post, I assume that you're familiar with the Oracle Cloud Infrastructure CLI and have it set up. If not, use our quick start guide to help you do that.
By default, every Linux instance launched in Oracle Cloud Infrastructure is created with a 50-GB boot volume. This value can be altered during instance creation, but that might lead to some limitations, which I’ll explain in the next section.
This scenario assumes that the size of your boot volume is 50 GB or less.
Create a custom image of an instance. The instance reboots during the process, so ensure that it’s not a production workload.
oci compute image create --display-name <display_name> --instance-id <instance_ID> --compartment-id <compartment_ID> --wait-for-state AVAILABLE
Export the custom image to an Object Storage bucket.
oci compute image export to-object --image-id <custom_image_ID> --namespace <tenancy_namespace> --bucket-name <object_storage_bucket> --name <object_name>
Wait for the process to complete. You can monitor the life cycle status using the following command:
oci compute image get --image-id <image_ID>
When the life cycle state changes from EXPORTING to AVAILABLE, the process is complete.
Copy the object to the new region. Ensure that you have relevant permissions and policies applied as outlined in https://docs.cloud.oracle.com/iaas/Content/Object/Tasks/copyingobjects.htm).
Cross-region copy lets you asynchronously copy objects to other buckets in the same region, to buckets in other regions, or to buckets in other tenancies within the same region or in other regions. When copying the objects, you can keep the same name or modify the object name. The object copied to the destination bucket is considered a new object with unique ETag values and MD5 hashes.
Before you start the operation, ensure that destination bucket exists or create one by using the oci os bucket create ... command); otherwise, the operation fails.
oci os object copy --bucket-name <bucket_name> --source-object-name <object_name> --destination-region <destination_region_name> --destination-bucket <destination_bucket_name>
Create a pre-authenticated request for the object.
oci --region <new_region_name> os preauth-request create --bucket-name <bucket_name> --name <object_name> --access-type ObjectRead --time-expires <date_time>
The URL is objectstorage.<region>.oraclecloud.com/<preauth_path>.
Import the custom image in to the region by using the Object Storage URL.
oci --region <region_name> compute image import from-object-uri --uri <URI> --compartment-id <compartment> --display-name <display_name> --launch-mode NATIVE --source-image-type QCOW2
After the image is imported, you should see it in the custom images list and be able to launch an instance by using the Console or CLI.
If the image is created from an instance with a boot volume larger than 50 GB, the process might fail because of a limitation of the pre-authenticated request object size. As a workaround, we clone the boot volume, use a disposable instance to create an image, and then upload and import the image. You can also use this method with a regular-sized image to avoid restarting the original instance.
Before you start, ensure that you have required permissions in the IAM policies, that you have an API key that you can apply on the remote machine, and that the Oracle Cloud Infrastructure CLI is installed locally.
Create a boot volume clone. This process is almost instantaneous.
oci bv boot-volume create --source-boot-volume-id <boot_volume_ID> --display-name <new_boot_volume_display_name>
Create a block volume big enough to store the temporary image in the same availability domain.
oci bv volume create --availability-domain <availability_domain> --size-in-gbs 1024
Launch a new Oracle Linux 7.5 instance in the same availability domain. This is your disposable instance.
Attach the block volume and the boot volume.
oci compute volume-attachment attach --instance-id <instance_ID> --volume-id <block_volume_ID> --type ISCSI
oci compute volume-attachment attach --instance-id <instance_ID> --volume-id <cloned_boot_volume_ID> --type ISCSI
Use SSH to connect to the instance.
Install the required packages:
sudo yum -y install qemu-img pv python-pip sudo pip install oci-cli
Configure the CLI on the remote system, following the procedure at https://docs.cloud.oracle.com/iaas/Content/API/SDKDocs/cliinstall.htm.
Configure disks on the temporary system and format the partition.
sudo oci-iscsi-config sudo parted -s -a optimal /dev/sdb mklabel gpt sudo parted -s -a optimal /dev/sdb mkpart primary 0% 100% sudo mkfs.xfs /dev/sdb1 sudo mount /dev/sdb1 /media
Create an image from the boot volume. This process might take a long time, even hours depending on the disk size.
sudo qemu-img convert -p -S1M /dev/sdc -O qcow2 /media/image.qcow2
The result is an image.qcow2 file that contains a QCOW2 formatted disk image of a boot volume that you can upload to Object Storage and import into your new region.
Upload the file to the Object Storage bucket.
oci --region <region_name> os object put -ns <namespace> -bn <bucket_name> --file /media/image.qcow2 --name image.qcow2
Import the image from the bucket.
oci --region <region_name> compute image import from-object --namespace <ns> --bucket-name <bucket_name> --compartment-id <compartment> --display-name <display_name> --launch-mode NATIVE --source-image-type QCOW2
After the image is imported, you should see it in the custom images list and be able to launch an instance by using the Console or the CLI.
Now you can terminate the temporary instance and delete the block volumes that you created during the process.
I hope this helps!