In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "the characteristics and working methods of rsync in Linux system". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Introduction of rsync data synchronization Service in Linux system
Rsync is an open source, fast, multi-functional, full and incremental local or remote data synchronous backup tool, which is suitable for a variety of operating system platforms.
One: features (functions) of rsync
1. Support copying special files (such as linked files, device files)
2. When copying, you can exclude the function that the directory or file in the directory does not need synchronization.
3. You can keep the attributes of the source file or directory unchanged
4. The full and incremental synchronization function can be realized with high transmission efficiency.
5. It can be used together with scp, ssh, rsh, etc.
6. Data can be synchronized through socke transmission.
7. Support the sum mode of anonymity or authentication (no need for system users) to transfer synchronous data
Second: the way rsync works
1. Host local transmission, similar to cp command
2. Transfer data through SSH service
3. Transfer data in a daemon way
Three: rsync synchronization command format
1. Local host
Local: rsync [OPTION...] SRC... [DEST]
Rsync-avz / etc/hosts / tmp/text/
Copy the local / etc/hosts file to the / tmp/text/ directory
[root@Centos ~] # rsync-avz / etc/hosts / tmp/text/
Sending incremental file list
Hosts
Sent 124 bytes received 31 bytes 310.00 bytes/sec
Total size is 158 speedup is 1.02
[root@Centos ~] # cd / tmp/text/
Test life execution results
[root@Centos text] # cat / etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@Centos text] # cat / tmp/text/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
What you should pay attention to when synchronizing locally is the difference between / tmp/text/ and / tmp/text. The former is the contents of the synchronized directory, and the latter is synchronized with the current directory.
2. With SSH service
Access via remote shell:
Pull: rsync [OPTION...] [USER@] HOST:SRC... [DEST]
Rsync-avzP-e''ssh-p 22 "root@192.168.1.3:/etc/hosts / tmp
Copy the / etc/hosts file of the remote host to the / tmp directory
[root@Centos text] # rsync-avzP-e "ssh-p 22" root@192.168.1.3:/etc/hosts / tmp
Root@192.168.1.3's password:
Receiving incremental file list
Hosts
183 100% 178.71kB/s 0:00:00 (xfer#1, to-check=0/1)
Sent 36 bytes received 146 bytes 40.44 bytes/sec
Total size is 183 speedup is 1.01
Test pull data
[root@Centos text] # contents of files under the local cat / tmp/hosts directory
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
# www.baidu.com
[root@localhost ~] # cat / etc/hosts remote host directory file content
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
# www.baidu.com
[root@localhost ~] # ifconfig
Eth0 Link encap:Ethernet HWaddr 00:0C:29:53:55:79
Inet addr:192.168.1.3 Bcast:192.168.1.255 Mask:255.255.255.0
Inet6 addr: fe80::20c:29ff:fe53:5579/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:330 errors:0 dropped:0 overruns:0 frame:0
TX packets:243 errors:0 dropped:0 overruns:0 carrier:0
Collisions:0 txqueuelen:1000
RX bytes:33999 (33.2KiB) TX bytes:30301 (29.5KiB)
It shows that the data was pulled successfully and the contents of the local and remote files are the same.
Push: rsync [OPTION...] SRC... [USER@] HOST:DEST
Rsync-avzP / etc/hosts-e''ssh-p 22 "root@192.168.1.3:/etc/hosts
Synchronize the local / etc/hosts file to the remote host / etc/hosts to synchronize the internal data of the two files
Test push data
[root@Centos text] # rsync-avzP / etc/hosts-e "ssh-p 22" root@192.168.1.3:/etc/hosts
Root@192.168.1.3's password:
Sending incremental file list
Hosts
158% 0.00kB/s 0:00:00 (xfer#1, to-check=0/1)
Sent 124 bytes received 37 bytes 35.78 bytes/sec
Total size is 158 speedup is 0.98
[root@Centos text] # cat / etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@localhost ~] # cat / etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
After testing, the contents of the files at both ends are the same, and the push data is successful.
3. Daemon mode
Since the relevant configuration is not configured in the current environment, the execution of the command cannot be tested. The relevant configuration process and specific parameters will be described later.
Access via rsync daemon:
Pull: rsync [OPTION...] [USER@] HOST::SRC... [DEST]
Rsync [OPTION...] Rsync:// [USER@] HOST [: PORT] / SRC... [DEST]
Rsync-avzP rsync://root@192.168.1.3:/etc/hosts / etc/hosts
Copy the hosts file on the remote host to the local / etc/hosts directory
Push: rsync [OPTION...] SRC... [USER@] HOST::DEST
Rsync [OPTION...] SRC... Rsync:// [USER@] HOST [: PORT] / DEST
Rsync-avzP / sever/backup rsync://root@192.168.1.2/data/bbs/
Synchronize the local / sever/backup data to the remote host / data/bbs/
Four: introduction of parameters
-an archived recursive transfer (equivalent to rtopgDl)
-v display detail mode
-z compress during transmission (as when transferring pictures, compress the size to increase the transmission speed)
-P displays transmission progress information
-- exclude specified files or directories during exclude transfer
This is the end of the introduction to "the characteristics and working methods of the Linux system rsync". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.