[RSYNC] Setup Rsync to transfer files from one server to another

Since this tutorial will switch between the backup server and your webserver, we will use names. Backup-Server is considered as Microtronix's server and the Webserver will be considered as your server where you want to send files from.

1. Make sure that rsync is actually installed on your Webserver by typing:

  • # rsync --version

Rsync will return the version number if it's installed. If not, please referr to our "How to Install Rsync" Tutorial!

2. We will need an RSA access key so that we can access the Backup-Server from your Webserver. Please type the following on your backup server:

  • cat ~/.ssh/id_rsa.pub

If your webserver returns a key we can go ahead and copy that, since we will need that key later. Please skip to step 4 if your webserver returns an access key.

3. Create an rsa access key using the keygen on your Webserver:

  • # ssh-keygen -t rsa -N '' (NOTE: These are 2 single quotes)

Now your Webserver will return this:

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):

  • Just press ENTER and please do not type anything in!
  • cat ~/.ssh/id_rsa.pub (verify that your key is in the right place and installed!)

4. Copy the RSA access key to our Backup-Server:

  • # vi .ssh/authorized_keys

Make sure that the directory .ssh exists and copy the RSA access key into this file. If the file already contains a key just put 2 blank lines under it and paste your rsa access key into that file.

  • Save the file!

(Please make sure that you now have an keyfile on your Webserver called id_rsa.pub which is located in ~/.ssh/id_rsa.pub. Please also make sure that your key has been added to the authorized_keys file on our Backup-Server which is located in.ssh/authorized_keys)

5. Testing Rsync

  • # rsync -avz -e ssh /tmp YourBackup-ServerUsername@Backup-ServerIP:FOLDERNAME

Please replace YourBackup-ServerUsername with your ssh username on ourBackup-Server, replace Backup-ServerIP with our Backup-Server IP and replace FOLDERNAME with the folder you want to place your files in. (ex.: MyBackups or /Backups/daily) This test will transfer all your files located in the /tmp folder from your Webserver.

6. Setting an Crontab on your Webserver

  • # crontab -e

Copy and Paste into this file:

  • "* * 1 * * rsync -avz -e ssh /cpbackup YourBackup-ServerUsername@Backup-ServerIP:FOLDERNAME" (without quotes)

Replace /cpbackup with the folder you want to backup or point it to the place where cpanel creates its backups. This cronjob will run everyday. For more information about cronjobs see this article.

Tip:

  • rsync -avz --bwlimit=1000 -e ssh /cpbackup YourBackup-ServerUsername@Backup-ServerIP:FOLDERNAME

- Limit Bandwidth usage with --bwlimit from rsync to 1000 KB/s, this setting will decrease the impact on your customers, otherwise rsync will eat up all your bandwidth!

  • 56 کاربر این را مفید یافتند
آیا این پاسخ به شما کمک کرد؟

مقالات مربوطه

[RSYNC] Installing Rsync backup on your Webserver

This Tutorial will show you how to install rsync on your webserver. Please follow these...