Linux文件同步rsync

Linux文件同步工具 — rsync

  • 安裝 yum install -y rsync
  • rsync -va /etc/passwd /tmp/1.txt # 把/etc/passwd同步拷貝到/tmp/1.txt
  • rsync -va /tmp/1.txt root@192.168.77.129:/tmp/2.txt rsync # 把/tmp/1.txt文件同步到192.168.77.129的/tmp下,並命名爲2.txt

常見選項
-a 包含-rtplgoD
-r 同步目錄時要加上,相似cp時的-r選項
-v 同步時顯示一些信息,可視化同步的過程
-l 保留軟鏈接
-L 像對待常規文件同樣處理軟鏈接。若是是SRC中有軟鏈接文件,則加上該選項後,將會把軟鏈接指向的目標文件複製到DST
-p 保持文件權限
-o 保持文件屬主信息
-g 保持文件屬組信息
-D 保持設備文件信息
-t 保持文件時間信息
--delete 刪除DST中SRC沒有的文件
--exclude=PATTERN 指定排除不須要傳輸的文件,等號後面跟文件名,能夠使用通配符(如*.txt)
-P 顯示經過過程,好比速率,比-v更詳細
-u 表示把DST中比SRC還新的文件排除掉,不會覆蓋
-z 傳輸過程當中壓縮ssh

[root@test-a ~]# rsync -va test_dir/ /tmp/test_dir
sending incremental file list
./

sent 43 bytes  received 19 bytes  124.00 bytes/sec
total size is 0  speedup is 0.00

[root@test-a test_dir]# rsync -vaLP /root/test_dir/ /tmp/test_dir/
sending incremental file list
./
b.txt
              0 100%    0.00kB/s    0:00:00 (xfr#1, to-chk=0/3)

sent 130 bytes  received 38 bytes  336.00 bytes/sec
total size is 472  speedup is 2.81

rsync經過ssh方式同步工具

  • rsync -va test1/ 192.168.77.129:/tmp/test2/
  • rsync -va -e "ssh -p 22" test1/ 192.168.77.129:/tmp/test2/
相關文章
相關標籤/搜索