LowEndBox - Cheap VPS, Hosting and Dedicated Server Deals

How to Migrate a Hosted Server in 5 Easy Steps with Rsync

In order to migrate the files on a VPS box from one provider to another, one of the best solutions for the job is to use a tool called Rsync.

Let’s take a closer look at Rsync and see how it can help you rapidly move virtual private servers from one provider to another.

About Rsync

Rsync is one of the most common ways to copy/backup/restore files and folders between two locations, regardless if these endpoints are local or remote servers.

It supports compression, encryption and incremental transfer which makes the app an extremely versatile and useful tool for systems administrators.

Note: Running Rsync does not require you to be logged in as root.

Since Rsync supports incremental file transfer, the first time you will run it, it will require the same time to copy all the files as any other command However, when you subsequently execute Rsync, it will determines which changes have been made and only transfers those files.

This mechanism is designed to save time for the system admin, load and bandwidth.
Getting Acquainted with Rsync

Let’s get started and copy our live running server in a new location in 5 easy steps.

Step 1) Ensure that your OS is in Place

In order to migrate your server to a new location, the first step is to install your operating system onto new infrastructure. You can determine what architecture your current server is running on with the following command:

uname –a

You will want to use a Linux distro and kernel as close as possible to the one installed on server you are migrating.

Most VPS providers will set this up for you when you buy your new VPS server.

Tip: You may only need to do this step if you are building out a server locally. Hypervisors such as VMware help administrators streamline the process of installing operating systems onto hardware.

Step 2) Check the connection between the 2 servers

Once you have the two systems up and running you will need to check to see if it will be possible to make a connection between the two servers.

You can easily do that with the command “ssh”. Assuming you are running SSH from the new server and trying to connect to the old one, if the old server asks for the password, you passed the test!

ssh user@oldserver

Step 3) Check Rsync

At this point you will have to verify that Rsync is installed on both systems and if not, it’s time to install it. You can check if the command is present in the following way:

which rsync

In case the tool should not be present, you can easily install it using the following commands:

apt-get install rsync (on Ubunbu based distros)
yum install rsync (on CentOS based distros)

Step 4) Prepare the Exclude List

You will now only need to decide which directories to exclude. This may vary from system to system, but I would never suggest you to include the following unless differently needed:

