拷贝本地文件。当SRC和DES路径信息都不包含有单个冒号":"分隔符时就启动这种工作模式。
rsync -a /data /backup
使用一个远程shell程序(如rsh、ssh)来实现将本地机器的内容拷贝到远程机器。当DST路径地址包含单个冒号":"分隔符时启动该模式。
rsync -avz *.c foo:src
使用一个远程shell程序(如rsh、ssh)来实现将远程机器的内容拷贝到本地机器。当SRC地址路径包含单个冒号":"分隔符时启动该模式。
rsync -avz foo:src/bar /data
从远程rsync服务器中拷贝文件到本地机。当SRC路径信息包含"::"分隔符时启动该模式。
rsync -av [email protected]::www /databack
从本地机器拷贝文件到远程rsync服务器中。当DST路径信息包含"::"分隔符时启动该模式。
rsync -av /databack [email protected]::www
-v, --verbose 详细模式输出。
-q, --quiet 精简输出模式。
-c, --checksum 打开校验开关,强制对文件传输进行校验。
-a, --archive 归档模式,表示以递归方式传输文件,并保持所有文件属性,等于-rlptgoD。
-r, --recursive 对子目录以递归模式处理。
-R, --relative 使用相对路径信息。
-b, --backup 创建备份,也就是对于目的已经存在有同样的文件名时,将老的文件重新命名为~filename。可以使用
--suffix选项来指定不同的备份文件前缀。
--backup-dir 将备份文件(如~filename)存放在在目录下。
-suffix=SUFFIX 定义备份文件前缀。
-u, --update 仅仅进行更新,也就是跳过所有已经存在于DST,并且文件时间晚于要备份的文件,不覆盖更新的文件。
-l, --links 保留软链结。 -L, --copy-links 想对待常规文件一样处理软链结。
--copy-unsafe-links 仅仅拷贝指向SRC路径目录树以外的链结。
--safe-links 忽略指向SRC路径目录树以外的链结。
-H, --hard-links 保留硬链结。
-p, --perms 保持文件权限。
-o, --owner 保持文件属主信息。
-g, --group 保持文件属组信息。
-D, --devices 保持设备文件信息。
-t, --times 保持文件时间信息。
-S, --sparse 对稀疏文件进行特殊处理以节省DST的空间。
-n, --dry-run现实哪些文件将被传输。
-w, --whole-file 拷贝文件,不进行增量检测。
-x, --one-file-system 不要跨越文件系统边界。
-B, --block-size=SIZE 检验算法使用的块尺寸,默认是700字节。
-e, --rsh=command 指定使用rsh、ssh方式进行数据同步。
--rsync-path=PATH 指定远程服务器上的rsync命令所在路径信息。
-C, --cvs-exclude 使用和CVS一样的方法自动忽略文件,用来排除那些不希望传输的文件。
--existing 仅仅更新那些已经存在于DST的文件,而不备份那些新创建的文件。
--delete 删除那些DST中SRC没有的文件。
--delete-excluded 同样删除接收端那些被该选项指定排除的文件。
--delete-after 传输结束以后再删除。
--ignore-errors 及时出现IO错误也进行删除。
--max-delete=NUM 最多删除NUM个文件。
--partial 保留那些因故没有完全传输的文件,以是加快随后的再次传输。
--force 强制删除目录,即使不为空。
--numeric-ids 不将数字的用户和组id匹配为用户名和组名。
--timeout=time ip超时时间,单位为秒。
-I, --ignore-times 不跳过那些有同样的时间和长度的文件。
--size-only 当决定是否要备份文件时,仅仅察看文件大小而不考虑文件时间。
--modify-window=NUM 决定文件是否时间相同时使用的时间戳窗口,默认为0。
-T --temp-dir=DIR 在DIR中创建临时文件。
--compare-dest=DIR 同样比较DIR中的文件来决定是否需要备份。
-P 等同于 --partial。 --progress 显示备份过程。
-z, --compress 对备份的文件在传输时进行压缩处理。
--exclude=PATTERN 指定排除不需要传输的文件模式。
--include=PATTERN 指定不排除而需要传输的文件模式。
--exclude-from=FILE 排除FILE中指定模式的文件。
--include-from=FILE 不排除FILE指定模式匹配的文件。
--version 打印版本信息。
--address 绑定到特定的地址。
--config=FILE 指定其他的配置文件,不使用默认的rsyncd.conf文件。
--port=PORT 指定其他的rsync服务端口。
--blocking-io 对远程shell使用阻塞IO。
-stats 给出某些文件的传输状态。
--progress 在传输时现实传输过程。
--log-format=formAT 指定日志文件格式。
--password-file=FILE 从FILE中得到密码。
--bwlimit=KBPS 限制I/O带宽,KBytes per second。
拉复制
1 install
yum install rsync
vim /etc/rsyncd/rsyncd.conf
uid=root
gid=root
port=873
max connections=0 #limit client conection
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
motd file = /etc/rsyncd/rsyncd.motd
read only=yes 只能下载不能上传
####limit user conn######
hosts allow=192.168.18.0/255.255.255.0
hosts deny=*
#transfer logging = yes
#log format = %t %a %m %f %b
#syslog facility = local3
#timeout = 300
[www]
path = /tmp/www/
list = yes
ignore errors
auth users = www
###username
secrets file = /etc/rsyncd/rsyncd.secrets
comment = www directory
exclude = a/ b/ #####a,b directory not backup
[root@www rsyncd]# cat rsyncd.motd
#####################
www.vfast.com rsync
#####################
[root@www rsyncd]# cat rsyncd.secrets
www:123
[root@www rsyncd]# chmod 600 rsyncd.secrets
4 start
[root@www rsyncd]# rsync --daemon --config=/etc/rsyncd/rsyncd.conf
[root@www rsyncd]# lsof -i:873
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
rsync 8043 root 4u IPv6 22013 TCP *:rsync (LISTEN)
rsync 8043 root 5u IPv4 22014 TCP *:rsync (LISTEN)
5 check log
tail -f /var/log/rsyncd.log
client : 192.168.18.146
echo 123 > /etc/rsync.password
chmod 600 /etc/rsync.password
mkdir -pv /tmp/www
rsync -avzP --delete --password-file=/etc/rsync.password [email protected]::www /tmp/www
#####################
www.vfast.com rsync
#####################
receiving file list ...
3 files to consider
deleting f/
deleting d/
deleting abcd/
deleting c/3
deleting c/2
deleting c/1
./
c/
c/c1
6 100% 5.86kB/s 0:00:00 (xfer#1, to-check=0/3)
sent 129 bytes received 260 bytes 778.00 bytes/sec
total size is 6 speedup is 0.02
146#cd /tmp/www/
146#tree
.
`-- c
`-- c1
1 directory, 1 file
192.168.18.254 server
rm -fr /tmp/c/c1
146#rsync -avzP --delete --password-file=/etc/rsync.password [email protected]::www /tmp/www
#####################
www.vfast.com rsync
#####################
receiving file list ...
2 files to consider
deleting c/c1
c/
sent 101 bytes received 191 bytes 194.67 bytes/sec
total size is 0 speedup is 0.00
146#tree
.
`-- c
1 directory, 0 files
crontab -e
10 2 * * * rsync -avzP --delete --password-file=/etc/rsync.password [email protected]::www /tmp/www
推复制
server sersync2 + rsync 192.168.18.254
client rsync 192.168.18.146
apache-server
[root@www tmp]# tar fvxz sersync.tar.gz
GNU-Linux-x86/
GNU-Linux-x86/sersync2
GNU-Linux-x86/confxml.xml
[root@www tmp]# cd GNU-Linux-x86/
vim confxml.xml
<sersync>
<localpath watch="/tmp/www">
<remote ip="192.168.18.146" name="www"/>
<commonParams params="-artuz"/>
<auth start="true" users="kyo" passwordfile="/etc/146rsync.pass"/>
<failLog path="/tmp/rsync_fail_log" timeToExecute="60"/><!--default every 60mins execute once-->;
client 192.168.18.146
146#chmod 600 /etc/rsyncd/rsyncd.secrets
146#cat /etc/rsyncd/rsyncd.secrets
kyo:123
146#cat /etc/rsyncd/rsyncd.conf
uid=root
gid=root
port=873
max connections=0 #limit client conection
use chroot = no
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
motd file = /etc/rsyncd/rsyncd.motd
read only=no ###############!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
####limit user conn######
hosts allow=192.168.18.0/255.255.255.0
hosts deny=*
#transfer logging = yes
#log format = %t %a %m %f %b
#syslog facility = local3
#timeout = 300
[www]
path = /tmp/www
list = yes
ignore errors
auth users = kyo
###username!!
secrets file = /etc/rsyncd/rsyncd.secrets
comment = www directory
read only = no
146#rsync --daemon --config=/etc/rsyncd/rsyncd.conf
146#lsof -i:873
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
rsync 4356 root 4u IPv6 14561 TCP *:rsync (LISTEN)
rsync 4356 root 5u IPv4 14562 TCP *:rsync (LISTEN)
server 192.168.18.254
[root@www GNU-Linux-x86]# cat /etc/146rsync.pass
123
[root@www GNU-Linux-x86]# chmod 600 /etc/146rsync.pass
[root@www www]# ps axu | grep rsync
root 8043 0.0 0.0 5252 480 ? Ss 11:08 0:00 rsync --daemon --config=/etc/rsyncd/rsyncd.conf
root 8191 0.6 2.3 82416 24024 pts/7 S+ 11:17 0:11 gedit rsync.txt
root 8668 0.0 0.0 5024 696 pts/3 S+ 11:46 0:00 grep rsync
[root@www www]# kill -9 8043
test
[root@www GNU-Linux-x86]# pwd
/tmp/GNU-Linux-x86
# ./sersync2 -r #run first!
[root@www GNU-Linux-x86]# ./sersync2
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
use rsync password-file :
user is kyo
passwordfile is /etc/146rsync.pass
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)
Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)
please according your cpu ,use -n param to adjust the cpu rate
run the sersync:
watch path is: /tmp/www