rsync介绍
rsync是类unix系统下的数据镜像备份工具
主要有以下三种用法:
1、本地备份
例:[iyunv@server~]#rsync /data/ /home/oldboy/
2、远端备份
例:pull
[iyunv@A~]# rsync-avz oldboy.txt -e 'ssh' 192.168.129.128:~ push [iyunv@A~]# rsync-avz -e 'ssh' 192.168.129.128:~/f1 ./ 3、daemon模式备份
以守护进程(socket)的方式传输数据(这个是rsync自身的重要功能)
rsync daemon模式配置
服务端:
[iyunv@A ~]#vi /etc/rsyncd.conf
创建rsync默认配置文件路径 /etc/rsyncd.conf 将 默认配置考到此文件内 以下是默认配置 #rsync_config___________start #created by oldboy16:01 2016-12-02 ##rsyncd.confstart## uid = rsync gid = rsync usechroot = no max connections =200 timeout = 300 pid file =/var/run/rsyncd.pid lock file =/var/run/rsync.lock log file =/var/log/rsyncd.log [oldboy] path = /oldboy/ ignore errors read only = false list = false hosts allow =192.168.0.0/24 hosts deny =0.0.0.0/32 auth users =rsync_backup secrets file =/etc/rsync.password #rsync_config_________end
rsyncd.conf 里面的共享目录 oldboy 要存在 启动服务之后的操作 [iyunv@A ~]# mkdir/oldboy -p [iyunv@A ~]# useraddrsync -s /sbin/nologin [iyunv@A ~]# chown-R rsync.rsync /oldboy [iyunv@A ~]# echo"rsync_backup:oldboy" >/etc/rsync.password [iyunv@A ~]# chmod600 /etc/rsync.password [iyunv@A ~]# rsync --daemon 注:rsync --daemon 可以放入/etc/rc.local 开机启动 [iyunv@A ~]# netstat -lntup|grep 873 至此服务端配置完毕
客户端:
[iyunv@B ~]# echo"rsync_backup:oldboy" >/etc/rsync.password [iyunv@B ~]# chown 600/etc/rsync.password
[iyunv@B tmp]# rsync -avz /tmp/ rsync_backup@192.168.129.128::oldboy --password-file=/etc/rsync.passwordsending incremental file list
./
123.txt
ceshi.log
123/
sent 192 bytes received 54 bytes 492.00 bytes/sec
total size is 0 speedup is 0.00
[iyunv@B tmp]#
[iyunv@C tmp]# ll
total 4
drwxr-xr-x. 2 root root 4096 Dec 7 13:10 123
-rw-r--r--. 1 root root 0 Dec 7 13:11 123.txt
-rw-r--r--. 1 root root 0 Dec 7 13:10 ceshi.log
[iyunv@A oldboy]# ll
total 4
drwxr-xr-x 2 rsync rsync 4096 Dec 7 00:10 123
-rw-r--r-- 1 rsync rsync 0 Dec 7 00:11 123.txt
-rw-r--r-- 1 rsync rsync 0 Dec 7 00:10 ceshi.log
-rw------- 1 rsync rsync 0 Nov 16 02:44 yum.log
|