/etc/sysconfig/network-scripts/* (CentOS distros)
/etc/network/* (Ubuntu distros)

Step 5) Run Rsync

Some VPS administrators may be worried about running Rsync while a MySQL instance running.

In most cases, this won’t present a problem. You might consider running it outside of heavy load periods if your server is hosting a live system, but other than that you should not have any problems.

Of course you will not have a consistent copy of the DB unless you stop the service before beginning Rsync, so please keep that in mind.

In this instance, Rsync will create a copy and it will allow you to test the system on the new server, which is usually always a big plus.

An Example of Rsync at Work

Assuming you are logged into the destination server, you’d implement a command that looks like this:

rsync -auHxv –numeric-ids –exclude=/etc/fstab –exclude=/etc/network/* –exclude=/proc/* –exclude=/tmp/* –exclude=/sys/* –exclude=/dev/* –exclude=/mnt/* –exclude=/boot/* –exclude=/root/* root@SRC-IP:/* /

Once it finishes, simply reboot your destination server and you will notice that you will have a precise copy of the files located on your source VPS.

(Tutorial written by a contributor)



  1. agentmishra:




    January 25, 2016 @ 5:37 pm | Reply
  2. Bacula, I think it can do a better job

    January 26, 2016 @ 8:10 pm | Reply
  3. Anton:

    Please make a tutorial about redundancy with rsync

    January 31, 2016 @ 4:42 pm | Reply
  4. Sven:

    Regarding database consistency – you can just run rsync twice. First you run it while the DB is up, then you stop the DB and run it again. It won’t take very long the second time and you will have a consistent copy of the data.

    February 4, 2016 @ 1:26 pm | Reply
  5. hawkjohn7:

    Please make tutorial about HA website, thanks

    February 8, 2016 @ 11:09 am | Reply
  6. goya:

    how about with using custom ssh port ? for example im using port 8888

    February 10, 2016 @ 5:02 am | Reply
    • Pedro Frota:

      To use rsync over a different ssh port, use -e “ssh -p XXXX” where XXXX is the port number needed.
      The shell command listed in the post would then become:

      rsync -auHxv -e "ssh -p XXXX" –numeric-ids –exclude=/etc/fstab –exclude=/etc/network/* –exclude=/proc/* –exclude=/tmp/* –exclude=/sys/* –exclude=/dev/* –exclude=/mnt/* –exclude=/boot/* –exclude=/root/* root@SRC-IP:/* /
      February 16, 2016 @ 10:58 am | Reply
    • Sven W.:

      add the flag “-e ‘ssh -p 22′”. where “-p 22” is the port you want to connect to via ssh.

      February 16, 2016 @ 4:11 pm | Reply
  7. Good post and rsync is a great tool to migrate.
    I recommend using the -z switch for compression to save time and bandwidth.
    One caveat is that databases should be stopped before rsyncing to ensure consistency especially for MySQL. You could always rsync a final time or export all databases.

    February 15, 2016 @ 8:40 am | Reply
  8. John Smith:

    Doesn’t work anymore. I tried exactly and follow all but not working.

    June 25, 2016 @ 5:55 pm | Reply
    • Eric Hernandez:

      It works, I am right now migrating xD over Debian Jessie

      August 30, 2016 @ 2:58 am | Reply
    • Beware that this webpage converted the double hyphens in the parameters to long hyphens so you have to replace those with double hyphens and it will work.

      September 12, 2016 @ 11:59 pm | Reply
  9. i dizzy

    September 14, 2016 @ 8:09 pm | Reply
  10. Jaap:

    Unfortunately I end up with an error. Doesn’t matter if I use – or — hyphens.

    Unexpected remote arg: root@xx.xx.xxx.x:/*
    rsync error: syntax or usage error (code 1) at main.c(1348) [sender=3.1.1]

    November 16, 2016 @ 8:33 am | Reply
    • I also getting the same error message

      February 2, 2017 @ 9:14 am | Reply
    • I get a slightly different error msg:

      Unexpected remote arg: root@xx.xx.xxx.x:/*
      rsync error: syntax or usage error (code 1) at main.c(1201) [sender=3.0.6]

      Does anyone know how to fix this?

      BTW, I tried the following changes to no avail:

      ‘ to ”
      – to —

      March 4, 2017 @ 5:02 pm | Reply
    • need to do –exclude instead of -exclude

      January 8, 2019 @ 6:14 pm | Reply
  11. Marta J. Petersenq:

    This article clearly explains how to migrate a hosted server. I like to add some more points to this Don’t Throw Out Your VPS Package Yet, Resist the Temptation to Make ‘Quick’ Changes. Find some more points here http://blog.fdcservers.net/tips-to-ensure-smooth-vps-to-dedicated-server-migration/

    January 31, 2017 @ 7:35 pm | Reply
  12. kraziekris:

    Hi, I just performed this task and while everything seemed to work fine, I cannot login to the destination server anymore as any user?

    March 9, 2017 @ 6:05 pm | Reply
  13. Melchior:

    What about users and file permissions??? Rsync is a great start for the file structure and contents, but this is hardly a migration.

    April 23, 2017 @ 10:15 am | Reply
  14. Maurizio Marini:

    Imho /etc/udev should be excluded

    May 4, 2017 @ 6:37 am | Reply
  15. Bob:

    Proper rsync command that worked for me is:
    rsync -auHxv –exclude etc/fstab –exclude etc/udev/ –exclude etc/sysconfig/network-scripts/ –exclude proc/ –exclude tmp/ –exclude sys/ –exclude dev/ –exclude mnt/ –exclude boot/ –exclude root/ –exclude opt/ root@SOURCE-IP:/* /

    Your excludes may be different than mine.

    June 14, 2017 @ 1:59 pm | Reply
  16. replays – with – and it going work

    June 26, 2017 @ 1:57 pm | Reply
  17. wow cool this helped alot

    August 8, 2017 @ 10:59 am | Reply
  18. Great post
    keep sharing :)

    August 18, 2017 @ 3:29 am | Reply
  19. David Favor:

    Be sure to exclude /etc/netplan/* + /etc/sysconfig/network-scripts/* + /etc/systemd/network/* as all these directories may contain various networking related files, which may destroy your target system.

    May 31, 2018 @ 5:22 pm | Reply
  20. fish:

    hi,mr Jarland Donnell:
    i encountered an error:

    how to solve it?

    June 29, 2018 @ 10:54 pm | Reply
  21. Maurizio Marini:

    may be interesting to not rsync /etc/lvm

    July 5, 2018 @ 6:58 am | Reply
  22. Maurizio Marini:

    maybe you should exclude /lib/modues too
    to be consistent with /boot exclusion

    July 9, 2018 @ 6:05 am | Reply
  23. Mat Jaggard:

    Because Numeric IDs are used, you need to replace /etc/passwd which didn’t happen for me, presumably because root didn’t have write access. It worked once I added write access (I also did shadow and sudoers)

    March 14, 2019 @ 3:34 am | Reply
  24. An:

    Hi, I have do that from Linode to GCP Compute Engine Instance with the followwing command:

    sudo rsync -auHxv –numeric-ids –exclude=/etc/fstab –exclude=/etc/network/* –exclude=/proc/* –exclude=/tmp/* –exclude=/sys/* –exclude=/dev/* –exclude=/mnt/* –exclude=/boot/* –exclude=/root/* root@* /

    Big thanks.

    August 23, 2019 @ 2:52 am | Reply
    • k k:

      Hello An, i have run the same command as u, AND rsync copying finishes successfully, but when i reboot my destination server, i cannot access the server via ssh, error”Could not connect to ‘’ (port 22): Connection failed.” and i reinstall the os and start over to rsync and also try to update grub using command”grub2-mkconfig -o /boot/grub2/grub.cfg” but still got the same error, can you please tell me what did u do after entering the following command? thanks so much.

      sudo rsync -auHxv –numeric-ids –exclude=/etc/fstab –exclude=/etc/network/* –exclude=/proc/* –exclude=/tmp/* –exclude=/sys/* –exclude=/dev/* –exclude=/mnt/* –exclude=/boot/* –exclude=/root/* root@IP ADDRESS:/* /

      October 3, 2019 @ 11:43 am | Reply
  25. Arnaud:

    Hi everyone,

    I’ve got the same problem that k k mentionned? When i’m doing rsync from one remote server to an other remote one, my server is not usable when it restarts, and my ssh is not working anymore.

    Any suggestion ?



    December 8, 2019 @ 11:58 am | Reply
  26. You must exclude the folder with ssh keys

    June 16, 2020 @ 5:09 am | Reply
  27. hi,
    I ran into syntax errors while running this command in Debian 9. The command below worked for me.

    rsync -auHxv –numeric-ids –-exclude ‘/etc/fstab’ -–exclude ‘/etc/network/*’ -–exclude ‘/proc/*’ -–exclude ‘/tmp/*’ -–exclude ‘/sys/*’ -–exclude ‘/dev/*’ -–exclude ‘/mnt/*’ –-exclude ‘/boot/*’ -–exclude ‘/root/*’ root@REMOTE_IP: /* /

    June 30, 2020 @ 7:50 am | Reply
  28. I can’t delete the previous comment, but please ignore it, wrong command.
    This one worked for me on Debian 9 after getting a lot of syntax errors from the recommended command here.

    rsync -aHAXSz --delete --info=progress2 --numeric-ids -e "ssh" --rsync-path="rsync" --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/etc/fstab","/etc/udev/rules.d/*","/etc/network/*","/lib/modprobe.d/*"} root@REMOTE_IP:/* /
    June 30, 2020 @ 7:53 am | Reply
  29. darkust Peru:

    It’s not working for me, I need to copy all the data from centos 4 5 or 6 to a new centos server. I don’t care about wasting space I just need to copy the data minus the OS. I have tried the command but get errors.

    July 1, 2020 @ 12:09 pm | Reply
  30. Super Simple. I was going nuts with clonezilla. Just install OS (mine is ubuntu) copy over the root certificates and its done
    This worked fine on Ubuntu 18.04
    Tried to post the command but cloudflare blocked me LOL

    February 9, 2021 @ 4:38 pm | Reply
  31. Hi, Is it going to work on SUSE sap servers with licensing ? We need to migrate the server from old hypervisor to new.

    March 30, 2021 @ 12:03 pm | Reply
  32. Ashwar:

    Only this worked on Ubuntu 20 :
    rsync -auHxv –numeric-ids –exclude=/etc/fstab –exclude=/etc/network/* –exclude=/proc/* –exclude=/tmp/* –exclude=/sys/* –exclude=/dev/* –exclude=/mnt/* –exclude=/boot/* –exclude=/root/* root@Server-IP:/* /

    July 15, 2021 @ 8:49 am | Reply
  33. Michael:

    I use Ubuntu 20.04 and show error:
    rsync error: syntax or usage error (code 1) at main.c(1372) [sender=3.1.3]

    December 26, 2021 @ 6:33 am | Reply
  34. fireindark:

    rsync -aHAXSz –delete –info=progress2 –numeric-ids -e “ssh” –rsync-path=”rsync” –exclude={“/dev/*”,”/proc/*”,”/sys/*”,”/tmp/*”,”/run/*”,”/mnt/*”,”/media/*”,”/lost+found”,”/etc/fstab”,”/etc/udev/rules.d/*”,”/etc/network/*”,”/lib/modprobe.d/*”,”/boot/*”,”/root/.ssh/”,”/etc/ssh”} root@SOURCE_IP:/* /

    This script succeed in Ubuntu 22.04 Jammy

    March 4, 2024 @ 12:59 pm | Reply
    • fireindark:
      rsync -aHAXSz --delete --info=progress2 --numeric-ids -e "ssh" --rsync-path="rsync" --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/etc/fstab","/etc/udev/rules.d/*","/etc/network/*","/lib/modprobe.d/*","/boot/*","/root/.ssh/","/etc/ssh"} root@SOURCE_IP:/* /
      March 4, 2024 @ 1:00 pm | Reply

Leave a Reply

Some notes on commenting on LowEndBox:

  • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
  • Akismet is used for spam detection. Some comments may be held temporarily for manual approval.
  • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

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