最近在做一套同步环境,用的是数据泵,由于数据泵只能在服务器端实施,所以需要把dmp文件ftp到相应的impdp的服务器上,那么我需要考虑一个问题,impdp的服务器是定时执行任务的,但是假如这个是expdp的dmp文件还没有ftp过来,或者中途断了,那么impdp服务器端就不应该进行同步。所以对ftp之后touch一个checkfile.log,如果判断可以找到checkfile.log就进行impdp的工作。
写脚本时候,写了2中方案,发现第一个方案有bug,测试工作如下:
1. 方案一(错误)
#FTP dmp file
ftp -i -n 172.16.191.130 < user oracle password
bin
prompt off
cd /sync02
put test.dmp
bye
FTPFILE
# IMP check file
touch /sync01/checkfile.log
ftp -i -n 172.16.191.130 < user oracle password
bin
prompt off
cd /sync02
put checkfile.log
bye
FTPFILE
定时任务开始后,确认进程存在
oracle@test1[/sync01]$ ps -ef|grep test.sh
oracle 14549 1864 0 11:54:00 ? 0:00 sh -c /sync01/test.sh
oracle 14555 7641 0 11:54:00 pts/1 0:00 grep test.sh
oracle 14552 14549 3 11:54:00 ? 0:00 /usr/bin/sh /sync01/test.sh
oracle@test1[/sync01]$ ps -ef|grep ftp
oracle 14553 14552 10 11:54:00 ? 0:00 ftp -i -n 172.16.191.130
oracle 14582 7641 0 11:54:05 pts/1 0:00 grep ftp
此时kill掉ftp 的进程,模拟网络终端
oracle@test1[/sync01]$ kill -9 14553
oracle@test1[/sync01]$ ps -ef|grep ftp
oracle 14682 7641 0 11:54:21 pts/1 0:00 grep ftp
oracle@test1[/sync01]$ ps -ef|grep test.sh
oracle 14694 7641 1 11:54:23 pts/1 0:00 grep test.sh
检查impdp端是否有checkfile.log文件
-rw-r--r-- 1 oracle oinstall 656518200 Jul 14 11:54 test.dmp
-rw-r--r-- 1 oracle oinstall 0 Jul 14 11:54 checkfile.log
发现checkfile.log还是被ftp到imdp端了,说明上面的方案不可行,kill只是中断了第一个ftp的任务,crontab会进入第二个ftp的任务继续执行,所以更改脚本,把2个文件放入同一个ftp的包中,这样的话要么一起终端,要么一起传输。
正确方案:
touch /sync01/checkfile.log
#FTP dmp file
ftp -i -n 172.16.191.130 < user oracle password
bin
prompt off
cd /sync02
mput test.dmp checkfile.log
bye
FTPFILE
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9252210/viewspace-668008/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9252210/viewspace-668008/