前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >rsync工具 原

rsync工具 原

作者头像
阿dai学长
发布2019-04-03 14:52:01
6530
发布2019-04-03 14:52:01
举报
文章被收录于专栏:阿dai_linux阿dai_linux

10.28 rsync工具介绍

rsync命令是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件。rsync使用所谓的“rsync算法”来使本地和远程两个主机之间的文件达到同步,这个算法只传送两个文件的不同部分,而不是每次都整份传送,因此速度相当快。


语法

rsync有六种不同的工作模式:

注: src表示源文件,dest表示目的文件


10.29 Options

  • -a:包含-rtplgoD
    • -r:同步目录时加上表示对子目录进行递归处理
    • -t:保持文件的时间属性
    • -p:保持文件的权限属性
    • -l:保留软链接
    • -g:保存文件数组
    • -o:保持文件的属主
    • -D:保存设备文件信息
  • -v:=visual,可视化
  • -L:同步软链接的同时同步其源文件
  • -P:显示同步过程,比v更详细
  • -u:=update,加上该选项,如果DEST中文件比SRC中的新,则不同步
  • -z:=zip,传输时压缩
  • --delete:删除DEST中SRC没有的文件
  • --exclude:过滤指定文件,不同步

10.30 语法应用:

  • 同步本地文件
代码语言:javascript
复制
[root@adai003 ~]# rsync -av /etc/passwd /tmp/11.txt
sending incremental file list
passwd

sent 1222 bytes  received 31 bytes  2506.00 bytes/sec
total size is 1148  speedup is 0.92
  • 将本地机器的内容拷贝到远程机器
代码语言:javascript
复制
[root@adai003 ~]# rsync -av /etc/passwd root@192.168.8.129:/tmp/11.txt
root@192.168.8.129's password: 
sending incremental file list
passwd

sent 1222 bytes  received 31 bytes  358.00 bytes/sec
total size is 1148  speedup is 0.92

注: 进行远程同步的时候,远程机和本地机必须都安装有rsync工具才可以。

  • 将本地机器的内容拷贝到远程机器,当端口不一致时:
代码语言:javascript
复制
[root@adai003 ~]# rsync -av -e "ssh -p 22" /etc/passwd root@192.168.8.129:/tmp/11.txt
root@192.168.8.129's password: 
sending incremental file list

sent 31 bytes  received 12 bytes  7.82 bytes/sec
total size is 1148  speedup is 26.70
  • 将远程机器的内容拷贝到本地机器。
代码语言:javascript
复制
[root@adai003 ~]# rsync -av root@192.168.8.129:/etc/passwd /tmp/22.txt 
root@192.168.8.129's password: 
receiving incremental file list
passwd

sent 42 bytes  received 83 bytes  27.78 bytes/sec
total size is 1149  speedup is 9.19

10.31选项应用

  • rsync -avP 显示详尽的同步过程
代码语言:javascript
复制
[root@adai003 ~]# rsync -avP /root/grep/ /tmp/grep_dest/
sending incremental file list
created directory /tmp/grep_dest
./
717.sh
          65 100%    0.00kB/s    0:00:00 (xfer#1, to-check=20/22)
aaa.sed.shell
          47 100%    3.53kB/s    0:00:00 (xfer#2, to-check=19/22)
…………
  • rsync -avL 同步软链接的同时同步其源文件
代码语言:javascript
复制
[root@adai003 ~]# rsync -avL /root/grep/ /tmp/grep_dest/
sending incremental file list
adailink

sent 1530 bytes  received 32 bytes  3124.00 bytes/sec
total size is 14275  speedup is 9.14
  • rsync -av --delete 删除目标文件中和源文件中不一样的文件
代码语言:javascript
复制
[root@adai003 ~]# touch /tmp/grep_dest/new2.txt

[root@adai003 ~]# rsync -av --delete /root/grep/ /tmp/grep_dest/
sending incremental file list
./
deleting new2.txt  ##删除文件new2.txt
adailink -> /root/awk/test.txt

sent 405 bytes  received 19 bytes  848.00 bytes/sec
total size is 13178  speedup is 31.08
  • rsync -av --exclude 传输时过滤掉指定文件
代码语言:javascript
复制
[root@adai003 ~]# rsync -av --exclude "*.txt" --exclude "*.shell" /root/grep/ /tmp/grep_dest/
sending incremental file list
./
717.sh
adailink -> /root/awk/test.txt
boot.log.bak

注: 可以同时过滤多种文件。

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017/07/18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 10.28 rsync工具介绍
    • 语法
    • 10.29 Options
    • 10.30 语法应用:
    • 10.31选项应用
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档