rsync命令的用法

相比scp,多了一个重复检测,当自己本来就有时,不复制,大大减少了复制时间

(虚拟机)

先用scp

再用rsync

对比二者复制速度,可以看出rsync的速度更快

快是因为省略了一部分东西

(真机)

创建文件

 满权力

给用户和组都改成westos

 做了个链接

查看:

 (虚拟机)

 注意,/mnt  后面带/表示光复制mnt目录里面的内容,不带/表示带着目录整个复制过来:

[root@localhost mnt]# rm -fr *
[root@localhost mnt]# history -c
[root@localhost mnt]# rsync -r root@172.25.254.111:/mnt /mnt/
root@172.25.254.111's password: 
skipping non-regular file "mnt/xizi"
[root@localhost mnt]# ls
mnt
[root@localhost mnt]# rm -fr *
[root@localhost mnt]# rsync -r root@172.25.254.111:/mnt/ /mnt/
root@172.25.254.111's password: 
skipping non-regular file "xizi"
[root@localhost mnt]# ls
westosfile1  westosfile2  westosfile3  westosfile4  westosfile5
[root@localhost mnt]# 

 一般情况下跳过链接

[root@localhost mnt]# rsync -r root@172.25.254.111:/mnt/ /mnt/
root@172.25.254.111's password: 
skipping non-regular file "xizi"

 如果想不跳过链接:(加l)

[root@localhost mnt]# rsync -lr root@172.25.254.111:/mnt/ /mnt/
root@172.25.254.111's password: 
[root@localhost mnt]# ls
westosfile1  westosfile2  westosfile3  westosfile4  westosfile5  xizi
[root@localhost mnt]# ll
总用量 0
-rwx------. 1 root root  0 1月  12 22:26 westosfile1
-rwx------. 1 root root  0 1月  12 22:26 westosfile2
-rwx------. 1 root root  0 1月  12 22:26 westosfile3
-rwx------. 1 root root  0 1月  12 22:26 westosfile4
-rwx------. 1 root root  0 1月  12 22:26 westosfile5
lrwxrwxrwx. 1 root root 16 1月  12 22:26 xizi -> /mnt/westosfile1

但是,会发现权限没有完全过来

要想要权限完全过来:(p)

[root@localhost mnt]# rsync -lpr root@172.25.254.111:/mnt/ /mnt/
root@172.25.254.111's password: 
[root@localhost mnt]# ll
总用量 0
-rwxrwxrwx. 1 root root  0 1月  12 22:30 westosfile1
-rwxrwxrwx. 1 root root  0 1月  12 22:30 westosfile2
-rwxrwxrwx. 1 root root  0 1月  12 22:30 westosfile3
-rwxrwxrwx. 1 root root  0 1月  12 22:30 westosfile4
-rwxrwxrwx. 1 root root  0 1月  12 22:30 westosfile5
lrwxrwxrwx. 1 root root 16 1月  12 22:26 xizi -> /mnt/westosfile1

用户过来:(o)

[root@localhost mnt]# rsync -lpor root@172.25.254.111:/mnt/ /mnt/
root@172.25.254.111's password: 
[root@localhost mnt]# ll
总用量 0
-rwxrwxrwx. 1 westos root  0 1月  12 22:32 westosfile1
-rwxrwxrwx. 1 westos root  0 1月  12 22:32 westosfile2
-rwxrwxrwx. 1 westos root  0 1月  12 22:32 westosfile3
-rwxrwxrwx. 1 westos root  0 1月  12 22:32 westosfile4
-rwxrwxrwx. 1 westos root  0 1月  12 22:32 westosfile5
lrwxrwxrwx. 1 root   root 16 1月  12 22:26 xizi -> /mnt/westosfile1

组过来:(加g)

[root@localhost mnt]# rsync -lporg root@172.25.254.111:/mnt/ /mnt/
root@172.25.254.111's password: 
[root@localhost mnt]# ll
总用量 0
-rwxrwxrwx. 1 westos westos  0 1月  12 22:33 westosfile1
-rwxrwxrwx. 1 westos westos  0 1月  12 22:33 westosfile2
-rwxrwxrwx. 1 westos westos  0 1月  12 22:33 westosfile3
-rwxrwxrwx. 1 westos westos  0 1月  12 22:33 westosfile4
-rwxrwxrwx. 1 westos westos  0 1月  12 22:33 westosfile5
lrwxrwxrwx. 1 root   root   16 1月  12 22:26 xizi -> /mnt/westosfile1

时间过来:(加t)

[root@localhost mnt]# rsync -lporgt root@172.25.254.111:/mnt/ /mnt/
root@172.25.254.111's password: 
[root@localhost mnt]# ll
总用量 0
-rwxrwxrwx. 1 westos westos  0 1月  12 22:08 westosfile1
-rwxrwxrwx. 1 westos westos  0 1月  12 21:12 westosfile2
-rwxrwxrwx. 1 westos westos  0 1月  12 21:12 westosfile3
-rwxrwxrwx. 1 westos westos  0 1月  12 21:12 westosfile4
-rwxrwxrwx. 1 westos westos  0 1月  12 21:12 westosfile5
lrwxrwxrwx. 1 root   root   16 1月  12 22:11 xizi -> /mnt/westosfile1

(真机) 默认情况下,设备文件同步不了

下面的字符文件,同步不过来

(虚拟机) 一般情况下自动跳过字符设备,加个D即可

[root@localhost mnt]# rsync -r root@172.25.254.111:/dev/pts/ /mnt/
root@172.25.254.111's password: 
skipping non-regular file "0"
skipping non-regular file "1"
skipping non-regular file "ptmx"
[root@localhost mnt]# rsync -rD root@172.25.254.111:/dev/pts/ /mnt/
root@172.25.254.111's password: 
[root@localhost mnt]# ls
0  1  ptmx  westosfile1  westosfile2  westosfile3  westosfile4  westosfile5  xizi
[root@localhost mnt]# ll
总用量 0
crw-------. 1 root   root   136, 0 1月  12 22:43 0
crw-------. 1 root   root   136, 1 1月  12 22:43 1
c---------. 1 root   root     5, 2 1月  12 22:43 ptmx
-rwxrwxrwx. 1 westos westos      0 1月  12 22:08 westosfile1
-rwxrwxrwx. 1 westos westos      0 1月  12 21:12 westosfile2
-rwxrwxrwx. 1 westos westos      0 1月  12 21:12 westosfile3
-rwxrwxrwx. 1 westos westos      0 1月  12 21:12 westosfile4
-rwxrwxrwx. 1 westos westos      0 1月  12 21:12 westosfile5
lrwxrwxrwx. 1 root   root       16 1月  12 22:11 xizi -> /mnt/westosfile1

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值