rsync remote synchronization

A, rsync Profile

rsync (Remote Sync, remote synchronization) is an open source fast backup tool, you can mirror the entire directory tree synchronization between different hosts, supports incremental backups, keeping links and permissions, and the use of synchronization algorithm optimization, compression is performed prior to transmission, making it ideal for remote backup, mirror server applications.

rsync official site: http: //rsync.samba.org/, the latest version is 3.1.3, maintained by Wayne Davison, as one of the most commonly used files backup tool, rsync Linux and UNIX systems are often installed by default. one of the basic components.

rsync is a fast incremental backup tool that supports:

(1) local replication;
(2) synchronized with the other the SSH;
(. 3) synchronized with the host rsync.

In remote synchronization tasks, responsible for initiating client rsync synchronization of operations as the initiator, and is responsible for the corresponding rsync server from a client synchronous operation called synchronization source. During the synchronization process, the synchronization position is responsible for providing the original source document, initiated to deal with the end position has read access. Figure:

 

 

 

Second, the configuration rsync source

Configuring rsync server source roughly divided into three steps:
(1) establish rsync configuration file;
(2) creating a data file backup account;
(3) start the rsync service.

(1) establish rsync configuration file

Before CentOS 7 system /etc/rsyncd.conf default file does not exist, CentOS start 7 have such a file, and where to place the template reference information (written content needs of the actual situation, pay attention to the format).

[root @ localhost ~] # vim / etc / rsyncd.conf 
uid = the nobody // Enable anonymous user 
gid = the nobody 
use chroot = yes // detained in the source directory 
address = 192.168 . 1.1  // Listen Address 
Port 873  // listening port 
file = log / var /log/rsyncd.log // log file location 
pid = file / var /run/rsyncd.pid // store the process ID of the file location 
hosts the allow = 192.168 . 1.0 / 24-  // client to allow access local address 
[wwwroot] // share module name
= path / var / WWW / HTML // actual path of the source directory 
Comment AAA = // description (may be omitted) 
Read only NO = // is read-only 
dont compress = * .gz * .bz2 * .rar * .zip // synchronization is no longer compressed file types 
auth = backuper the Users // authorized account 
Secrets file = /etc/rsyncd_users.db // store data files account information

 

For security purposes, for the synchronous source rsync preferably only allowed to do read-only synchronized manner. In addition, the synchronization can be used anonymously, as long as one of the "auth users" and "secrets file" configuration item can be removed!

(2) creating a data file backup account

According to rsync configuration file contents, create accounts data files. One user per line, between the user and password separated by colons.

[root@localhost ~]# vim /etc/rsyncd_users.db
backuper:123456

 

Since the account information stored in plain text, it is necessary to adjust file permissions to prevent account information leakage.

[root@localhost ~]# chmod 600 /etc/rsyncd_users.db

 

Backup source directory user should have read permissions.

[root@localhost ~]# ls -ld /var/www/html
drwxr-xr-x. 2 root root 6 11月 15 2016 /var/www/html

 

(3) start the rsync service

[root@localhost ~]# rsync --daemon
[root@localhost ~]# netstat -anpt | grep rsync
tcp 0 0 192.168.1.1:873 0.0.0.0:* LISTEN 44001/rsync

 

If you need to restart rsync service, you need:

[root @ localhost ~] # the kill $ (CAT / var / RUN / rsyncd.pid)
 // stop the service 
[root @ localhost ~] # rsync - daemon
 // start the service 
[root @ localhost ~] # the kill - 9 $ (CAT / var /run/rsyncd.pid)

 

Or directly use the "netstat -anpt | grep rsync" command to find out the process ID, use the "kill process number" the same.
The first method to stop rsync rsync service must delete the file storage service process:

[root@localhost ~]# rm -rf /var/run/rsyncd.pid

 

Third, the use rsync backup tool

Once you've configured rsync synchronization source server, the client can then use to perform remote synchronization tool rsync.

Options rsync command:
 - r: Recursive mode, the directory containing all the files and subdirectories
 - L: For symbolic link files are still copying is a symbolic link files
 - the p-: keep the file permissions mark
 - t: retention file timestamps
 - G : reserved flag is a group (only super user) files
 - O: reserved owner markup file (only super user)
 - D: retention device files and other special files
 -a: filing mode, and retain recursive object properties, is equivalent to - rlptgoD
 - V: Show (verbose) information synchronization process
 - Z: compression (the compress) file transfers
 - H: reserved connecting hard file
 - a: ACL attribute information reserved
 - delete: delete certain location the original location of the file without
 --checksum: whether to skip the file checksum determined according to the object

 

rsync is a fast incremental backup tool support:
(1) local replication;
(2) synchronized with other SSH;
(3) synchronized with rsync host.

(1) Local Copy

[the root @ localhost ~] # the rsync / etc / the passwd 123 .txt
 // similar cp command

 

(2) synchronized with the other SSH

[root@localhost ~]# rsync -av root@192.168.1.2:/root/123.txt .
root@192.168.1.2's password:

 

(3) sync with rsync host

[root@localhost ~]# rsync -avz backuper@192.168.1.1::wwwroot /root
或者
[root@localhost ~]# rsync -avz rsync://[email protected]/wwwroot /root

 

These two commands effect is the same!
Simply upload directory can reverse the order of (Make sure you have write access to the directory upload)!
Enter the following command synchronization source, write permission before implementation

[root@localhost ~]# chmod o+w /var/www/html
[root@localhost ~]# ls -ld /var/www/html
drwxr-xrwx. 2 root root 6 8月 17 16:47 /var/www/html
[root@localhost ~]# rsync -avz /root backuper@192.168.1.1::wwwroot

 

But in the real work environment, backup is often performed repeatedly as planned, such as:

[root @ localhost ~] # vim / root / 123 .pass
 123456 
// arbitrarily create a file used to store the rsync authorized user's password information 
[root @ localhost ~] # chmod 600 / root / 123 .pass
 // must be set 600 permissions, otherwise it will error when executing 
[root @ localhost ~] # crontab - E
 // create a scheduled task 
30  22 * * * / usr / bin / rsync --password--az --delete File = / root / 123 backuper @ .pass 192.168 . 1.1 :: wwwroot / A
 // 22:30 pm daily execution of the script 
[root @ localhost ~ ] # systemctl restart crond
 // restart crond service

 

Format scheduled tasks on crond profile (top to bottom)

 

 [Link] Reference:

https://mp.weixin.qq.com/s/BUOcm1Gk0OleOzsVvFcskw

Guess you like

Origin www.cnblogs.com/Tang-Yuan/p/11504434.html