Sync Files Between Servers with 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

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.


© 2021 metinsaylan