Rsync + crontab for timed file synchronization (first full + subsequent increments)

Source: Internet
Author: User
Tags rsync

First, Introduction

In the configuration of HA, you need to configure the configuration of multiple nodes, the configuration of the nodes are often similar to duplicate, perhaps through the SCP and other means to achieve, but each change requires manual SCP also seems troublesome, this way we can use Rsync to achieve file synchronization.

When using Rsync+crontab to do timed synchronization, the main server side opens the Rsync daemon, while the mirror server is running rsync client, usually using crontab timing to obtain data on the rsync server.



Second, the configuration

①rsync server (file send out side)

Run in the background as a daemon

1.rsync installation and file package composition

[[email protected] ~]# yum install rsync[[email protected] ~]# rpm  -ql rsync /etc/xinetd.d/rsync         ## Management/usr/bin/rsync              # based on XINETD #rsync工具/usr/share/doc/rsync-3.0.6 /usr/share/doc/rsync-3.0.6/copying /usr/share/doc/rsync-3.0.6/ news /usr/share/doc/rsync-3.0.6/oldnews /usr/share/doc/rsync-3.0.6/readme /usr/share/doc/ rsync-3.0.6/support /usr/share/doc/rsync-3.0.6/support/makefile /usr/share/doc/rsync-3.0.6/support/ atomic-rsync /usr/share/doc/rsync-3.0.6/support/cvs2includes /usr/share/doc/rsync-3.0.6/support/ deny-rsync /usr/share/doc/rsync-3.0.6/support/file-attr-restore /usr/share/doc/rsync-3.0.6/support/ files-to-excludes /usr/share/doc/rsync-3.0.6/support/git-set-file-times /usr/share/doc/rsync-3.0.6/ Support/logfilter /usr/share/doc/rsync-3.0.6/support/lsh /usr/share/doc/rsync-3.0.6/support/mnt-excl /usr/share/doc/rsync-3.0.6/ support/munge-symlinks /usr/share/doc/rsync-3.0.6/support/rrsync /usr/share/doc/rsync-3.0.6/support/ Rsyncstats /usr/share/doc/rsync-3.0.6/support/savetransfer.c /usr/share/doc/rsync-3.0.6/tech_ Report.tex /usr/share/man/man1/rsync.1.gz /usr/share/man/man5/rsyncd.conf.5.gz

The configuration file and the corresponding file are not provided in the package composition, so you need to add the following yourself:

[Email protected] ~]# MKDIR/ETC/RSYNCD # #创建配置目录 [[email protected] ~]# touch/etc/rsyncd/rsyncd.conf # #创建主配置文件 [email  Protected] ~]# touch/etc/rsyncd/rsyncd.secrets # #创建用户密码文件 [[email protected]e1 ~]# chmod 600/etc/rsyncd/rsyncd.secrets # #修改用户密码文件 [[email protected] ~]# TOUCH/ETC/RSYNCD/RSYNCD.MOTD # #创建定义服务器信息的文件

2. Edit Configuration rsyncd.conf

[[email protected] ~]# vi /etc/rsyncd/rsyncd.conf# minimal configuration  File for rsync daemon # see rsync (1)  and rsyncd.conf (5)  man  Pages for help# this line is required by the /etc/init.d/rsyncd  script pid file = /var/run/rsyncd.pid port = 873   ## Listening Port  address = 192.168.192.208  # #监听地址   #uid  = nobody  #gid  =  nobody   uid = root gid = rootuse chroot = yes    # #是否限制在指定目录, in order to install, generally need to enable  read only = no#limit access to  private lans hosts allow=192.168.192.0/255.255.255.0   # #允许网段  hosts  deny=*max connections = 5 motd file = /etc/rsyncd/rsyncd.motd#this  Will give you a separate log file  #log  file = /var/log/rsync.log#This will  Log every file transferred - up to 85,000+ per user, per  sync  #transfer  logging = yeslog format = %t %a %m %f  %b syslog facility = local3 timeout = 300# #定义一个同步目录 [Webdir] path  = /var/www/html list=yes ignore errors auth users = apache  secrets file = /etc/rsyncd/rsyncd.secrets  # #指定上述账号密码文件  comment = web  homeexclude =   data/   # #排除目录


3. Add account password file

[Email protected] ~]# vi/etc/rsyncd/rsyncd.secretsapache:123456# #注意, this account is the system account, but not the password to use the system account, but the custom password


4. Let Rsync run as daemon

[Email protected] ~]#/usr/bin/rsync--daemon--config=/etc/rsyncd/rsyncd.conf


5. Auto Start on Boot

[Email protected] ~]# echo "/usr/bin/rsync--daemon--config=/etc/rsyncd/rsyncd.conf" >>/etc/rc.d/rc.local


② Configuring the Client for Rsync

The client also needs to install rsync, but only need to configure the following files

[Email protected] ~]# MKDIR/ETC/RSYNCD # #创建配置目录 [[email protected] ~]# echo "passowd123" >/etc/rsyncd/rsyncd.passwor D # #创建密码文件, the password is the password in the server-side rsyncd.secrets file. [Email protected] ~]# chmod 600/etc/rsyncd/rsyncd.password




③ Synchronous operation

[Email protected] ~]# rsync-avzp--delete--password-file=/etc/rsyncd/rsyncd.password [email protected]::webdir/var/ www/html/Description:--delete: Local and server exactly the same, if the local presence is different, then delete, with caution--password-file: Specify the password file, if not specified, you need to manually enter a: parameter, equivalent to-rlptgod,-r is recursive-l is a link file, which means to copy the link file;-p to maintain the original file permissions;-T to keep the file in its original user group;-O to keep the original owner of the file;-D is equivalent to block device files;-Z: Transfer time compression;-P: transfer progress; Rotected]::webdir uses a double colon to refer to a defined resource in the master configuration file, or to synchronize with an absolute path after a single quotation mark, only the new content is synchronized.



Will rsync-avzp--delete--password-file=/etc/rsyncd/rsyncd.password [email protected]::webdir/var/www/html/ Write crontab to


This article is from the "Lu2yu" blog, make sure to keep this source http://lu2yu.blog.51cto.com/10009517/1632410

Rsync + crontab for timed file synchronization (first full + subsequent increments)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.