https://rsync.samba.org/
Remote synchronization

rsync 相当于 scp cp rm
quick check 算法
拉取 推送

https://www.samba.org/ftp/rsync/

软件使用说明

https://www.samba.org/ftp/rsync/rsync.html

NAME
rsync — a fast, versatile, remote (and local) file-copying tool
SYNOPSIS
Local: rsync [OPTION…] SRC… [DEST]
Access via remote shell:
Pull: rsync [OPTION…] [USER@]HOST:SRC… [DEST]
Push: rsync [OPTION…] SRC… [USER@]HOST:DEST
Access via rsync daemon:
Pull: rsync [OPTION…] [USER@]HOST::SRC… [DEST]
rsync [OPTION…] rsync://[USER@]HOST[:PORT]/SRC… [DEST]
Push: rsync [OPTION…] SRC… [USER@]HOST::DEST
rsync [OPTION…] SRC… rsync://[USER@]HOST[:PORT]/DEST
Usages with just one SRC arg and no DEST arg will list the source files
instead of copying.

推送实例
[root@backup-server ~]# rsync -avzP -e ‘ssh -p 22’ /tmp/ root@192.168.222.21:/tmp
root@192.168.222.21’s password:
sending incremental file list
sent 74 bytes received 13 bytes 19.33 bytes/sec
total size is 0 speedup is 0.00
[root@backup-server ~]#

拉取实例

[root@backup-server ~]# rsync -avzP -e ‘ssh -p 22’ root@192.168.222.21:/tmp/ /home/
root@192.168.222.21’s password:
receiving incremental file list
tmp/
tmp/liweiming
0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=1/3)
tmp/.ICE-unix/
sent 38 bytes received 130 bytes 37.33 bytes/sec
total size is 0 speedup is 0.00
[root@backup-server ~]#

第一种工作模式 local

rsync -avz /etc/hosts /tmp/ ==cp
rsync -avz —delete /null /tmp/ ==rm

第二种工作模式 remote shell

push
rsync -avzP -e ‘ssh -p 22’ /tmp/ root@192.168.222.21:/tmp
pull
rsync -avzP -e ‘ssh -p 22’ root@192.168.222.21:/tmp/ /home/

第三种工作模式 daemon

客户端 常用参数
-v -vernose 详细模式输出和进度等信息
-z —compress 传输时进行压缩 提高传输效率 —compress-level=NUM可按照级别压缩
-a —archive 归档模式 表示递归方式传输文件并保持所有文件属性
-r —recursive 对子目录以递归模式
-t —time 保持文件时间信息
-o —owner 保持文件属主信息
-p —perms 保持文件权限
-g —group 保持文件属组信息
-P —progress 显示同步过程
-D —devices 保持设备文件信息
-I —-links 保留软链接
-e — 使用的传输协议

生产 -avz 或者 -vzrtopg
https://www.samba.org/ftp/rsync/rsync.html

1 备份服务器
rsync服务端
[root@backup-server ~]# rsync —version
rsync version 3.0.6 protocol version 30
Copyright (C) 1996-2009 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
append, ACLs, xattrs, iconv, symtimes
rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you
are welcome to redistribute it under certain conditions. See the GNU
General Public Licence for details.
[root@backup-server ~]#

[root@backup-server ~]# rpm -qa rsync
rsync-3.0.6-12.el6.x86_64
[root@backup-server ~]#

[root@backup-server ~]# touch /etc/rsyncd.conf
[root@backup-server ~]# vim /etc/rsyncd.conf
[root@backup-server ~]# cat /etc/rsyncd.conf
##Rsync server
##rsyncd.conf_start##
uid = rsync
gid = rsync
use chroot = no
max connections = 2000
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[backup]
comment = databackup
path = /backup/
ignore errors
read only = false
list = false
hosts allow = 192.168.222.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
##rsync_config_end##

启动服务
[root@backup-server ~]#rsync —daemon

[root@backup-server ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:873 0.0.0.0: LISTEN 1193/rsync
tcp 0 0 0.0.0.0:22 0.0.0.0:
LISTEN 1173/sshd
tcp 0 0 :::873 ::: LISTEN 1193/rsync
tcp 0 0 :::22 :::
LISTEN 1173/sshd
[root@backup-server ~]#

客户端
1创建密码文件
echo “AAbb0101” > /etc/rsync.password
chmod 600 /etc/rsync.password
2 推送文件 rsync
[root@backup-server01 ~]# rsync -avz /tmp/ rsync_backup@192.168.222.20::backup —password-file=/etc/rsync.password
sending incremental file list
./
liweiming
.ICE-unix/
sent 108 bytes received 34 bytes 284.00 bytes/sec
total size is 0 speedup is 0.00
[root@backup-server01 ~]#

3 拉取远端到本地
[root@backup-server01 tmp]# rsync -avz rsync_backup@192.168.222.20::backup /tmp/ —password-file=/etc/rsync.password
receiving incremental file list
./
liweimin
liweiming
test
sent 125 bytes received 306 bytes 862.00 bytes/sec
total size is 0 speedup is 0.00
[root@backup-server01 tmp]#

工作场景
1 两台服务器数据同步 cron+rsync