When you replace the operating system of an Elastic Compute Service (ECS) instance, its system disk and image are also replaced. The original system disk is released and all its data is deleted. Therefore, you cannot use a snapshot of the original disk to roll back the new system disk. This guide explains how to restore data from the original snapshot after the replacement.
Prerequisites
You have created a snapshot of the original system disk and have its snapshot ID. For more information, see Create a snapshot.
NoteSnapshots incur charges. For more information, see Snapshot billing.
You have the ID of the target ECS instance.
You have replaced the operating system. For more information, see Replace a system disk (change the operating system).
Procedure
Step 1: Create a disk from a snapshot
Go to ECS console - Snapshots.
In the top navigation bar, select the region and resource group of the resource that you want to manage.
On the Disk Snapshots tab, find the snapshot that you want to use. In the Actions column, click .
Select Attach to ECS Instance and enter the ECS instance ID. For more information about other parameters, see Parameter details.
Confirm the configuration and fees, and then complete the purchase as prompted.
Step 2: Log on to the ECS instance and restore data
This example uses an instance whose original operating system was Alibaba Cloud Linux 3.2104. Partitions may differ on other operating systems. Adjust the steps accordingly.
Connect to the ECS instance.
For more information, see Log on to a Linux instance using Workbench.
Run the following command to list the partitions on the attached disk.
sudo fdisk -lu
In this example of an Alibaba Cloud Linux 3.2104 system, the disk has three partitions:
The first partition,
/dev/vdb1, stores the bootloader, which enables the system to boot from the Cloud Disk. No action is needed on this partition.The second partition,
/dev/vdb2, stores the EFI boot program, which enables the system to boot by using EFI firmware. No action is needed on this partition.The third partition,
/dev/vdb3, stores the operating system files and data. This partition contains the data you need to restore.Partitions vary by operating system. The partitions on your disk may be different.
Run the following command to create a new mount directory. This example uses /temporary. Replace it with your actual directory name.
sudo mkdir -p /temporaryRun the following command to mount the file system. Replace /dev/vdb3 with your data partition and /temporary with your mount directory.
sudo mount /dev/vdb3 /temporaryRun the following command to copy files. This example copies data from the /mnt directory on the old system disk to the /mnt directory on the new system disk.
sudo cp -v /temporary/mnt/* /mntAlternatively, you can install the rsync tool to copy files and view the progress.
sudo yum install -y rsync rsync --progress /temporary/mnt/* /mnt
Step 3: Verify that services are running properly
After the data is copied, restart the relevant services and check that they are running correctly.
After confirming your services are running correctly, detach and release the data disk created from the snapshot. For more information, see Detach data disk and Release a disk.
> Create Disk