In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Linux uses the operation method of data backup synchronization tool Rsync. In view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
For operation and maintenance personnel, data backup is one of the most important work. Rsync is a tool / software that backs up important data through the network.
Rsync is also a network protocol that synchronizes folders and files between systems over the network on Unix-like and Window-like systems. It can copy or display directories and copy files. Rsync listens to TCP port 873 by default and copies files via remote shell such as rsh and ssh. Sync is also required to be installed on both remote and local systems.
If it is not installed on Linux, it is easy to install:
The code is as follows:
# sudo apt-get install rsync # online installation methods such as debian, ubuntu, etc.
# yum install rsync # Fedora, Redhat and other online installation methods
# rpm-ivh rsync # Fedora, Redhat and other rpm package installation methods
The main advantages of rsync are:
Speed: everything is initially copied between local and remote. Next time, only the changed blocks or bytes will be transferred.
Security: the transmission can encrypt data through the ssh protocol.
Low bandwidth: rsync can compress and decompress data blocks at both ends.
Sync command syntax:
The code is as follows:
# rsysnc [options] source path destination path
The following describes the specific usage based on the parameters and application scenarios of sync:
Example: 1-enable compression
The code is as follows:
[root@localhost /] # rsync-zvr / home/aloft/ / backuphomedir
Building file list... Done
.bash _ logout
.bash _ profile
.bashrc
Sent 472 bytes received 86 bytes 1116.00 bytes/sec
Total size is 324 speedup is 0.58
The above rsync command uses-z to enable compression,-v is visual, and-r is recursive. The above synchronizes between the local / home/aloft/ and / backuphomedir.
Example: 2-preserve the properties of files and folders
The code is as follows:
[root@localhost /] # rsync-azvr / home/aloft/ / backuphomedir
Building file list... Done
. /
.bash _ logout
.bash _ profile
.bashrc
Sent 514 bytes received 92 bytes 1212.00 bytes/sec
Total size is 324 speedup is 0.53
Above we used the-an option, which retains everyone and their groups, timestamps, soft links, permissions, and runs in recursive mode.
Example: 3-synchronize local to remote host
The code is as follows:
Root@localhost /] # rsync-avz / home/aloft/ azmath@192.168.1.4:192.168.1.4:/share/rsysnctest/
Password:
Building file list... Done
. /
.bash _ logout
.bash _ profile
.bashrc
Sent 514 bytes received 92 bytes 1212.00 bytes/sec
Total size is 324 speedup is 0.53
The above command allows you to synchronize between local and remote machines. You can see that you are prompted for a password when synchronizing files to another system. When doing remote synchronization, you need to specify the user name and IP or hostname of the remote system.
Example: 4-synchronize remotely to local
The code is as follows:
[root@localhost /] # rsync-avz azmath@192.168.1.4:192.168.1.4:/share/rsysnctest/ / home/aloft/
Password:
Building file list... Done
. /
.bash _ logout
.bash _ profile
.bashrc
Sent 514 bytes received 92 bytes 1212.00 bytes/sec
Total size is 324 speedup is 0.53
The above command synchronizes remote files locally.
Example: 5-find out the differences between files
The code is as follows:
[root@localhost backuphomedir] # rsync-avzi / backuphomedir / home/aloft/
Building file list... Done
Cd+ backuphomedir/
> f + backuphomedir/.bash_logout
> f + backuphomedir/.bash_profile
> f + backuphomedir/.bashrc
> f + backuphomedir/abc
> f + backuphomedir/xyz
Sent 650 bytes received 136 bytes 1572.00 bytes/sec
Total size is 324 speedup is 0.41
The above command helps you find the difference between the file or directory between the source address and the destination address.
Example: 6-backup
The rsync command can be used to back up linux.
You can use rsync in cron to schedule backups.
The code is as follows:
0 * / usr/local/sbin/bkpscript & > / dev/null
Vi / usr/local/sbin/bkpscript
Rsync-avz-e'ssh-p2093' / home/test/ root@192.168.1.150:/oracle/data/
Rsync incremental transfer of large files optimization skills:
Question:
Rsync is very useful for synchronizing data, especially incremental synchronization. But there is a situation where it doesn't work very well without adding specific parameters. For example, you have to synchronize dozens of gigabytes of files, and then the network is suddenly disconnected, and you restart incremental synchronization. However, it is found that there is no data transmission after waiting for a long time, but the IO of the machine remains high.
Reason:
The specific incremental synchronization algorithm of rsync is not clear. According to its performance, when incrementally synchronizing a file that already exists, it will check whether some of the transferred data is consistent with the source file, and the verification is complete before continuing to incrementally synchronize the remaining data of the file. So incremental synchronization of a large file with such an algorithm is very time-consuming and IO-intensive.
Methods:
Spent more than an hour in the middle of the night looking at rsync documents and found that there is a parameter that can quickly restore the incremental synchronization of large files,-append. Setting the-append parameter calculates the file size during incremental synchronization and appends new data directly to the file, saving the IO check process. However, it is best to use this parameter only when neither the source file nor the destination file will be changed, such as backed up files.
This is the answer to the question about the operation method of using the data backup synchronization tool Rsync in Linux. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.