Ubuntu 下安装配置 rsync

07/31/2020
  • 启用rsync
royakon@localhost~: sudo vim /etc/default/rsync
...
RSYNC_ENABLE=true # fals改为true
  • Server 端配置
# | - /etc/rsyncd.conf
# | - /etc/rsyncd
#            | - rsyncd.secrets
#            | - rsyncd.motd

royakon@localhost~: mkdir /etc/rsyncd
royakon@localhost~: touch /etc/rsyncd/rsyncd.secrets
royakon@localhost~: touch /etc/rsyncd/rsyncd.motd
royakon@localhost~: sudo chmod 600 /etc/rsyncd/rsyncd.secrets

royakon@localhost~: sudo vim /etc/rsyncd.conf

...
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
port=873
syslog facility = local3
...
[site-backup]
    comment                =    www.magth.cn site backup
    path                =    /home/magth/backup
    userchroot            =    yes
    max Connections        =    10
    motd file            =    /etc/rsyncd/rsyncd.motd

    lock file            =    /var/lock/rsyncd    
    #centos /var/run/rsync.lock

    read only            =    yes
    list                 =    yes
    uid                    =    root
    gid                    =    root
    exclude                =    error_log    httpd.pid
    auth users            =    magth
    secrets file        =    /etc/rsyncd/rsyncd.secrets
    strict modes        =    yes
    ignore errors        =    yes
    ignore nonreadable    =    yes
    transfer logging    =    yes
    log format            =    %t: host %h (%a) %o %f (%l bytes). Total %b bytes.
    timeout                =    600
    refuse options        =    checksum dry-run
    dont compress        =    *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz
...


royakon@localhost~: sudo vim /etc/rsyncd/rsyncd.secrets

magth:Admin@20o20


royakon@localhost~: sudo vim /etc/rsyncd/rsyncd.motd

++++++++++++++++++++++++++++++++
+ www.magth.cn rsync 2020-2030 +
++++++++++++++++++++++++++++++++



royakon@localhost~: sudo vim /etc/services

...
rsync    873/tcp    #rsync
rsync 873/udp    #rsync
...


royakon@localhost~: sudo vim /etc/xinetd.d/rsync

service rsync
{
    disable         = no
    socket_type     = stream
    wait            = no
    user            = root
    server          = /usr/bin/rsync
    server_args     = --daemon --config=/etc/rsyncd.conf
    log_on_failure  += USERID
}



royakon@localhost~: sudo service xinetd restart
royakon@localhost~: sudo /etc/init.d/rsync start
  • Client 配置
royakon@localhost~: mkdir /etc/rsyncd
royakon@localhost~: touch /etc/rsyncd/rsyncd.secrets

Admin@20o20


# Test 
royakon@localhost~: sudo rsync -vzrtopg --delete --progress  --password-file=/etc/rsyncd/rsyncd.secrets --port=873 magth@www.magth.cn::site-backup /home/magth/backup/site
  • 同步脚本
royakon@localhost~: vim /home/magth/backup/script/site-rsync.sh

#!/bin/sh
sudo rsync -vzrtopg --delete  --password-file=/etc/rsyncd/rsyncd.secrets --port=873 magth@www.magth.cn::site-backup /home/magth/backup/site

royakon@localhost~: chmod +x site-rsync.sh
  • 定时任务
royakon@localhost~: crontab -e

25        21        *        *        *        /home/magth/backup/script/site-rsync.sh