注意: rsync命令使用中, 若是源参数的末尾有斜线, 只会复制指定目录的内容, 而不复制目录自己, 没有斜线, 则会复制目录自己, 包括目录.
Examples:
rsync -r /mydata/data /bachups
#会把目录data直接同步至/bakups目录中
rsync -r /mydata/data/ /backups
#会把目录data/中的内容至/backups目录中html
马哥linux视频linux
王晓冬/Rsync 12种故障排查及思路(http://www.javashuo.com/article/p-ufmoxbew-kk.html)vim
John_ABC/Linux-Rsync服务器/客户端搭建实战(http://www.javashuo.com/article/p-ksdjfxpj-kk.html)bash
SHIHUC/rsync配置中的auth error,一个隐秘的错误(http://www.javashuo.com/article/p-mqhcqkqj-kh.html)服务器
rysnc -- a fast, versatile, remote and local file-copying toolssh
前提: SRC和DEST端必须都安装rsynctcp
yum install rsync -y
ide
其余选项:测试
# Options: -q, --quiet # suppress non-error messages -c, --checksum -e ssh # use ssh protocl to transfer -a, --archive # archive mode; equals -rlptgoD -z, --compress --stats # give some file-transfer stats --progress # show progress during transfer --password-file=FILE
Please dry run first for testui
rsync -nv SRC... DEST # Options: -n, --dry-run # perform a trail run with no changes mode -v, --verbose
rsync -avz --progress SRC... DEST
# Pull rsync -avz -e ssh --progress USER@HOST:SRC... DEST # Push rsync -avz -e ssh --progress SRC... USER@HOST:DEST
Port: 873/tcp
注意: 关闭该死的seinux !!!
安装超级守护进程xinetd
yum install xinetd -y
为rsync提供配置文件
man 5 rsyncd.conf
# 查看rsyncd.conf配置里每一个属性含义
以及查看EXAMPLES部分了解基础配置例子
vim /etc/rsyncd.conf
定义一个全局配置和多个rsync共享配置
# Global Settings
uid = nobody
gid = nobody
use chroot = no # 是否禁锢用户家目录
max connections = 10 # 最大链接数, 10已经很是大
strict modes = yes # 是否彻底检查
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
# Directory to be synced
[SYNCED_NAME] # 模块名映射成下面path
path = /PATH/TO/SOME_DIR
ignore errors = yes
read only = yes
# This parameter determines whether clients will be able to upload files or not. If “read only” is true then any attempted uploads will fail. If “read only” is false then uploads will be possible if file permissions on the daemon side allow them. The default is for all modules to be read only.
write only = no
# This parameter determines whether clients will be able to download files or not. If “write only” is true then any attempted downloads will fail. If “write only” is false then downloads will be possible if file permissions on the daemon side allow them. The default is for this parameter to be disabled.
hosts allow = 192.168.0.0/24
hosts deny = *
list = false
# This parameter determines if this module should be listed when the client asks for a listing of available modules. By setting this to false you can create hidden modules. The default is for modules to be listable.
uid = USERNAME # 表示以哪一个用户身份去获取文件, 最好不要用root
gid = GROUPNAME # 表示以哪一个属组身份去获取文件, 最好不要用root
auth users = USERNAME # 容许的用户
secrets file = /etc/rsyncd.passwd # 用户密码的存放位置
配置密码文件/etc/rsyncd.passwd
vim /etc/rsyncd.passwd
USERNAME:PASSWORD
chmod 600 /etc/rsyncd.passwd
配置服务可以启动
chkconfig rsync on
chkconfig xinetd on
service xinetd restart
# Pull rsync -avz --progress USER@HOST::SRC... DEST rsync -avz --progress rsync://USER@HOST/SRC... DEST #SRC: rsyncd.conf里指定的共享模块名, 即配置文件里[SYNCED_NAME] # Push rsync -avz --progress SRC... USER@HOST::DEST rsync -avz --progress SRC... rsync://USER@HOST/DEST #DEST: rsyncd.conf里指定的共享模块名, 即配置文件里[SYNCED_NAME]
配置密码文件
vim /etc/rsyncd.passwd
PASSWORD
chmod 600 /etc/rsyncd.passwd
指定密码文件rsync传输文件
# E.G. pull rsync -avz --progress \ --password-file=/etc/rsyncd.passwd \ zak@192.168.0.117::mydata/test /tmp
😄 Oh Yeah!