一、需要备份的服务器设置
apt-get install rsync
1、修改/etc/default/rsync
RSYNC_ENABLE=true
2、创建/etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = no
max connections = 4
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
gid = nobody
use chroot = no
max connections = 4
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[xkq]
path = /data/
read only = no
list = no
uid = root
gid = root
hosts allow = 192.168.1.2 #允许同步机器的IP
hosts deny = 0.0.0.0/32
auth users = root
secrets file = /etc/rsyncd.pass
path = /data/
read only = no
list = no
uid = root
gid = root
hosts allow = 192.168.1.2 #允许同步机器的IP
hosts deny = 0.0.0.0/32
auth users = root
secrets file = /etc/rsyncd.pass
[mysqlxkq]
path = /backup/mysqlbackup/
read only = no
list = no
uid = root
gid = root
hosts allow = 192.168.1.2
path = /backup/mysqlbackup/
read only = no
list = no
uid = root
gid = root
hosts allow = 192.168.1.2
auth users = root
secrets file = /etc/rsyncd.pass
secrets file = /etc/rsyncd.pass
[day]
path = /backup/data/day/file/
read only = no
list = no
uid = root
gid = root
hosts allow = 192.168.1.2
auth users = root
secrets file = /etc/rsyncd.pass
path = /backup/data/day/file/
read only = no
list = no
uid = root
gid = root
hosts allow = 192.168.1.2
auth users = root
secrets file = /etc/rsyncd.pass
3、创建/etc/rsyncd.pass
root:root用户密码
4、重启rsync
/etc/init.d/rsync
rsync --daemon
二、保存备份的服务器
apt-get install rsync
1、编辑存放密码的文件,写入需要备份的服务器中/etc/rsyncd.pass的密码部分
2、同步命令
rsync -vzrtopg --delete --progress root@192.168.1.1::xkq /data/ --password-file=/etc/rsync
d.pass
FAQ
Q:出现如此错误:rsync: failed to set times . "/." (in test): Operation not permitted (1)
rsync: failed to set times . "/." (in test): Operation not permitted (1)
rsync error: some files could not be transferred (code 23) at main.c(892) [sender=2.6.8]
A:那是因为rsync服务端的要 同步的目录的权限设置不对,应该要设置你启动rsync用户的权限
d.pass
运行参数解释:
-u
更新数据
-h , --help
显示
rsync
求助资讯
--version 顯示 rsync 版本
-v , --verbose 复杂的输出信息
-q , --quiet 安静模式,几乎没有讯息产生, 常用在以 cron 执行 rsync
-I, --ignore-times 通常 rsync 为了加快速度会忽略同样档案大小且同样 , 同样存取时间点的档案
可以通过此参数开关此快速检查 .
--size-only rsync 只检查档案大小是否改变 , 不管时间存取点是否改变
通常用在 mirror, 且对方时间不太正确时
-c, --checksum 在传送之前透过 128bit 的 md4 检查码来检查所有要传送的档案 ( 会托满速度 );
-a, --archive archive mode 权限保存模式 , 相当于 -rlptgoD 参数 .
很快速的保存几乎所有的权限设定 , 除了硬式连接 ( 透过 -H 设定 ).
-r, --recursive 复制所有下面的资料 ( 透过 )
-R, --relative 使用相对路径
如 : rsync foo/bar/foo.c remote:/tmp/ 在远端产生 /tmp/foo.c 档案
rsync -R foo/bar/foo.c remote:/tmp/ 在远端产生 /tmp/foo/bar/foo.c 档案
-R, --relative 不使用相对路径
-b, --backup 目的地端先前已经存在的档案在传输或删除前会被备份
--backup-dir=DIR 设定备份的资料夹
--suffix=SUFFIX 指定备份的档案名称字尾形式 ( 预设为 ~)
-K, --keep-dirlinks 接收方将连接到资料夹的档案视为资料夹处理
-l, --links 复制所有的连接
-H, --hard-links 保留硬式连结
-p, --perms 保留档案权限
-o, --owner 保留档案所有者 (root .ly)
-g, --group 保留档案群组
-D, --devices 保留 device 资讯 (root .ly)
-t, --times 保留时间点
-n, --dry-run 不实际执行传送 , 只显示将会有的传输动作
-S, --sparse 尝试去处理稀疏的档案 , 让这些档案在目的端占去较少的磁碟空间
-W, --whole-file 复制所有的档案 , 不额外作检查
--no-whole-file 关闭 --whole-file 参数
-x, --one-file-system 不要跨越档案系统分界 ( 只在一个档案系统处理 )
-B, --block-size=SIZE 强制透过 rsync 程式去比对修复 block-sizeforce
-e --rsh=COMMAND 定义所试用的 remote shell
--rsync-path=PATH 定义 rsync 在远端机器存放资料的路径
--existing 只对比更新目的端已经存在的档案
--ignore-existing 忽略目的断已经存在的档案 ( 也就是不更新 )
--delete 删除传送断已经不存在 , 而目的端存在的档案
--delete-excluded 除了把传送端已经不存在 , 而目的端存在的档案删除之外 , 也删除 --exclude 参数所包含的档案
--delete-after rsync 预设会在档案传送前进行相关删除动作确保接收端有足够的档案空间 ,
单可以透过 --delete-after 让删除动作在档案传送后在进行删除
--ignore-errors 忽略任何错误即使是 I/O error 也进行 --delete 删除动作
--max-delete=NUM 定义 rsync 不要删除超过 NUM 个档案
--partial rsync 若遇到传输过程中断时 , 会把那些已经传输的档案删除 .
在某种状况下保留那些部分传送的档案是令人高兴的 ;
你可以透过 --partial 参数达到这个目的 .
--partial-dir=DIR 在 --partial 参数启动时 , 你还是可以定义 rsync 把那些部分传送的档案
写入定义的资料夹 , 而非直接写入目的端 , 需要注意的是 ,
此资料夹不应该被其他试用者可以写入 .( 如 :/tmp)
--force 当目的端资料夹被传送端非资料夹名称覆盖时 , 强制 rsync 删除资料夹 , 即使该资料夹不是空的 .
--numeric-ids 不将传送端档案的 uid 及 gid 值 , 与目的端的使用者 / 群组进行配对 ,
若传送端并没有 uid 及 gid 的对应名称 ( 如 : 原帐号群组被删除的遗留档案 ),
或目的端没有相对应的帐号 / 群组 , 保留数字型式的 uid/gid
--timeout=TIMEOUT 设定 I/O 超时的时间 ( 秒 ). 超过这个秒数而没有资料传送 , rsync 将会结束 . 预设为 0, 也就是没有定义超时时间
-T, --temp-dir=DIR 定义 rsync 在接收端产生暂时性的复制档案时使用资料夹暂存, 预设时直接在接收端资料夹直接产生暂存档案
--compare-dest=DIR 定义 rsync 在目的端建立资料夹来比对传送过来的档案 .
--link-dest=DIR 与 --compare-dest 相同 , 但同时会针对无法改变的档案建立硬式连结 .
-z, --compress 压缩模式 , 当资料在传送到目的端进行档案压缩 .
-P -P 参数和 --partial --progress 相同 . 只是为了把参数简单化 .
-C, --cvs-exclude 排除那些通常不希望传送的档案 , 定义的方式与 CVS 传送相同 :
RCS SCCS CVS CVS.adm RCSLOG cvslog.* tags TAGS .make.state
.nse_depinfo *~ #* .#* ,* _$* *$ *.old *.bak *.BAK *.orig *.rej
.del-* *.a *.olb *.o *.obj *.so *.exe *.Z *.elc *.ln core .svn/
符合以上条件的都会被忽略不传送 .
--exclude=PATTER 符合 PATTERN( 规则表示式 ) 样式的档案不仅行传送
--exclude-from=FILE 和 --exclude 参数相同 , 不过是把不进行传送的档案事先写入某一档案 .
执行时 , 透过此参数让 rsync 读取 .
(; # 开头的行列或者空白会被 rsync 忽略 )
--include=PATTERN 定义 rsync 不要排除符合 pattern 样式的档案
--include-from=FILE 和 --include 参数相同 , 只不过把要包含的档案写到某一档案 .
--files-from=FILE 把要传送的档案名称都精确的写入某一档案 , 让 rsync 读取 .
如 : rsync -a --files-from=/tmp/foo /usr remote:/backup
-0 --from0 定义档案所要读取的档案时 null 字元结尾 .
--version 现四版本信息 .
--daemon 定义 rsync 以 daemon 型态执行
--no-detach 当以 daemon 形态执行时 , 不要进行分裂且变成背景程序 .
--address=ADDRESS 定义所要连接 (bind) 的 ip 位置或者是 host 名称 (daemon 限定 )
--config=FILE 定义所要读取的设定档 rsyncd.conf 位置 (daemon 限定 )
预设值为 /usr/local/etc/rsyncd.conf
--port=PORT 定义 rsyncd(daemon) 要旨行的 port( 预设为 tcp 873)
--blocking-io 使用 blocking I/O 连结远端的 shell, 如 rsh, remsh
--no-blocking-io 使用 non-blocking 连结远端的 shell, 如 ssh( 预设值 )
--stats 显示档案传送时的资讯状态
--progress 显示传送的进度 .( 给档案传送时 , 怕无聊的人用的 ..)
--log-format=FORMAT 定义 log 的格式 ( 在 rsyncd.conf 设定 )
--password-file=FILE 从档案读取与远端 rsync 伺服务连结的密码
--bwlimit=KBPS 定义传输频宽的大小 (KBytes/ 秒 )
--write-batch=FILE 把记录资料写入一个档案 ( 给其他相同环境且相同需求的机器试用 )
--read-batch=FILE 透过读取记录档案来进行传输 .( 档案由 --write-batch 参数产生 )
--checksum-seed=NUM 定义档案 checksum-seed 的大小 (byte)
-4 --ipv4 使用 IPv4 协定
-6 --ipv6 使用 IPv6 协定
--version 顯示 rsync 版本
-v , --verbose 复杂的输出信息
-q , --quiet 安静模式,几乎没有讯息产生, 常用在以 cron 执行 rsync
-I, --ignore-times 通常 rsync 为了加快速度会忽略同样档案大小且同样 , 同样存取时间点的档案
可以通过此参数开关此快速检查 .
--size-only rsync 只检查档案大小是否改变 , 不管时间存取点是否改变
通常用在 mirror, 且对方时间不太正确时
-c, --checksum 在传送之前透过 128bit 的 md4 检查码来检查所有要传送的档案 ( 会托满速度 );
-a, --archive archive mode 权限保存模式 , 相当于 -rlptgoD 参数 .
很快速的保存几乎所有的权限设定 , 除了硬式连接 ( 透过 -H 设定 ).
-r, --recursive 复制所有下面的资料 ( 透过 )
-R, --relative 使用相对路径
如 : rsync foo/bar/foo.c remote:/tmp/ 在远端产生 /tmp/foo.c 档案
rsync -R foo/bar/foo.c remote:/tmp/ 在远端产生 /tmp/foo/bar/foo.c 档案
-R, --relative 不使用相对路径
-b, --backup 目的地端先前已经存在的档案在传输或删除前会被备份
--backup-dir=DIR 设定备份的资料夹
--suffix=SUFFIX 指定备份的档案名称字尾形式 ( 预设为 ~)
-K, --keep-dirlinks 接收方将连接到资料夹的档案视为资料夹处理
-l, --links 复制所有的连接
-H, --hard-links 保留硬式连结
-p, --perms 保留档案权限
-o, --owner 保留档案所有者 (root .ly)
-g, --group 保留档案群组
-D, --devices 保留 device 资讯 (root .ly)
-t, --times 保留时间点
-n, --dry-run 不实际执行传送 , 只显示将会有的传输动作
-S, --sparse 尝试去处理稀疏的档案 , 让这些档案在目的端占去较少的磁碟空间
-W, --whole-file 复制所有的档案 , 不额外作检查
--no-whole-file 关闭 --whole-file 参数
-x, --one-file-system 不要跨越档案系统分界 ( 只在一个档案系统处理 )
-B, --block-size=SIZE 强制透过 rsync 程式去比对修复 block-sizeforce
-e --rsh=COMMAND 定义所试用的 remote shell
--rsync-path=PATH 定义 rsync 在远端机器存放资料的路径
--existing 只对比更新目的端已经存在的档案
--ignore-existing 忽略目的断已经存在的档案 ( 也就是不更新 )
--delete 删除传送断已经不存在 , 而目的端存在的档案
--delete-excluded 除了把传送端已经不存在 , 而目的端存在的档案删除之外 , 也删除 --exclude 参数所包含的档案
--delete-after rsync 预设会在档案传送前进行相关删除动作确保接收端有足够的档案空间 ,
单可以透过 --delete-after 让删除动作在档案传送后在进行删除
--ignore-errors 忽略任何错误即使是 I/O error 也进行 --delete 删除动作
--max-delete=NUM 定义 rsync 不要删除超过 NUM 个档案
--partial rsync 若遇到传输过程中断时 , 会把那些已经传输的档案删除 .
在某种状况下保留那些部分传送的档案是令人高兴的 ;
你可以透过 --partial 参数达到这个目的 .
--partial-dir=DIR 在 --partial 参数启动时 , 你还是可以定义 rsync 把那些部分传送的档案
写入定义的资料夹 , 而非直接写入目的端 , 需要注意的是 ,
此资料夹不应该被其他试用者可以写入 .( 如 :/tmp)
--force 当目的端资料夹被传送端非资料夹名称覆盖时 , 强制 rsync 删除资料夹 , 即使该资料夹不是空的 .
--numeric-ids 不将传送端档案的 uid 及 gid 值 , 与目的端的使用者 / 群组进行配对 ,
若传送端并没有 uid 及 gid 的对应名称 ( 如 : 原帐号群组被删除的遗留档案 ),
或目的端没有相对应的帐号 / 群组 , 保留数字型式的 uid/gid
--timeout=TIMEOUT 设定 I/O 超时的时间 ( 秒 ). 超过这个秒数而没有资料传送 , rsync 将会结束 . 预设为 0, 也就是没有定义超时时间
-T, --temp-dir=DIR 定义 rsync 在接收端产生暂时性的复制档案时使用资料夹暂存, 预设时直接在接收端资料夹直接产生暂存档案
--compare-dest=DIR 定义 rsync 在目的端建立资料夹来比对传送过来的档案 .
--link-dest=DIR 与 --compare-dest 相同 , 但同时会针对无法改变的档案建立硬式连结 .
-z, --compress 压缩模式 , 当资料在传送到目的端进行档案压缩 .
-P -P 参数和 --partial --progress 相同 . 只是为了把参数简单化 .
-C, --cvs-exclude 排除那些通常不希望传送的档案 , 定义的方式与 CVS 传送相同 :
RCS SCCS CVS CVS.adm RCSLOG cvslog.* tags TAGS .make.state
.nse_depinfo *~ #* .#* ,* _$* *$ *.old *.bak *.BAK *.orig *.rej
.del-* *.a *.olb *.o *.obj *.so *.exe *.Z *.elc *.ln core .svn/
符合以上条件的都会被忽略不传送 .
--exclude=PATTER 符合 PATTERN( 规则表示式 ) 样式的档案不仅行传送
--exclude-from=FILE 和 --exclude 参数相同 , 不过是把不进行传送的档案事先写入某一档案 .
执行时 , 透过此参数让 rsync 读取 .
(; # 开头的行列或者空白会被 rsync 忽略 )
--include=PATTERN 定义 rsync 不要排除符合 pattern 样式的档案
--include-from=FILE 和 --include 参数相同 , 只不过把要包含的档案写到某一档案 .
--files-from=FILE 把要传送的档案名称都精确的写入某一档案 , 让 rsync 读取 .
如 : rsync -a --files-from=/tmp/foo /usr remote:/backup
-0 --from0 定义档案所要读取的档案时 null 字元结尾 .
--version 现四版本信息 .
--daemon 定义 rsync 以 daemon 型态执行
--no-detach 当以 daemon 形态执行时 , 不要进行分裂且变成背景程序 .
--address=ADDRESS 定义所要连接 (bind) 的 ip 位置或者是 host 名称 (daemon 限定 )
--config=FILE 定义所要读取的设定档 rsyncd.conf 位置 (daemon 限定 )
预设值为 /usr/local/etc/rsyncd.conf
--port=PORT 定义 rsyncd(daemon) 要旨行的 port( 预设为 tcp 873)
--blocking-io 使用 blocking I/O 连结远端的 shell, 如 rsh, remsh
--no-blocking-io 使用 non-blocking 连结远端的 shell, 如 ssh( 预设值 )
--stats 显示档案传送时的资讯状态
--progress 显示传送的进度 .( 给档案传送时 , 怕无聊的人用的 ..)
--log-format=FORMAT 定义 log 的格式 ( 在 rsyncd.conf 设定 )
--password-file=FILE 从档案读取与远端 rsync 伺服务连结的密码
--bwlimit=KBPS 定义传输频宽的大小 (KBytes/ 秒 )
--write-batch=FILE 把记录资料写入一个档案 ( 给其他相同环境且相同需求的机器试用 )
--read-batch=FILE 透过读取记录档案来进行传输 .( 档案由 --write-batch 参数产生 )
--checksum-seed=NUM 定义档案 checksum-seed 的大小 (byte)
-4 --ipv4 使用 IPv4 协定
-6 --ipv6 使用 IPv6 协定
--password-file=/etc/swd/rsync.secrets
指定同步用户的用户名密码,这个文件的权限必须要是
600
p_w_picpaths@192.168.88.11::p_w_picpaths
用户名
@rsync
服务器::模块名
FAQ
Q:出现如此错误:rsync: failed to set times . "/." (in test): Operation not permitted (1)
rsync: failed to set times . "/." (in test): Operation not permitted (1)
rsync error: some files could not be transferred (code 23) at main.c(892) [sender=2.6.8]
A:那是因为rsync服务端的要 同步的目录的权限设置不对,应该要设置你启动rsync用户的权限
转载于:https://blog.51cto.com/21wmd/207522