rsync实现同步(下)

3   Server B 上面设置自动获取 Server A 上的文件
a)          为了方便管理,把脚本文件放置在 Server B 上的特定目录下,下面的命令建立目录 /data/rsync
mkdir /data/rsync
b)         建立不同步文件的列表清单,清单文件名自己定义,该文件可选,如果不建立该文件,可以直接在后面步骤 C) 的脚本命令中使用参 --exclude 来直接指明。
vi /data/rsync/grpdomain1_exclude_file.list
文件每行表示一条,支持通配符,以发布项作为当前目录,文件内容如下:
grpdomain1.log*    # 表示 /data/bea/user_projects/grpdomain1/grpdomain1.log* 不同步
newgrplog             # 表示 /data/bea/user_projects/grpdomain1/newgrp 目录及子目录
home/logs
applications/cenep/WEB-INF/log
文件在本文所附的目录中可以找到,名称: ServerB\grpdomain1_exclude_file.list
c)         建立同步脚本,可以根据需要建立多个脚本,每个脚本定义自己的调度计划(见后)
vi /data/rsync/rsync-grpdomain1.sh                    # 编辑文件
chmod 700 /data/rsync/rsync-grpdomain1.sh              # 设置文件为仅属主可读些执行
文件内容如下,注意不要换行:
/usr/local/bin/rsync �Cztruvoglp --exclude-from=/data/rsync/grpdomain1_exclude_file.list --delete --progress rsync:// 10.1.4 .10/grpdomain1 /data/bea/user_projects/grpdomain1
参数说明:
l          --ztruvoglp ,表示的是压缩传输、包含子目录、保持相同的权限等,可不理会。
l          --exclude-from ,指明从那个文件读取除外文件清单
l          --delete ,指明当文件被从 Server A 上删除后,也在 Server B 上删除
l          --progress ,是否在控制台上显示明细,如果在定时任务中运行,最好不增加该参数。
l          --exclude ,在命令行上直接指明那些文件不同步,格式 --exclude=” hgFF
l          rsync:// 10.1.4 .10:873/grpdomain1 同布的源, 873 是缺省端口,可忽略
l          /data/bea/user_projects/grpdomain1 同步目的地
d)         文件在本文所附的目录中可以找到,名称: ServerB\rsync-grpdomain1.sh
e)          检测脚本是否正确,直接执行命令: /data/rsync/rsync-grpdomain1.sh
f)          设定每天 0 点执行同步命令,执行下面的命令
crontab -e                           # 编辑当前用户的调度表
显示的是一个 vi 界面,文件的内容可能如下,其中黑体部分是我们添加的:
#ident  "@(#)root       1.20    01/11/06 SMI"
#
# The root crontab should be used to perform accounting data collection.
#
# The rtc command is run to adjust the real time clock if and when
# daylight savings time changes.
#
10 3 * * * /usr/sbin/logadm
15 3 * * 0 /usr/lib/fs/nfs/nfsfind
1 2 * * * [ -x /usr/sbin/rtc ] && /usr/sbin/rtc -c > /dev/null 2>&1
30 3 * * * [ -x /usr/lib/gss/gsscred_clean ] && /usr/lib/gss/gsscred_clean
# 每天的晚上 24 点运行同步脚本 , 10 上的 grpdomain1 文件拷贝到本机
0 0 * * * /data/rsync/rsync-grpdomain1.sh
#10 3 * * * /usr/lib/krb5/kprop_script ___slave_kdcs___
起作用的是 0 0 * * * /data/rsync/rsync-grpdomain1.sh 其中前面由空格间隔开的五项分别代表分钟 小时 星期
g)         定时服务的启动和停止:
/etc/init.d/cron stop                      # 停止定时服务
/etc/init.d/cron start                            # 启动定时服务
 
4   更多的文件目录的同步之 ServerA 的操作
a)          修改 ServerA /etc/rsyncd.conf ,增加新的描述,参见 [grpdomain1] 的描述
b)         停止 Server A 上的 rsync 守候进程,命令:
ps �Cef|grep rsync                  # 显示 rsync 进程
kill 888                               #888 要根据实际的进程号替换
c)         重新启动守候进程,执行:
/usr/local/bin/rsync �Cdaemon
5   更多的文件目录的同步之 ServerB 的操作,参见步骤 3

你可能感兴趣的:(linux,职场,rsync,休闲)