Introduction to rsync file synchronization tool, common options, synchronization via ssh

rsync file synchronization tool introduction

The rsync tool can be used to synchronize files, such as a directory to b directory, a machine to b machine, (multiple synchronization, you can only synchronize changed files)

Example: rsync -av /etc/passwd /tmp/1.txt Synchronize passwd to 1.txt, -v visualization

rsync -av /etc/passwd [email protected]:/tmp/1.txt remote sync

root@ can be omitted, the default is the currently logged in user

Common options

[root@g_linux01 ~]# rsync -av /root/soft/ /tmp/test_dest/
sending incremental file list
./
1.txt
2.txt
3.txt

sent 180 bytes  received 72 bytes  504.00 bytes/sec
total size is 0  speedup is 0.00
[root@g_linux01 ~]# ls /tmp/test_dest/
1.txt  2.txt  3.txt

--delete delete files not in the original directory

[root@g_linux01 ~]# touch /tmp/test_dest/4.txt
[root@g_linux01 ~]# rsync -av --delete /root/soft/ /tmp/test_dest/
sending incremental file list
./
deleting 4.txt

sent 63 bytes  received 15 bytes  156.00 bytes/sec
total size is 0  speedup is 0.00

 --exclude filter out log type files

[root@g_linux01 soft]# ls 
1.log  1.txt  2.txt  3.txt
[root@g_linux01 soft]# rsync -av --exclude "*.log" /root/soft/ /tmp/test_dest/
sending incremental file list
./

sent 67 bytes  received 15 bytes  164.00 bytes/sec
total size is 0  speedup is 0.00
[root@g_linux01 soft]# ls /tmp/test_dest/
1.txt  2.txt  3.txt

 Sync via ssh, -e "ssh -p 22" specifies port 22

[root@g_linux01 soft]# rsync -avP -e "ssh -p 22" /root/soft/ 192.168.198.129:/tmp/1_dest/ 
[email protected]'s password: 
Permission denied, please try again.
[email protected]'s password: 
sending incremental file list

sent 78 bytes  received 12 bytes  6.67 bytes/sec
total size is 0  speedup is 0.00

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325479128&siteId=291194637