手机版
你好,游客 登录 注册
背景:
阅读新闻

如何在Linux下使用rsync

[日期:2014-12-23] 来源:Linux中国  作者:Linux [字体: ]

对于各种组织和公司,数据对他们是最重要的,即使对于电子商务,数据也是同样重要的。Rsync是一款通过网络备份重要数据的工具/软件。它同样是一个在类Unix和Window系统上通过网络在系统间同步文件夹和文件的网络协议。Rsync可以复制或者显示目录并复制文件。Rsync默认监听TCP 873端口,通过远程shell如rsh和ssh复制文件。Rsync必须在远程和本地系统上都安装。

rsync的主要好处是:

速度:最初会在本地和远程之间拷贝所有内容。下次,只会传输发生改变的块或者字节。

安全:传输可以通过ssh协议加密数据。

低带宽:rsync可以在两端压缩和解压数据块。

语法:

  1. #rsysnc [options] source path destination path

示例: 1 - 启用压缩

  1. [root@localhost /]# rsync -zvr /home/aloft//backuphomedir
  2. building file list ...done
  3. .bash_logout
  4. .bash_profile
  5. .bashrc
  6. sent 472 bytes received 86 bytes 1116.00 bytes/sec
  7. total size is324 speedup is0.58

上面的rsync命令使用了-z来启用压缩,-v是可视化,-r是递归。上面在本地的/home/aloft/和/backuphomedir之间同步。

示例: 2 - 保留文件和文件夹的属性

  1. [root@localhost /]# rsync -azvr /home/aloft//backuphomedir
  2. building file list ...done
  3. ./
  4. .bash_logout
  5. .bash_profile
  6. .bashrc
  7.  
  8. sent 514 bytes received 92 bytes 1212.00 bytes/sec
  9. total size is324 speedup is0.53

上面我们使用了-a选项,它保留了所有人和所属组、时间戳、软链接、权限,并以递归模式运行。

示例: 3 - 同步本地到远程主机

  1. root@localhost /]# rsync -avz /home/aloft/ azmath@192.168.1.4:192.168.1.4:/share/rsysnctest/
  2. Password:
  3.  
  4. building file list ...done
  5. ./
  6. .bash_logout
  7. .bash_profile
  8. .bashrc
  9. sent 514 bytes received 92 bytes 1212.00 bytes/sec
  10. total size is324 speedup is0.53

上面的命令允许你在本地和远程机器之间同步。你可以看到,在同步文件到另一个系统时提示你输入密码。在做远程同步时,你需要指定远程系统的用户名和IP或者主机名。

示例: 4 - 远程同步到本地

  1. [root@localhost /]# rsync -avz azmath@192.168.1.4:192.168.1.4:/share/rsysnctest/ /home/aloft/
  2. Password:
  3. building file list ...done
  4. ./
  5. .bash_logout
  6. .bash_profile
  7. .bashrc
  8. sent 514 bytes received 92 bytes 1212.00 bytes/sec
  9. total size is324 speedup is0.53

上面的命令同步远程文件到本地。

示例: 5 - 找出文件间的不同

  1. [root@localhost backuphomedir]# rsync -avzi /backuphomedir /home/aloft/
  2. building file list ...done
  3. cd+++++++ backuphomedir/
  4. >f+++++++ backuphomedir/.bash_logout
  5. >f+++++++ backuphomedir/.bash_profile
  6. >f+++++++ backuphomedir/.bashrc
  7. >f+++++++ backuphomedir/abc
  8. >f+++++++ backuphomedir/xyz
  9.  
  10. sent 650 bytes received 136 bytes 1572.00 bytes/sec
  11. total size is324 speedup is0.41

上面的命令帮助你找出源地址和目标地址之间文件或者目录的不同。

示例: 6 - 备份

rsync命令可以用来备份linux。

你可以在cron中使用rsync安排备份。

  1. 00***/usr/local/sbin/bkpscript &>/dev/null

  1. vi /usr/local/sbin/bkpscript
  2.  
  3. rsync -avz -e ssh -p2093/home/test/ root@192.168.1.150:/Oracle/data/

Rsync+inotify实现Git数据实时同步备份 http://www.linuxidc.com/Linux/2014-10/108298.htm

Rsync实现文件备份同步详解 http://www.linuxidc.com/Linux/2014-09/106967.htm

Rsync同步两台服务器 http://www.linuxidc.com/Linux/2014-09/106574.htm

CentOS 6.5下Rsync远程同步 http://www.linuxidc.com/Linux/2014-05/101084.htm

Ubuntu Linux下用Rsync进行数据备份和同步配制 http://www.linuxidc.com/Linux/2014-03/97592.htm

Linux使用Rsync客户端与服务端同步目录进行备份 http://www.linuxidc.com/Linux/2014-02/97068.htm

Rsync 的详细介绍请点这里
Rsync 的下载地址请点这里

本文永久更新链接地址http://www.linuxidc.com/Linux/2014-12/110754.htm

linux
相关资讯       rsync 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款