rsync介绍
主要有以下三种用法:
1、本地备份
例:[root@server~]#rsync /data/ /home/oldboy/
2、远端备份
例:pull
[root@A ~]# rsync -avz oldboy.txt -e 'ssh' 192.168.129.128:~
push
[root@A ~]# rsync -avz -e 'ssh' 192.168.129.128:~/f1 ./
3、daemon模式备份
以守护进程(socket)的方式传输数据(这个是rsync自身的重要功能)
rsync daemon模式配置
服务端:
[root@A~]#vi /etc/rsyncd.conf
创建rsync默认配置文件路径 /etc/rsyncd.conf 将 默认配置考到此文件内
以下是默认配置
#rsync_config___________start
#created by oldboy 16:01 2016-12-02
##rsyncd.conf start##
uid = rsync
gid = rsync
use chroot = 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 要存在
启动服务之后的操作
[root@A ~]# mkdir/oldboy -p
[root@A ~]# useradd rsync -s /sbin/nologin
[root@A ~]# chown -R rsync.rsync /oldboy
[root@A ~]# echo"rsync_backup:oldboy" >/etc/rsync.password
[root@A ~]# chmod600 /etc/rsync.password
[root@A~]#rsync --daemon
注:rsync --daemon 可以放入/etc/rc.local 开机启动
[root@A~]#netstat -lntup|grep 873
至此服务端配置完毕
客户端:
[root@B ~]# echo"rsync_backup:oldboy" >/etc/rsync.password
[root@B ~]# chown 600 /etc/rsync.password
[root@B ~]# rsync -avz rsync_backup@192.168.129.128::oldboy /tmp/ --password-file=/etc/rsync.password
[root@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
[root@B tmp]#
[root@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
[root@A oldboy]# ll
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