Eight weeks two sessions (January 30)
10.28 Rsync Tools Introduction
10.29/10.30 rsync Common Options
10.31 rsync sync via ssh
I. Introduction of RSYNC Tools
Linux system has a lot of data backup tools, commonly used is rsync, from the literal meaning of the remote sync to understand. Rsync can not only synchronize data remotely (like an SCP), but also synchronize data locally (similar to CP), but unlike the CP or SCP, it does not overwrite the previous data (if the data already exists), but rather first judging the difference between the existing data and the new data. Different parts of the data are not overwritten.
- If you do not have the rsync command, use the Yum install-y rsync installation.
Example:
[[email protected] ~]# rsync -av /etc/passwd /tmp/1.txtsending incremental file listpasswdsent 2465 bytes received 31 bytes 4992.00 bytes/sectotal size is 2391 speedup is 0.96
In the example above, the/etc/passwd is synchronized to the/tmp/directory, and renamed to 1.txt, if you want to change to remote replication, the format of data backup is: User name @ip:path, such as 192.168.188.128:/root/. The specific usage is as follows:
[[email protected] ~]# rsync-av/etc/passwd [email protected]:/tmp/1.txtthe authenticity of host ' 192.168.72.133 (192.168.72.133) ' can ' t be established. ECDSA key fingerprint is 54:1a:44:33:2e:df:c2:58:41:cf:f3:d2:e3:69:87:b7. Is you sure want to continue connecting (yes/no)? yeswarning:permanently added ' 192.168.72.133 ' (ECDSA) to the list of known hosts. [email protected] ' s password:sending incremental file listpasswdsent 2465 bytes received 253 bytes 175.35 Bytes/se Ctotal size is 2391 speedup is 0.88
This requires the remote machine must also have rsync installed, need to verify the password is because there is no two machine interconnection.
Rsync is a very powerful tool, and its commands have many feature options.
1. Command syntax format:
- [] rsync [OPTION] ... SRC DEST
- [] rsync [OPTION] ... SRC [[Email protected]]host:dest//The first case does not add [email protected], the default is root
- [] rsync [OPTION] ... [[email protected]] HOST:SRC dest//synchronizing data from a remote directory to a local
- [] rsync [OPTION] ... [[email protected]] HOST::SRC DEST
- [] rsync [OPTION] ... SRC [[Email protected]]host::D EST
2.rsync Common Options
- []-A: Contains the-RTPLGOD,A option can be followed by--no-option, which indicates that one of the-rlptgod in the shutdown is equivalent to-rptgod, for example-a--no-l
- []-R: Synchronize the directory to add, similar to the CP-r option
- []-V: Display at synchronization-some information, let us know the process of synchronization
- []-L: Keep soft connection
- []-L: When this option is added, the source files are synchronized when the soft connection is synchronized
- []-P: Keep File Permissions property
- []-O: Maintain the owner of the file
- []-G: Preserve the genus Group of files
- []-D: Keep device file information
- []-T: Keep file Time Properties
- []--delete: Delete files not in src dest
- []--exclude: Filter the specified file, such as--exclude "logs" will be the file name containing logs files or directories filtered out, not synchronized
- []-P: Shows the synchronization process, such as rate, more detailed than-V
- []-U: After adding this option, if the file in the dest is newer than SRC, the sync
- []-Z: Compression on transfer
The above options have many notes, often with-a,-v,-z,--Delete and--exclude.
3. Test options for Rsync
To replace the test, you need to create a new directory and file
[[email protected] ~]# lsanaconda-ks.cfg grep httpd-2.4.29.tar.gz [[email protected] split_dirawk httpd-2.4.29 initial-setup-ks.cfg sed xaa## ls 下没有合适的目录和文件,只能重新建[[email protected] ~]# mkdir rsync[[email protected] ~]# cd rsync[[email protected] rsync]# mkdir 111[[email protected] rsync]# touch 1 2 3 /root/123.txt[[email protected] rsync]# ln -s /root/123.txt ./134.txt //建立软链接[[email protected] rsync]# ls -l总用量 0-rw-r--r-- 1 root root 0 1月 31 23:22 1
3.1-A option Usage
3.2 Using-l usage
[[email protected] ~]# rsync -avL ./rsync/ ./test2/sending incremental file list111/111/123.txtsent 158 bytes received 35 bytes 386.00 bytes/sectotal size is 0 speedup is 0.00[[email protected] ~]# ls -l test2/总用量 0-rw-r--r-- 1 root root 0 1月 31 23:22 1drwxr-xr-x 2 root root 21 1月 31 23:50 111-rw-r--r-- 1 root root 0 1月 31 23:22 134.txt-rw-r--r-- 1 root root 0 1月 31 23:22 2-rw-r--r-- 1 root root 0 1月 31 23:22 3-rw-r--r-- 1 root root 0 1月 31 23:22 321.txt
3.3 Using the Delete option
[[email protected] ~]# rsync -avL --delete ./rsync/ ./test2/sending incremental file listsent 116 bytes received 13 bytes 258.00 bytes/sectotal size is 0 speedup is 0.00[[email protected] ~]# ls123.txt 556.txt awk httpd-2.4.29 initial-setup-ks.cfg rsync split_dir xaa321.txt anaconda-ks.cfg grep httpd-2.4.29.tar.gz [[email protected] sed test2
3.4 Using the--exclude option
[[email protected] ~]# mkdir test1[[email protected] ~]# touch test1/4[[email protected] ~]# rsync -a --exclude="4" test1/ test2/[[email protected] ~]# ls test14
Three, SSH mode synchronization
The first method: Roll out the file
[[email protected] ~]# rsync -avL test2/ 192.168.72.133:/root/xavi/[email protected]‘s password: sending incremental file list./1134.txt23321.txt111/111/123.txtsent 356 bytes received 133 bytes 75.23 bytes/sectotal size is 0 speedup is 0.00
Chapter Two: Pull the file over, Test failed!!!! Reason not found
[[email protected] ~]# rsync -avP 192.168.72.132:/root/xavi/ ./test1/ssh: connect to host 192.168.72.132 port 22: No route to hostrsync: connection unexpectedly closed (0 bytes received so far) [Receiver]rsync error: unexplained error (code 255) at io.c(605) [Receiver=3.0.9][[email protected] ~]# rsync -avP 192.168.72.132:/root/xavi/ ./test1/ssh: connect to host 192.168.72.132 port 22: No route to hostrsync: connection unexpectedly closed (0 bytes received so far) [Receiver]rsync error: unexplained error (code 255) at io.c(605) [Receiver=3.0.9]
Data Backup tool under 31.Linux rsync