Transfer business data from a system disk directory to a data disk to reduce system disk load on a Linux ECS instance.
Data migration may disrupt your business. Consider resizing the system disk instead. See Step 1: Resize a disk to extend the disk capacity.
Prerequisites
-
The system disk usage is below 100%.
ImportantLog on to the instance and run df -h to check root partition usage. If usage reaches 100%, see Resolve "no space left" issues on Linux.
-
The target data disk meets the following requirements:
-
The data disk is in the In Use (In_use) state.
-
The data disk is initialized with no file system mounted. See Initialize a data disk on a Linux instance.
-
The following example transfers data from the /userdata directory to the /dev/vdb1 partition on Alibaba Cloud Linux 3.2104. Replace /userdata and /dev/vdb1 with your actual directory and partition names.
Workflow
Procedure
Step 1: Back up the system disk
Create a snapshot of the system disk to prevent data loss. See Create snapshot manually.
Snapshots incur fees. See Snapshot billing.
Step 2: Copy data to the data disk
-
Create the /temporary directory and mount the data disk partition. Replace /dev/vdb1 with your actual partition name.
sudo mkdir /temporary sudo mount /dev/vdb1 /temporary -
Copy data from /userdata to the mounted /temporary directory. Replace /userdata with your actual directory name.
sudo cp -rv /userdata/. /temporaryAlternatively, use rsync to copy files with progress display.
sudo yum install -y rsync rsync --progress /userdata/* /temporary
Step 3: Mount the data disk partition to the data directory
-
Unmount the /temporary directory.
sudo umount /temporary -
Rename /userdata to /userdata_bak as a short-term backup.
sudo mv /userdata /userdata_bakWarningRenaming the data directory may cause business errors and short-term data loss. Evaluate the risks and perform this operation during off-peak hours.
-
Rename /temporary to /userdata. Replace /userdata with your actual directory name.
sudo mv /temporary /userdata -
Mount /dev/vdb1 to /userdata. Replace with your actual partition and directory names.
sudo mount /dev/vdb1 /userdata -
Run the
df -Thcommand to check if the data disk partition is mounted to the target directory. The following output shows that /dev/vdb1 is mounted to /userdata.[ecs-xxx ~]$ df -Th Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 867M 0 867M 0% /dev tmpfs tmpfs 879M 0 879M 0% /dev/shm tmpfs tmpfs 879M 436K 878M 1% /run tmpfs tmpfs 879M 0 879M 0% /sys/fs/cgroup /dev/vda1 ext4 40G 2.8G 35G 8% / /dev/vdb1 ext4 40G 3.8G 34G 11% /userdata
Step 4: Verify business system operation
-
Restart the business system and verify that it runs as expected.
-
After confirming the business system runs normally, delete the /userdata_bak directory.