Linux rsync file synchronization tool of

Learning background

1. The company's recent projects done using automated build jenkins, jenkins because when building is more consumption of performance, they use a single server to do the build server. But personally I feel that the cost is too high, take a single server to build and configure the server can not be too bad. I think by building a service in the local jenkins, do build to use. But such a question can not be used webhooks, will be selected in rotation to build. In fact, you can use the network to penetrate the way to solve the example still learning, but also the success of the experiment, the use is not particularly familiar with the latter alone write an article to share.

2. When jenkins framework, we need to configure a work directory, as /root/jenkins/workspace/daodao_systemsuch directories, but we need to use nginx configuration item catalog, it is certainly not possible to configure this jenkins working directory. By understanding, Linux synchronization command rsync command file synchronization can be achieved. This refers to the file synchronization is to jenkins working directory synchronization of files to a directory specified by us (as we nginx configuration of the project directory). And includes a synchronization command rsync, high efficiency, low bandwidth consumption, supports replication links, equipment, owner, is a group, permissions.

Commands

rsync is remote (or local) to replicate and synchronize files most commonly used commands. With rsync command, you can cross directories, disks and across networks across remote and local data replication and synchronization. For example: data backup and mirroring between two Linux host. This article describes the common use were remote and local file transfers on a Linux host without knowing the root account can also allow rsync.

rsync command Features

1. replicate efficiently synchronize data to the peer, or to the local end.

2. Copy Link support, equipment, owner, is a set of permissions.

3. than scp (Secure Copy) faster. rsync using remote update protocol (remote-update protocol), which allows transmission of only the difference between the two files. For the first transmission, the entire contents of a file or directory will be copied from the source to the target, but from the next time, it will copy only the changed portion to the target.

4.rsync consume less bandwidth because it uses the compression and decompression method of simultaneously transmitting and receiving data at both ends. HTTP compression technology.

Installation command

This article demonstrates the environment is centos7.0 version can be used directly. For installation can refer to this article

Command syntax

rsync [options] 资源源目录 目标目录

-v: Detail mode output

-r: recursive copy data, but does not retain permissions and timestamps when transferring data

-a: archive mode, archive mode always recursive copy, symbolic links and reservations, permissions, owner, is a set of timestamps

-z: compression and transmission

-h : human-readable

--progress: Displays transmission

--exclude = PATTERN exclude specified file transfer mode

--include = PATTERN mode Specifies file transfer

When the --delete sync, delete those files have DST, but not SRC

--max-size: defining a file size transfer limit

--dry-run: display those files will be transferred, and not the actual transfer

--bwlimit: limit the transmission bandwidth

-W: copying files, not the incremental detecting

Use Cases

Synchronize a local file

[root@iZ7eetumtw8c9jZ jenkins]# rsync -zvrh remoting.jar /root/work/
sending incremental file list
created directory /root/work
remoting.jar

sent 796.37K bytes  received 68 bytes  1.59M bytes/sec
total size is 872.44K  speedup is 1.10

View sync results

[root@iZ7eetumtw8c9jZ jenkins]# ll /root/work/
total 852
-rw-r--r-- 1 root root 872440 Nov  3 20:03 remoting.jar

A directory synchronization

[root@iZ7eetumtw8c9jZ jenkins]# rsync -zvrh workspace/ /root/work/
sending incremental file list 
公司服务器测试/tests/Unit/
公司服务器测试/tests/Unit/ExampleTest.php
公司服务器测试@tmp/

sent 18.82M bytes  received 7.30K bytes  7.53M bytes/sec
total size is 29.87M  speedup is 1.59

View sync results

[root@iZ7eetumtw8c9jZ jenkins]# ll /root/work/
total 868
-rw-r--r--  1 root root 872440 Nov  3 20:03 remoting.jar
drwxr-xr-x 11 root root   4096 Nov  3 20:05 公司服务器测试
drwxr-xr-x  2 root root   4096 Nov  3 20:04 公司服务器测试@tmp       

Remote directory synchronization

[root@tecmint]$ rsync -avz rpmpkgs/ [email protected]:/home/
[email protected]'s password:
sending incremental file list
./
httpd-2.2.3-82.el5.centos.i386.rpm
mod_ssl-2.2.3-82.el5.centos.i386.rpm
nagios-3.5.0.tar.gz
nagios-plugins-1.4.16.tar.gz
sent 4993369 bytes  received 91 bytes  399476.80 bytes/sec
total size is 4991313  speedup is 1.00

to sum up

Using this command, the most appealing to me is that we can achieve incremental synchronization, rather than the full amount of synchronization. This reduces bandwidth consumption, but also accelerate the speed of transmission. As for the principle of command synchronization, refer to this article

This switched micro-channel public number late at night have something to talk about release!

Guess you like

Origin www.cnblogs.com/qqblog/p/11788969.html