crontab linux下oracle备份 定时任务

最近项目上线,由开发任务转向实施,程序员简直就是一万能选手,什么都能做,所以我的工作就转到了oracle和linux上来,从扫盲到新手吧!!
crontab 是linux下的一个定时任务,内置的,可以调用一些shell文件,定时执行一些任务:如:oracle数据库的定时备份,
这里就把写好的copy过来了。


------oracle自动备份文件   /nsfc/app/oransfc/work/bakdev.sh
dh=`date '+%Y%m%d%H%M%S'`
fn=${dh}'.dmp'
echo $fn
expdp system/***** schemas=agile dumpfile=$fn directory=backup parallel=4  COMPRESSION=ALL
cd /backup/oraclebak
echo 'tar#################################################'
set timeout 3000
tar -zcvf $fn'.tar.gz' $fn 
set timeout 3000
echo 'cd /u01/app/oransfc/work#################################################'
cd /nsfc/app/oransfc/work
echo 'expdpfinish='`date '+%Y%m%d%H%M%S'`
#./logindev.exp $password /backup/oraclebak/$fn
#echo 'logout'=`date '+%Y%m%d%H%M%S'`
rm /backup/oraclebak/$fn
echo 'rm='`date '+%Y%m%d%H%M%S'`


------- 日志文件              bak.log
20120914121001.dmp
tar#################################################
cd /u01/app/oransfc/work#################################################
expdpfinish=20120914121008
rm=20120914121008

-------crontab调用的文件          rootbakdev.sh
su - oransfc -c '/nsfc/app/oransfc/work/bakdev.sh > /nsfc/app/oransfc/work/bak.log'


-------添加任务
用crontab命令添加2个任务---  问一下谷歌吧
[root@localhost work]# crontab -l
10 23 * * * /nsfc/app/oransfc/work/rootbakdev.sh
10 12 * * * /nsfc/app/oransfc/work/rootbakdev.sh


测试时可以直接打文件地址和文件名:看执行效果
/nsfc/app/oransfc/work/rootbakdev.sh



遇见问题:我的shell文件一直好好的执行,有一天不知问什么就不备份了,手动执行,发现如下错误:

ORA-31634: job already exists

ORA-31664: unable to construct unique job name when defaulted


解决办法:转的
http://blog.sina.com.cn/s/blog_4ca246370100pzml.html

1、问题发现:
每天定时的数据泵导入作业未正常导入,查看import.log,居然为空。
2、问题追踪:
手工调用脚本导入,运行几秒后报错:
ORA-31634: job already exists
ORA-31664: unable to construct unique job name when defaulted
3、查找解决
1)分析错误及如何解决:
ORA-31634: job already exists
Cause: Job creation or restart failed because a job having the selected name is currently executing. This also generally indicates that a Master Table with that job name exists in the user schema. Refer to any following error messages for clarification.
Action: Select a different job name, or stop the currently executing job and re-try the operation (may require a DROP on the Master Table).
ORA-31664: unable to construct unique job name when defaulted
Cause: The job name was defaulted, and the name creation algorithm was unable to find a unique job name for this schema where the table name (for the master table) didn"t already exist.
Action: Specify a job name to use or delete some of the existing tables causing the name conflicts.
经分析是expdp运行时调用job的唯一名不存在,查询dba_datapump_jobs,正常情况下job_name字段只有SYS_IMPORT_SCHEMA_01和SYS_IMPORT_SCHEMA_02两行,而此表有70行,解决方法删除表中字段state是NOT RUNNING状态的表。
2)解决
生成清除master table的SQL语句为:
select 'drop table ' || owner_name || '.' || job_name || ';'
from dba_datapump_jobs
where state = 'NOT RUNNING'
手工执行生成的SQL语句后,再次查询dba_datapump_jobs确认是否有state是NOT RUNNING的master table,重复生成SQL语句执行即可。
再次手工调用导入脚本,正常导入。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值