Migrate your Linux Server using Rsync

Sometimes we need to move our server to another. Either it’s from on-prem to cloud, vm to vm, or to vps. While migrating we want minimum downtime as we can to the service or systems. Usually, i use rsync to migrate the data and even the OS, so we don’t need to reconfigure the server on the new DC or environment.

To perform that you need to;

  1. Make sure you set up the target VM/server the same as the source.
  2. Setup ssh keyless for root either from or to the target server. You can use rsync to push or pull the data from or to the servers.
  3. Perform rsync dryrun to test your migration. Also, make sure to exclude the specific configuration for the host to avoid conflict or error when you transfer the data. Example;
    rsync -aHAXPn –numeric-ids –exclude={“/boot/*”,”/etc/default/grub”,”/etc/fstab”,”/etc/lvm/*”,”/etc/udev/*”,”/etc/ssh/*”,”/etc/network/interfaces”,”/root/.ssh/*”,”/etc/hostname”,”/etc/hosts”,”/dev/*”,”/proc/*”,”/sys/*”,”/tmp/*”,”/run/*”,”/mnt/*”,”/media/*”,”/lost+found”} old.hostname:/ /
    -n : dry-run
    -another option : please reffer to manual 😛
    * You need to adjust the excluded files based on your OS distribution
    * In this case, we pull the data from the old server to new server.
  4. Perform the initial sync by removing the “-n” from the command above.
  5. For final migration, stop all service on the source server to keep data consistency and avoid data corruption. Then perform step number 4 again.
  6. Now you can try to restart your VM in the new environment or DC. The server supposed to boot normally unless you’ve done something wrong.

Hope this helps you.
Thank You.

Leave a Reply

Your email address will not be published. Required fields are marked *