良许Linux教程网 干货合集 Linux下rsync使用实例

Linux下rsync使用实例

rsync 是一个常用的 Linux 应用程序,用于文件同步,它可以在本地计算机与远程计算机之间,或者两个本地目录之间同步文件(但不支持两台远程计算机之间的同步)。它也可以当作文件复制工具,替代cpmv命令,下面为大家分享一下Linux下rsync使用实例。

Linux下rsync使用实例

语法:

#rsysnc [options] source path destination path

示例: 1 – 启用压缩

[root@localhost /]# rsync -zvr /home/aloft/ /backuphomedir
building file list ... done
bash_logout
bash_profile
bashrc
sent 472 bytes received 86 bytes 1116.00 bytes/sec
total size is 324 speedup is 0.58

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

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

[root@localhost /]# rsync -azvr /home/aloft/ /backuphomedir
building file list ... done
/
bash_logout
bash_profile
bashrc

sent 514 bytes received 92 bytes 1212.00 bytes/sec
total size is 324 speedup is 0.53

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

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

root@localhost /]# rsync -avz /home/aloft/ azmath@192.168.1.4:192.168.1.4:/share/rsysnctest/
Password:

building file list ... done
/
bash_logout
bash_profile
bashrc
sent 514 bytes received 92 bytes 1212.00 bytes/sec
total size is 324 speedup is 0.53

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

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

[root@localhost /]# rsync -avz azmath@192.168.1.4:192.168.1.4:/share/rsysnctest/ /home/aloft/
Password:
building file list ... done
/
bash_logout
bash_profile
bashrc
sent 514 bytes received 92 bytes 1212.00 bytes/sec
total size is 324 speedup is 0.53

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

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

[root@localhost backuphomedir]# rsync -avzi /backuphomedir /home/aloft/
building file list ... done
cd+++++++ backuphomedir/
>f+++++++ backuphomedir/.bash_logout
>f+++++++ backuphomedir/.bash_profile
>f+++++++ backuphomedir/.bashrc
>f+++++++ backuphomedir/abc
>f+++++++ backuphomedir/xyz

sent 650 bytes received 136 bytes 1572.00 bytes/sec
total size is 324 speedup is 0.41

示例: 6 – 备份

rsync命令可以用来备份linux

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

0 0 * * * /usr/local/sbin/bkpscript &> /dev/null
vi /usr/local/sbin/bkpscript

rsync -avz -e ‘ssh -p2093′ /home/test/ root@192.168.1.150:/oracle/data/

以上就是良许教程网为各位朋友分享的Linux系统相关内容。想要了解更多Linux相关知识记得关注公众号“良许Linux”,或扫描下方二维码进行关注,更多干货等着你 !

img
本文由 良许Linux教程网 发布,可自由转载、引用,但需署名作者且注明文章出处。如转载至微信公众号,请在文末添加作者公众号二维码。
良许

作者: 良许

良许,世界500强企业Linux开发工程师,公众号【良许Linux】的作者,全网拥有超30W粉丝。个人标签:创业者,CSDN学院讲师,副业达人,流量玩家,摄影爱好者。
上一篇
下一篇

发表评论

联系我们

联系我们

公众号:良许Linux

在线咨询: QQ交谈

邮箱: yychuyu@163.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部