metinsaylan // rogue developer

How to sync files between linux servers using Rsync

Rsync is a linux application to sync files between linux servers. It is not installed by default, so to use this command, you have to install it using following commands. ***

Install Rsync on server

Debian Linux user type the following command:

# apt-get install rsync

Fedora Linux user, user type the following command:

# yum install rsync

Red Hat Linux user, user type the following command:

# up2date rsync

FreeBSD user, user type the following command:

# pkg_add -r -v rsync

ALTERNATIVELY, use FreeBSD ports collection:

# cd /usr/ports/net/rsync
# make; make install; make clean

Basic usage to update files on a remove server

rsync -avrR --links --rsh=/usr/bin/ssh 202.54.1.11:/var/html/ /var/html
  • -avrR : archive mode (a), verbose (v), recurse into directories (r), use relative path names (R)
  • --links : copy symlinks as symlinks
  • --rsh=/usr/bin/ssh : Use to specify the remote shell ssh to use (secure copy).
  • 202.54.1.11:/var/html/ : WWW2 server IP address and path to synchronize to www1 server
  • /var/html : WWW1 server path

Using rsync in a shell script to synchronize files

#!/bin/bash
MASTER="master-server-ip"
DIR="/var/www/change-me"
LDIR="/local/dir"
SSH="/usr/bin/ssh"
rsync -avrR --links --rsh=$SSH $MASTER:$DIR $LDIR

You can find more information on rsync official site. You can find more options here and more great linux tricks here. Looking for backing up your files on linux, you can read more about it here.

Search How to sync files between linux servers using Rsync on Google