Jump to content

Sync Files between Linux Servers

Cowboy Denny

Recommended Posts

Many cases you spend a lot of time and energy creating files to have someone trash the system and you spend what feels like forever trying to get your files back.  Well an easy solution to setup is using another Linux server so your files are always in two places.

We are going to use the very powerful rsync tool to sync a directory and all subdirectories and files from an Active server to a server that we will using as our Backup server.

Directory to backup: /apps  

Utilize SSH key for authentication between both servers 

  1. Create ssh key on Backup server by running: ssh-keygen -t rsa -b 2048 (If asked for a password leave blank)
  2. Copy the Private and Public created keys to Active server: ssh-copy-id -i /root/.ssh/id_rsa.pub root@

Install rsync on both servers 

  1. sudo yum install rsync -y 
  2. sudo dnf install rsync -y 
  3. From Backup Server, do an Initial rsync from Active box without using a password: rsync -avzhe ssh root@ /

Setup Cron to do this every 5min

  1. From Backup Server run: crontab -e
  2. Create a new line and paste the successful rsync command: * * * * * rsync -avzhe ssh root@ / (this will test every minute and once successful we'll update it)

Validate / Test

Here I typically add a test.txt file to one of the directories on the Active Server and see if it shows up on the Backup server..  If so, success..  If not, time to troubleshoot step by step

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...