rsync Remote Sync

Source: Internet
Author: User
Tags auth file permissions iptables rsync ssh server

The official site of Rsync is located in http://rsync.samba.org
Rsync is a data mirroring Backup tool under Unix-like systems--remote sync. A fast incremental backup tool remote Sync, which supports local replication or synchronizes with other SSH and rsync hosts.

Rsync includes some of the following features:
1. Ability to update entire directory tree and file system;
2. Has the selective keeping symbol chain, the hard link, the document attribute, the authority, the equipment and the time and so on;
3. Perform compression before transmission, so it is very suitable for offsite backup, mirror server and other applications.
4. Can use rsh, SSH or direct port as the transmission port;
5. Support anonymous rsync synchronization files, is the ideal mirror tool;

Rsync can be used in rsh or SSH or in daemon mode, and Rsync server will open a 873 port to wait for the client to connect when running daemon.
In a remote synchronization task, the client responsible for initiating the rsync synchronization is called the initiator, and the server that responds to the rsync synchronization from the airliner is called the backup source.
1. Configure the SSH backup source:

The advantage of using the SSH protocol is the ability to enhance the confidentiality of backups based on more secure remote connections. This way the backup source is easiest to configure, as long as you confirm the location of the source folder and prepare a backup operation User (System user)
commonly used parameters are:

-A (--archive): Archive mode, which represents the transfer of files recursively, and maintains all file attributes, equal to-rlptgod. -
V (--verbose): Verbose mode output. -
Z (--compress): Compresses files that are backed up while they are being transferred.
-P (--progress): Displays the transfer process during transmission.
--delete: Delete files that are not in the DST src
--config=file: Specify additional configuration files and do not use the default rsyncd.conf file
--password-file=file Get the password from file
----------------------------------------------------------
-r,–recursive the subdirectory in recursive mode
-L,  --links represents the Copy link file
-p,--perms means to keep the file's original permissions-
T,--times to maintain the original time of the file
-G,--group to maintain the original user group of the file
-O,--owner means to maintain the original owner
-D of the file,--devices represents the block device file information

Client: 192.168.198.131 Backup Source: 192.168.198.132
Execute rsync command on client to implement downlink synchronization

Rsync-avzh--delete Rget@192.168.198.132:/var/www/html/wwwroot

Uplink sync ssh backup Source:
The upload of content from the/usr/share/directory in the client is synchronized to the/var/www/html directory of the SSH server, and options such as "G", "-o" will not be available because the backup user rput is not the root user.

Rsync-rlvz--delete/usr/share/rput@192.168.198.132:/var/www/html

Create a key pair on the client, distribute the public key file to the server (a SSH b, give a public key to B)

ssh-keygen-t RSA
Ssh-copy-id rget@192.168.198.132
2. Configure Rsync backup Source:

Rsync is not only used as the initiator (client) of remote synchronization, it can also run as a daemon, provide backup sources for other clients, configure Rsync backup sources to establish profile rsync.conf, create backup accounts, and then run rsync programs with the "--daemon" option.
Introduction to rsync configuration file:
Global parameters: Effective for the entire Rsync server, if module parameters and global parameters conflict, module parameters for the conflict module take effect
Module parameters: Defining the parameters of a directory definition that needs to be exported through rsync
To Create a rsyncd.conf file:

vim/etc/rsyncd.conf uid = nobody #指定当该模块传输文件时守护进程应该具有的uid gid = nobody #指定当该模块传输文件时守护进程应该具有的gid use chroot = yes A  ddress = 192.168.198.132 Port = 873 #默认873 Log file =/var/log/rsyncd.log #指定日志文件 without sending the log to the syslog PID File =/var/run/rsyncd.pid #存放进程ID的文件位置 hosts allow = 192.168.198.131 # A single IP address, for example: 192.167.0.1, multiple IP or network segments need to be separated by spaces, # The entire network segment, such as
: 192.168.0.0/24, or 192.168.0.0/255.255.255.0 # "*" means all, by default, all host connections are allowed. # max connections Specifies the maximum number of concurrent connections for this module.
The default value is 0, with no restrictions. # lock file Specifies the lock files that support the Max connections parameter, the default value is/var/run/rsyncd.lock [wwwroot] path =/var/www/html #供备份的目录树路径 Co mment = document Root of test #给模块指定一个描述 Read Only = yes # Exclude: Specifies multiple files or directories (relative paths) separated by spaces. Equivalent to using the-exclude dont compress in the command = *.gz *.bz2 *.tgz *.zip *.tzr *.z Auth users = backuper # Specifies a list of user names separated by spaces or commas, only These users are allowed to connect to the module secrets file =/etc/rsyncd_users.db # only when "auth users" is defined. Each row contains a USERNAME:PASSWD pair without a default secures file name, Note: File permissions must be 600, otherwise the client will not be able to connect to the server Timeout = #超Time unit is seconds, 0 indicates no time-out definition, this is also the default value 

Based on security considerations, it is best to allow only read-only downlink synchronization for the backup source for rsync, and it is recommended that you use an SSH backup source if you do need to do an uplink synchronization. In addition, downlink backups can be anonymous, as long as the "Auth users" and "Secrets File" configuration records are removed.

to create a data file for a backup account:

Vim/etc/rsyncd_users.db
backuper:123456

chmod 600/etc/rsyncd_users.db

Start and close rsync

rsync--daemon                   #启动
Kill $ (cat/var/run/rsyncd.pid)  #关闭

Note: Creating a rule on the iptables firewall allows 873-port traffic:

Iptables-i input-p TCP--dport 873-j ACCEPT

Save "Rsync–daemon" to the/etc/rc.local file to ensure that the Rsync service starts automatically after the system starts

echo "Rsync--daemon" >>/etc/rc.local

below, use the Rsync Backup tool to implement backup operations
Format 1:
rsync option username @ backup Source server IP:: Shared module Name target directory
Or
Format 2:
rsync option rsync://username @ backup Source server ip/shared module name target directory

Rsync-avzp backuper@192.168.198.132::wwwroot/wwwroot/
or
rsync-avzh rsync://backuper@192.168.198.132/ wwwroot/wwwroot/

The above Launch rsync service program is the "Rsync–daemon" way to start the rsync service. Considering the characteristics of offsite backup, usually does not require a full day uninterrupted operation, preferably only when there is a client connection to enable, so you can give rsync to the Super service xinetd management, as long as the corresponding configuration and start xinetd services, you can provide rsync services. That is, when the XINETD service receives a synchronization request from the client, the Rsync synchronization request is transferred to the Rsync program.
Configuration method:

Kill $ (cat/var/run/rsyncd.pid)
sed-i ' 6s/yes/no/'/etc/xinetd.d/rsync
#将disable = yes to No; certain--daemon service options

Install and start the XINETD service

Yum install xinetd 
service xinetd start
chkconfig xinetd on

Reprint please be sure to retain this source: http://blog.csdn.net/fgf00/article/details/50732731

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.