码迷,mamicode.com
首页 > 系统相关 > 详细

2018-03-27 Linux学习

时间:2018-03-27 20:50:56      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:Linux   学习   2018-03-27   

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 [user@]host:DEST
rsync [OPTION] ...[user@]host:SRC DEST
rsync [OPTION] ...SRC [user@]host::DEST
rsync [OPTION] ...[user@]host::SRC DEST

    [root@aming-01 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 常用选项 下

    [root@aming-01 ~]# 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

    [root@aming-01 ~]# touch /tmp/rootbak/0011.txt
    [root@aming-01 ~]# 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

    [root@aming-01 ~]# 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

    [root@aming-01 ~]# 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)

    [root@aming-01 ~]# vim /tmp/rootbak/anaconda-ks.cfg 
    [root@aming-01 ~]# 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

    [root@aming-01 ~]# 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/

    [root@aming-01 ~]# rsync -av /etc/passwd 192.168.104.165:/tmp/aming.txt
    root@192.168.104.165‘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学习

标签:Linux   学习   2018-03-27   

原文地址:http://blog.51cto.com/9298822/2091774

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!