2018-03-27 Linux学习
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2018-03-27 Linux学习相关的知识,希望对你有一定的参考价值。
10.28 rsync 工具介绍
rsync -av /etc/passwd /tmp/1.txt
rsync -av /tmp/1.txt 192.168.188.128:/tmp/2.txt
rsync 格式
rsync [OPTION] ...SRC DEST
rsync [OPTION] ...SRC [[email protected]]host:DEST
rsync [OPTION] ...[[email protected]]host:SRC DEST
rsync [OPTION] ...SRC [[email protected]]host::DEST
rsync [OPTION] ...[[email protected]]host::SRC DEST
[[email protected] system]# rsync -av /etc/passwd /tmp/1.txt
sending incremental file list
passwd
sent 1128 bytes received 31 bytes 2318.00 bytes/sec
total size is 1054 speedup is 0.91
10.29 rsync 常用选项 上
rsync 常用选项
-a 包含-rtplgoD
-r 同步目录时要加上,类似cp时的-r选项
-v 同步时显示一些信息,让我知道同步的过程
-l 保留软链接
-L 加上该选项后,同步软链接时会把源文件给同步
-p 保持文件的权限属性
-o 保持稳健的属主
-g 保持文件的属组
-D 保持设备文件信息
-t 保持文件的时间属性
--delete 删除DEST中SRC没有的文件
--exclude 过滤指定文件,如 --exclude "logs" 会把文件名包含 logs 的文件或者目录过滤掉,不同步
-P 显示同步过程,比如速率,比 -v 更加详细
-u 加上该选项后,如果DEST中的文件比SRC新,则不同步
-z 传输时压缩
10.30 rsync 常用选项 下
[[email protected] ~]# rsync -av /root/ /tmp/rootbak/
sending incremental file list
created directory /tmp/rootbak
./
.bash_history
.bash_logout
.bash_profile
.bashrc
.cshrc
.tcshrc
.viminfo
1.txt
a.txt
anaconda-ks.cfg
bacaa
bacab
bacac
.pki/
.pki/nssdb/
.ssh/
.ssh/authorized_keys
.ssh/known_hosts
awk/
awk/text.txt
grep/
grep/grep.log
grep/inittab
grep/passwd
sed/
sed/test.txt
sed/test.txt.bac
sent 581498 bytes received 438 bytes 1163872.00 bytes/sec
total size is 579989 speedup is 1.00
[[email protected] ~]# touch /tmp/rootbak/0011.txt
[[email protected] ~]# rsync -av --delete /root/ /tmp/rootbak/
sending incremental file list
./
deleting 0011.txt
sent 528 bytes received 21 bytes 1098.00 bytes/sec
total size is 579989 speedup is 1056.45
[[email protected] ~]# rsync -av --exclude "*txt" /root/ /tmp/rootbak
sending incremental file list
created directory /tmp/rootbak
./
.bash_history
.bash_logout
.bash_profile
.bashrc
.cshrc
.tcshrc
.viminfo
anaconda-ks.cfg
bacaa
bacab
bacac
.pki/
.pki/nssdb/
.ssh/
.ssh/authorized_keys
.ssh/known_hosts
awk/
grep/
grep/grep.log
grep/inittab
grep/passwd
sed/
sed/test.txt.bac
sent 329932 bytes received 362 bytes 660588.00 bytes/sec
total size is 328682 speedup is 1.00
[[email protected] ~]# rsync -avP --exclude "*txt" /root/ /tmp/rootbak
sending incremental file list
created directory /tmp/rootbak
./
.bash_history
26302 100% 0.00kB/s 0:00:00 (xfer#1, to-check=22/24)
.bash_logout
18 100% 17.58kB/s 0:00:00 (xfer#2, to-check=21/24)
.bash_profile
176 100% 171.88kB/s 0:00:00 (xfer#3, to-check=20/24)
.bashrc
176 100% 171.88kB/s 0:00:00 (xfer#4, to-check=19/24)
.cshrc
100 100% 97.66kB/s 0:00:00 (xfer#5, to-check=18/24)
.tcshrc
129 100% 125.98kB/s 0:00:00 (xfer#6, to-check=17/24)
.viminfo
5673 100% 5.41MB/s 0:00:00 (xfer#7, to-check=16/24)
anaconda-ks.cfg
1420 100% 1.35MB/s 0:00:00 (xfer#8, to-check=15/24)
bacaa
102400 100% 48.83MB/s 0:00:00 (xfer#9, to-check=14/24)
bacab
102400 100% 24.41MB/s 0:00:00 (xfer#10, to-check=13/24)
[[email protected] ~]# vim /tmp/rootbak/anaconda-ks.cfg
[[email protected] ~]# rsync -avPu --exclude "*txt" /root/ /tmp/rootbak
sending incremental file list
.viminfo
5785 100% 0.00kB/s 0:00:00 (xfer#1, to-check=16/24)
sent 6294 bytes received 37 bytes 12662.00 bytes/sec
total size is 328794 speedup is 51.93
[[email protected] ~]# rsync -avPz --exclude "*txt" /root/ /tmp/rootbak
sending incremental file list
created directory /tmp/rootbak
./
.bash_history
26302 100% 0.00kB/s 0:00:00 (xfer#1, to-check=22/24)
.bash_logout
18 100% 17.58kB/s 0:00:00 (xfer#2, to-check=21/24)
.bash_profile
176 100% 171.88kB/s 0:00:00 (xfer#3, to-check=20/24)
.bashrc
176 100% 171.88kB/s 0:00:00 (xfer#4, to-check=19/24)
.cshrc
100 100% 97.66kB/s 0:00:00 (xfer#5, to-check=18/24)
.tcshrc
129 100% 125.98kB/s 0:00:00 (xfer#6, to-check=17/24)
.viminfo
5785 100% 5.52MB/s 0:00:00 (xfer#7, to-check=16/24)
anaconda-ks.cfg
1420 100% 1.35MB/s 0:00:00 (xfer#8, to-check=15/24)
bacaa
102400 100% 19.53MB/s 0:00:00 (xfer#9, to-check=14/24)
10.31 Linux文件同步工具 rsync
rsync 通过ssh方式同步
rsync -av test1/ 192.168.133.132:/tmp/test2
rsync -avP -e "ssh -p 22" test/ 192.168.133.132:/tmp/test2/
rsync 通过服务的方式同步
要编辑配置文件 /etc/rsyncd.conf
启动服务 rsync --daemon
格式: rsync -av test1/ 192.168.133.130::module/dir/
[[email protected] ~]# rsync -av /etc/passwd 192.168.104.165:/tmp/aming.txt
[email protected]‘s password:
sending incremental file list
passwd
sent 1128 bytes received 31 bytes 331.14 bytes/sec
total size is 1054 speedup is 0.91
以上是关于2018-03-27 Linux学习的主要内容,如果未能解决你的问题,请参考以下文章
20172319 2018.03.27-04.05 《Java程序设计》第4周学习总结