MOX
Products
Learn about our additional services
Resources & Elements
Return

MOXNicolás Aravena
27-09-2021

How to perform a backup on a VPS with Rsync?

Rsync is currently the most powerful tool for securely and freely backing up and synchronizing files to another server on Linux. It's a remote application that helps you efficiently transfer files. It's currently available for Unix-like systems and Microsoft Windows.

Rsync's main features are:
* Copy links (shortcuts), devices, owners, groups, and permissions.
* Does not require sudo privileges.
* Data transfers are pipelined to minimize latency costs.

By using Rsync on Linux, you can transfer and synchronize both files and directories from one remote server to another (external or your own PC).

Installing Rsync


On Debian and Ubuntu

apt-get install rsync


On CentOS

yum install rsync


External Transfer Method



Rsync can transfer via SSH, in which case the receiving server must also have Rsync support. Like all applications that have been in development for years, there are many ways to use it Rsync on Wikipedia. Personally, I have found the following very useful:

Case 1


If you want to transfer a folder exclusively to another server via SSH:
 
rsync -vPa -e 'ssh -o StrictHostKeyChecking=no' /var/www/ 154.14.123.1:/var/www/


By adding the StrictHostKeyChecking parameter to the SSH connection, we will allow the fingerprint to be entered into the .known_hosts file automatically.

In this case, we will be transferring the contents of our /var/www/ folder to the /var/www/ folder on the server located at IP 154.14.123.1. When you execute this instruction, if both servers allow SSH connections, it will request the destination server's password and the data copy will begin progressively.

Case 2


If you want to transfer a VPS to another VPS. Ideally, both should be running the same Linux distribution, but a little experimentation isn't necessary as long as you're excluding critical files and folders from the VPS:

You should create a text file with the paths to exclude during the data migration:
 
/boot
/dev
/tmp
/sys
/proc
/backup
/etc/fstab
/etc/mtab
/etc/mdadm.conf
/etc/sysconfig/network*


You can name it excludes.txt

Later, just like in case 1, we'll call the same command but with an additional parameter (--exclude-from)

rsync -vPa -e 'ssh -o StrictHostKeyChecking=no' --exclude-from=/excludes.txt / 154.14.123.1:/


Conclusion


Rsync is a very powerful tool for secure data migration. It is very important that both servers (remote and external) have Rsync support to perform this task.

In our experience with VPS, working with this tool has been very satisfactory, allowing us to perform large data migrations with very little effort. It has over a hundred options or parameter lists that we invite you to discover and experiment with.



Other articles that might interest you