Migrate Linux server data to a Selectel cloud server using dd
You can migrate a Linux server to a Selectel cloud server using the dd utility.
The dd utility copies the entire disk contents along with the operating system, settings, and data. During copying, disks and network bandwidth will be fully utilized. After the migration, you only need to update the parameters that depend on the hardware and network: partition IDs, network settings, and IP addresses in the service configurations.
Migrate data in one of two ways:
- with stopping the source server — both servers boot into Rescue mode, data does not change during copying, and the copy is completely consistent. The work can be carried out at night or on weekends;
- without stopping the source server — the source server continues to run, and databases and actively changing files are migrated separately after copying the disk.
If intensive disk writes occur on the source server, we recommend migrating Linux server data to a Selectel cloud server using rsync.
To migrate data:
- Create a cloud server.
- Prepare the Linux server.
- Migrate data using the dd utility.
- Check and switch services.
1. Create a cloud server
Use the Create a cloud server instructions. The disk size of the new server must not be smaller than the original one.
2. Prepare the Linux server
-
Estimate the copy time. To do this, divide the server disk size by the link speed between the servers. You can measure link speed using the
iperf3utility. For example, a 500 GB disk at 100 MB/s takes about an hour and a half to copy. -
Back up data and databases on the source server.
-
Save the list of running services and open ports on the source server to compare the list with the new server:
systemctl list-units --type=service --state=running > <service_file_name>.txtss -tulpn > <ports_file_name>.txtSpecify:
<service_file_name>— the name of the file to save the service list. For example,services-before;<ports_file_name>— the name of the file to save the port list. For example,ports-before.
-
24 hours before switching, reduce the TTL of domain DNS records to 300 seconds.
3. Migrate data using the dd utility
With stopping the source server
Without stopping the source server
-
Check the disk names on both servers:
lsblk -o NAME,SIZE,TYPE,MOUNTPOINTThe response will display information about the disks. For example:
NAME SIZE TYPE MOUNTPOINTsda 8G disk├─sda1 8G part /└─sda14 8M partsr0 488K romWhere
sdais the disk name. -
Start copying from the source server:
dd if=<source_disk> bs=32M status=progress | ssh root@<new_ip_address> "dd of=<target_disk> bs=32M"Specify:
<source_disk>— name of the disk on the source server that you checked in step 3. For example,/dev/sda;<new_ip_address>— public IP address of the new server;<target_disk>— name of the disk on the new server that you checked in step 3. For example,/dev/sdb.
If the entire bandwidth should not be occupied by copying, limit the rate with the
pvutility. For example:dd if=/dev/sda bs=32M status=progress | pv -qL 90M | ssh root@203.0.113.16 "dd of=/dev/sdb bs=32M"Where
90Mis a data transfer rate limit of up to 90 MB/s. -
If copying is interrupted, resume data transfer:
5.1. Check the number of completely transferred blocks of size
bsin theddutility output after the copy was interrupted. For example:^C244234+0 records in244233+0 records out8195099590656 bytes (8.2 TB, 7.5 TiB) copied, 271390 s, 30.2 MB/sWhere
244233is the number of completely transferred blocks of sizebs.If the disk was copied to an image file and the output of the
ddutility was not preserved, divide the file size in bytes by the block size (32 MB = 33,554,432 bytes) and take the integer part.5.2. Continue data transfer:
dd bs=32M skip=<records_out> if=<source_disk> status=progress | ssh root@<new_ip_address> "dd bs=32M seek=<records_out> of=<target_disk>"Specify:
<records_out>— number of completely transferred blocks that you obtained in step 5.1;<source_disk>— name of the disk on the source server;<new_ip_address>— public IP address of the new server;<target_disk>— name of the disk on the new server.
-
Exit Rescue mode on the new server.
-
If the OS on the new server does not boot, check the UUIDs and partition names:
7.1. Boot the new server into Rescue mode.
7.2. Check partitions and
fstab:blkidmount <root_partition> /mntcat /mnt/etc/fstabSpecify
<root_partition>— the name of the root partition. For example,/dev/sda1.7.3. Fix UUIDs or partition names in the
/mnt/etc/fstabfile. 7.4. Optional: to restore the bootloader, reinstall it:for d in dev proc sys; do mount --bind /$d /mnt/$d; donechroot /mntgrub-install <target_disk>update-grub # on RHEL-based distributions: grub2-mkconfig -o /boot/grub2/grub.cfgexitSpecify
<target_disk>— the disk name on the new server. For example,/dev/sda. -
Update network settings on the new server: IP address, subnet mask, gateway.
-
Find configuration files that contain the public IP address of the source server:
grep -rl "<old_ip_address>" /etcSpecify
<old_ip_address>— the public IP address of the source server. -
In the found files, replace the public IP address of the source server with the new one.
-
Exit Rescue mode on the new server.
-
Compare the list of running services and open ports on the new server with the list you saved in step 2.
-
Optional: to keep data up to date during testing, configure database replication from the source server.
4. Check and switch services
During final data synchronization and switching between servers, service downtime occurs. We recommend synchronizing data and switching services during off-peak hours.
-
Check service operation on the new server before switching DNS. To do this, add an entry with the new IP to the
hostsfile on your local computer. This will allow you to connect to services on the new server while user requests continue to be routed to the source server:<new_ip_address> <domain> <subdomain>Specify:
<new_ip_address>— the public IP address of the new server;<domain>— your domain name. For example,example.com;<subdomain>— your subdomain name. For example,www.example.com.
In Linux and macOS, the
hostsfile is located at/etc/hosts, and in Windows — atC:\Windows\System32\drivers\etc\hosts. -
If services access their own domain, add the same entry to the
hostsfile on the new server. -
If you find errors in service operation, fix them and repeat step 1.
-
Test services for 3 business days and address any issues if necessary.
-
Perform the final data and database synchronization.
-
Switch DNS records to the new IP.
-
Monitor service operation for another 3 business days.
-
If everything is working correctly, the source server can be shut down.