Linux Learning Summary (28) data Synchronization tool rsync

Source: Internet
Author: User
Tags file permissions rsync

Rsync is a data mirroring backup tool for Linux systems. Using the Fast incremental Backup tool remote Sync can be synchronized remotely, support local replication, or synchronize with other SSH and rsync hosts.

rsync格式rsync [OPTION] … SRC   DESTrsync [OPTION] … SRC   [[email protected]]host:DESTrsync [OPTION] … [[email protected]]host:SRC   DEST
1 rsync Common options

-A contains-rtplgod
-r Sync Directory with the-R option similar to CP
-V synchronization shows some information, let us know the process of synchronization
-L reserved Soft connection
-L with this option, the source files are synchronized when the soft link is synchronized
-P Keep File permissions property
-O Keep File owner
-G hold file of the genus Group
-D Keep Device file information
-T keep file Time properties
--delete Delete files in dest that are not in SRC
--exclude filter the specified file, such as--exclude "logs" will be the file name contains logs files or directories filtered out, not synchronized
-P shows the synchronization process, such as rate, more detailed than-V
-U plus this option, if the file in dest is newer than SRC, it is out of sync
-Z Compression during transfer
We found that the A option contains many other options, so our common options are combined with AV

2 SSH remote Sync

Local synchronization
rsync -av /etc/passwd /tmp/1.txt
Remote synchronization via SSH

rsync -av test1/ 192.168.133.132:/tmp/test2/rsync -av 192.168.133.132:/tmp/test2/ test1/rsync -av -e "ssh -p 22" test1/ 192.168.133.132:/tmp/test2/  //有时需要指定端口
3 Client-server Mode synchronization

To edit a configuration file/etc/rsyncd.conf
Start the servicersync --daemon
Format:rsync -av test1/ 192.168.133.130::module/dir/
PS aux |grep rsync or NETSTAT-LNP |grep rsync to see if the service is started
Here is an example of a configuration file:

port=873log file=/var/log/rsync.logpid file=/var/run/rsyncd.pidaddress=192.168.133.130[test]path=/root/rsyncuse chroot=truemax connections=4read only=nolist=trueuid=rootgid=rootauth users=testsecrets file=/etc/rsyncd.passwdhosts allow=192.168.133.132 1.1.1.1 2.2.2.2  192.168.133.0/24

Detailed configuration file:
PORT specifies on which ports to start, default is 873
Log file: Specify log files
PID file specifies the PID files, which are related to the start, stop and other process management operations of the service.
Adress: Specifies the IP that initiates the RSYNCD service. If your machine has multiple IPs, you can specify that one of the boot RSYNCD services, if not specified, is started on all IPs by default.
[] Specify the module name
Path: Specifying the data storage path
Use Chroot:true|false: Represents the first chroot to the directory specified by the path parameter before transferring the file. The reason for this is to implement additional security, but the disadvantage is that you need root permissions, and you cannot back up the directory files that point to external symbolic connections. By default, the Chroot value is true, and it is recommended to set false if there is a soft connection file in your data.
Max connections: Specifies the maximum number of connections, which defaults to 0, which means there is no limit.
Read Only Ture|false: If true, you cannot upload to the path specified by the module.
List: Indicates whether the module is listed when the user queries the available modules on the server, set to True is listed, and false is hidden.
Uid/gid: Specifies which user/group is transferred as the file is transferred.
Auth Users: Specifies the user name to use when transferring.
Secrets file: Specifies the password files, which, together with the parameters above, do not use password authentication if they are not specified. Note that the password file's permissions must be 600. Format: User name: Password
Hosts allow: Represents the host that is allowed to connect to the module, either IP or network segment, if multiple, separated by a space.
Set Password:
Edit the password file specified in the configuration file just now
echo "test:lv123" > /etc/rsyncd.passwdNote that the password file name is a keyword and cannot be taken lightly.
The file permission should be changed to 600
If you want to bring a password on the command line, you can set a password file
rsync -avL [email protected]::test/test1/ /tmp/test8/ --password-file=/etc/pass
Where the/etc/pass content is a password, the permissions should be changed to 600
We can also not specify the authentication account, the default is the root user synchronization.
Let's comment out the auth user line.
sed -i ‘s/auth users/#auth users/‘ /etc/rsyncd.conf

4 Final Summary

Summarize some important parameters of rsync
Rsync typically uses a parameter of-AV
-L can synchronize soft-linked source files
-P More detailed display of the synchronization process
--delete Delete files that are not in the source file in the destination file, meaning delete backup redundancy
--exclude filtering out the specified file, not synchronizing
-U Reference file time property to avoid overwriting new files with old files

Linux Learning Summary (28) data Synchronization tool rsync

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.