在Linux下使用rsync的6个实例

2025-12-23 16:00:52

1、Rsync同样是一个在类Unix和Window系统上通过网络在系统间同步文件夹和文件的网络协议。Rsync可以复制或者显示目录并复制文件。Rsync默认监听TCP 873端口,通过远程shell如rsh和ssh复制文件。Rsync必须在远程和本地系统上都安装。《Linux就该这么学》

rsync的主要好处是:

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

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

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

语法:

#rsysnc [options] source path destination path

1、[root@localhost /]# rsync -zvr /home/aloft/ /backuphomedirbuilding file list ... donebash_logoutbash_profilebashrcsent 472 bytes received 86 bytes 1116.00 bytes/sectotal size is 324 speedup is 0.58

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

1、[root@localhost /]# rsync -azvr /home/aloft/ /backuphomedirbuilding file list ... done/bash_logoutbash_profilebashrc sent 514 bytes received 92 bytes 1212.00 bytes/sectotal size is 324 speedup is 0.53

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

1、root@localhost /]# rsync -avz /home/aloft/ azmath@192.168.1.4:192.168.1.4:/share/rsysnctest/Password: building file list ... done/bash_logoutbash_profilebashrcsent 514 bytes received 92 bytes 1212.00 bytes/sectotal size is 324 speedup is 0.53

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

1、[root@localhost /]# rsync -avz azmath@192.168.1.4:192.168.1.4:/share/rsysnctest/ /home/aloft/Password:building file list ... done/bash_logoutbash_profilebashrcsent 514 bytes received 92 bytes 1212.00 bytes/sectotal size is 324 speedup is 0.53

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

1、[root@localhost backuphomedir]# rsync -avzi /backuphomedir /home/aloft/building file list ... donecd+++++++ 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/sectotal size is 324 speedup is 0.41

1、rsync命令可以用来备份linux。

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

0 0 * * * /usr/local/sbin/bkpscript &> /dev/nullvi /usr/local/sbin/bkpscript rsync -avz -e ‘ssh -p2093′ /home/test/ root@192.168.1.150:/oracle/data/

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