Replacing the operating system by replacing the system disk also replaces the system disk and its image. The original system disk is released, and all its data is deleted. Therefore, you cannot directly roll back using a snapshot created from the old system disk. This topic explains how to restore data from a snapshot of the original system disk after replacing the system disk.
Prerequisites
-
Create a snapshot from the old system disk and obtain the snapshot ID. For more information, see Create a single snapshot manually.
NoteUsing snapshots incurs charges. For more information, see Snapshot billing.
-
Obtain the instance ID of the ECS instance to which you will attach the disk.
-
You have changed the operating system. For more information, see Change the system disk (change the operating system).
Procedure
Step 1: Create a disk from the snapshot
Go to ECS console - Snapshots.
In the upper-left corner of the page, select a region and resource group.
-
On the Disk Snapshot tab, find the snapshot 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 Detailed explanation of configuration parameters.
-
Review the configuration and cost, then complete the purchase as prompted.
Step 2: Log on to the ECS instance and restore data
This example uses Alibaba Cloud Linux 3.2104 as the original operating system. Partition layouts may differ across operating systems. Adjust accordingly based on your actual setup.
-
Connect to the ECS instance remotely.
For more information, see Log on to a Linux instance using Workbench.
-
Run the following command to get the device name of the data disk.
sudo fdisk -lu[ecs-xxx ~]$ sudo fdisk -lu Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors Units = sectors of 1 × 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000edc45 Device Boot Start End Blocks Id System /dev/vda1 * 2048 83886046 41941999+ 83 Linux WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion. Disk /dev/vdb: 42.9 GB, 42949672960 bytes, 83886080 sectors Units = sectors of 1 × 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: gpt Disk identifier: 6CA42D45-D495-417A-99B7-DFFEF4B29C93 # Start End Size Type Name 1 2048 6143 2M BIOS boot 2 6144 415743 200M EFI System 3 415744 83886046 39.8G Linux filesysteThis example uses Alibaba Cloud Linux 3.2104, which has three partitions:
The first partition, /dev/vdb1, stores the boot loader and ensures the system can start normally from the disk. You do not need to focus on it.
The second partition, /dev/vdb2, stores the EFI boot program and ensures the system can start using EFI firmware. You do not need to focus on it.
The third partition, /dev/vdb3, stores operating system files and data—the data you need to restore from the system disk.
Partition layouts vary by operating system. Adjust based on your actual setup.
-
Run the following command to create a mount directory. This example uses /temporary. Modify it as needed.
sudo mkdir -p /temporary -
Run the following command to mount the file system. Replace /dev/vdb3 and /temporary with your actual values.
sudo mount /dev/vdb3 /temporary -
Run the following command to copy files. This example copies data from /mnt on the old system disk to /mnt on the new system disk.
sudo cp -v /temporary/mnt/* /mntAlternatively, install the rsync tool for file copying with progress tracking.
sudo yum install -y rsync rsync --progress /temporary/mnt/* /mnt
Step 3: Verify that your services run normally
-
Verify that your services are restored. After completing the operation, restart related services and check whether they run normally.
-
After you confirm that your business runs as expected, detach the data disk created from the snapshot of the original system disk and release the data disk. For more information, see Detach Data Disk and Release Disk.
> Create {category}