How to Setup Rsync on Linux

    Testing Environment

    • Server-side Host Rsync server
    • Client-side Host

    Server-side configuration

    Install packages

    #sudo yum -y install xinetd  rsync

    Setup xinetd

    Modify “disable = yes” to “disable = no” (/etc/xinetd.d/rsync)

    #sudo vim /etc/xinetd.d/rsync

    Sample file:

    service rsync
    disable = no #Update "yes" to "no"
    socket_type = stream
    wait = no
    user = root
    server = /usr/bin/rsync
    server_args = –daemon
    log_on_failure += USERID

    Start xinetd services

    #sudo  /etc/init.d/xinetd start

    Setup iptables

    The port of rsync service is 873.

    # iptables -A INPUT -p tcp --dport 873 -j ACCEPT

    Sample outputs:

    # iptables --list
    ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh 
    ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:rsync 

    Save the new rule:

    #sudo /etc/init.d/iptables save

    Edit “rsyncd.conf”

    #sudo vim /etc/rsyncd.conf

    Sample content:

    # Global setup
    hosts allow=  
    hosts deny=*
    log file = /var/log/rsyncd.log
    uid = root
    gid = root
    # Module setup
    path = /var/www
    auth users = admin
    secrets file = /etc/rsyncd.secrets
    read only= yes
    path = /var/database
    auth users = admin
    secrets file = /etc/rsyncd.secrets
    read only= yes

    Edit “rsyncd.secrets”

    #sudo vim /etc/rsyncd.secrets

    Sample content:


    Modify the permission of “rsynced.secrets”

    #sudo  chown root:root /etc/rsyncd.secrets
    #sudo  chmod 600 /etc/rsyncd.secrets

    Client-side configuration

    Install rsync

    #sudo yum -y install rsync



    rsync [OPTION]... SRC DEST
    rsync [OPTION]... SRC [USER@]HOST:DEST
    rsync [OPTION]... [USER@]HOST:SRC DEST
    rsync [OPTION]... [USER@]HOST::SRC DEST
    rsync [OPTION]... SRC [USER@]HOST::DEST	
    rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]


    Rsync data

    # rsync -avz admin@ /www

    Rsync data with delete

    # rsync -avz --delete admin@ /www

    NOTE With delete(Warnin:When using this parameter, it is recommended to use absolute path 136 Specify the local directory path to prevent empty the current directory)

    Rsync data with SSH

    SeeHow to backup data useing rsync with SSH

    Rsync data with crond

    Files and Directories

    Content of backup(“/opt/backup”):

    drwxr-xr-x 11 lampnode lampnode May 23 09:44 data
    -r--------  1 lampnode lampnode   23 Jun 15 15:39 rsync.pwd
    -rwx------  1 lampnode lampnode  122 Jun 15 15:43

    Content Example:


    Content Example:

    /usr/bin/rsync -avz admin@ /opt/backup/data --password-file=/opt/backup/rsync.pwd

    Related articles

    comments powered by Disqus