10月31日任務linux
10.28 rsync工具介紹bash
10.29/10.30 rsync經常使用選項ssh
10.31 rsync經過ssh同步tcp
10.2八、linux文件同步工具-rsync工具
10.29 /10.30、rsync經常使用選項ui
-a 包含 -rtplgoDrem
-r 同步目錄時要加上,相似cp時的-r選項同步
-v 同步時顯示一些信息,讓咱們知道同步的過程test
-l 保留軟鏈接module
-L 加上該選項後,同步軟鏈接時會把源文件給同步
-p 保持文件的權限屬性
-o 保持文件的屬主
-g 保持文件的屬組
-D 保持設備文件信息
-t 保持文件的時間屬性
--delte 刪除DEST中SRC沒有的文件
--exclude 過濾指定文件,如--exclude "logs"會把文件名包含logs的文件或者目錄過濾掉,不一樣步
-P 顯示同步過程,好比速率,比-v更加詳細
-u 加上該選項後,若是DEST中的文件比SRC新,則不一樣步
-z 傳輸時壓縮
#運用,把目錄/root/目錄下111目錄同步到/tmp/下並改名爲111_dest
[root@zgxlinux-aliyun 111]# rsync -av /root/111/ /tmp/111_dest/ sending incremental file list created directory /tmp/111_test ./ 1.txt 2.txt passwd.txt zgx -> /etc/passwd 222/ sent 1,264 bytes received 119 bytes 2,766.00 bytes/sec total size is 967 speedup is 0.70 [root@zgxlinux-aliyun 111]# ls /tmp/ 111_dest Aegis-<Guid(5A2C30A2-A87D-490A-9281-6765EDAD7CBA)> 1.txt systemd-private-2c5b8db77cfb4ec8b50aeac4c31538bb-ntpd.service-EadYZI [root@zgxlinux-aliyun ~]# ll 111/ total 8 -rw-r--r-- 1 root root 0 Oct 31 14:26 1.txt drwxr-xr-x 2 root root 4096 Oct 31 14:29 222 -rw-r--r-- 1 root root 0 Oct 31 14:28 2.txt -rw-r--r-- 1 root root 956 Oct 31 14:27 passwd.txt lrwxrwxrwx 1 root root 11 Oct 31 14:32 zgx -> /etc/passwd [root@zgxlinux-aliyun ~]# ll /tmp/111_dest/ total 8 -rw-r--r-- 1 root root 0 Oct 31 14:26 1.txt drwxr-xr-x 2 root root 4096 Oct 31 14:29 222 -rw-r--r-- 1 root root 0 Oct 31 14:28 2.txt -rw-r--r-- 1 root root 956 Oct 31 14:27 passwd.txt lrwxrwxrwx 1 root root 11 Oct 31 14:32 zgx -> /etc/passwd
#加上L選項會把軟連接的源文件給拷貝到目標目錄
[root@zgxlinux-aliyun ~]# tail -n2 /etc/passwd tcpdump:x:72:72::/:/sbin/nologin nscd:x:28:28:NSCD Daemon:/:/sbin/nologin [root@zgxlinux-aliyun ~]# useradd zhangguoxiang [root@zgxlinux-aliyun ~]# tail -n2 /etc/passwd nscd:x:28:28:NSCD Daemon:/:/sbin/nologin zhangguoxiang:x:1000:1000::/home/zhangguoxiang:/bin/bash [root@zgxlinux-aliyun ~]# rsync -avL /root/111/ /tmp/111.dest/ sending incremental file list ./ 1.txt 2.txt passwd.txt zgx 222/ sent 2,312 bytes received 99 bytes 4,822.00 bytes/sec total size is 1,979 speedup is 0.82 [root@zgxlinux-aliyun ~]# tail -n2 /tmp/111.dest/zgx nscd:x:28:28:NSCD Daemon:/:/sbin/nologin zhangguoxiang:x:1000:1000::/home/zhangguoxiang:/bin/bash
#添加delete選項後會刪除源文件中沒有的文件
[root@zgxlinux-aliyun ~]# ls /root/111/ 1.txt 222 2.txt passwd.txt zgx [root@zgxlinux-aliyun ~]# ls /tmp/111_dest/ 1.txt 222 2.txt passwd.txt zgx [root@zgxlinux-aliyun ~]# touch /tmp/111_dest/new.txt [root@zgxlinux-aliyun ~]# ls /tmp/111_dest/ 1.txt 222 2.txt new.txt passwd.txt zgx [root@zgxlinux-aliyun ~]# rsync -avL --delete /root/111/ /tmp/111_dest/ sending incremental file list deleting new.txt ./ sent 162 bytes received 31 bytes 386.00 bytes/sec total size is 2,020 speedup is 10.47 [root@zgxlinux-aliyun ~]# ls /tmp/111_dest/ 1.txt 222 2.txt passwd.txt zgx
#加上exclude表示過濾
[root@zgxlinux-aliyun ~]# ls /tmp/111_dest/ 1.txt 222 2.txt passwd.txt zgx [root@zgxlinux-aliyun ~]# rm -rf /tmp/111_dest/* [root@zgxlinux-aliyun ~]# rsync -avL --exclude "*.txt" /root/111/ /tmp/111_dest/ sending incremental file list ./ zgx 222/ sent 1,197 bytes received 42 bytes 2,478.00 bytes/sec total size is 1,054 speedup is 0.85 [root@zgxlinux-aliyun ~]# ls /tmp/111_dest/ 222 zgx
10.31 rsync經過ssh同步
rsync經過ssh方式同步
rsync -av test1/ 192.168.133.132:/tmp/test2/
rsync 經過服務的方式同步
要編輯配置文件 /etc/rsyncd.conf
啓動服務 rsync --daemon
格式 : rsync -av test1/192.168.133.130::module/dir/