oracle10g里用DBMS_SCHEDULER替代linux下的crontab
2009-02-24 11:00
比如完成周日0级全备、周三1级备份、其它星期为2级备份,每天都是4:30开始执行,crontab里是如下设置:
$ crontab -l 30 4 * * 0 /orahome/backup/rman_level.sh 0 30 4 * * 3 /orahome/backup/rman_level.sh 1 30 4 * * 1,2,4,5,6 /orahome/backup/rman_level.sh 2 现在可以在oracle里通过dbms_scheduler包来设置,完成以上功能的调度设置如下: SQL> conn /as sysdba SQL> BEGIN DBMS_SCHEDULER.drop_job (job_name => 'rman_level0'); END; / SQL> BEGIN DBMS_SCHEDULER.drop_job (job_name => 'rman_level1'); END; / SQL> BEGIN DBMS_SCHEDULER.drop_job (job_name => 'rman_level2'); END; / SQL> BEGIN DBMS_SCHEDULER.create_job ( job_name => 'rman_level0', job_type => 'EXECUTABLE', job_action => '/orahome/backup/rman_level.sh', number_of_arguments => 1, repeat_interval => 'freq=daily; BYDAY=SUN; byhour=4; byminute=30', enabled => FALSE, auto_drop => FALSE, comments => 'rman incremental level 0 backup database' ); DBMS_SCHEDULER.set_job_argument_value ('rman_level0', 1, '0'); DBMS_SCHEDULER.enable ('rman_level0'); END; / SQL> BEGIN DBMS_SCHEDULER.create_job ( job_name => 'rman_level1', job_type => 'EXECUTABLE', job_action => '/orahome/backup/rman_level.sh', number_of_arguments => 1, repeat_interval => 'freq=daily; BYDAY=WED; byhour=4; byminute=30', enabled => FALSE, auto_drop => FALSE, comments => 'rman incremental level 1 backup database' ); DBMS_SCHEDULER.set_job_argument_value ('rman_level1', 1, '1'); DBMS_SCHEDULER.enable ('rman_level1'); END; / SQL> BEGIN DBMS_SCHEDULER.create_job ( job_name => 'rman_level2', job_type => 'EXECUTABLE', job_action => '/orahome/backup/rman_level.sh', number_of_arguments => 1, repeat_interval => 'freq=daily; BYDAY=MON,TUE,THU,FRI,SAT; byhour=4; byminute=30', enabled => FALSE, auto_drop => FALSE, comments => 'rman incremental level 2 backup database' ); DBMS_SCHEDULER.set_job_argument_value ('rman_level2', 1, '2'); DBMS_SCHEDULER.enable ('rman_level2'); END; / 使用dbms_sheduler包来设置定时任务的主要优势,除了安全原因外(也就是不想让能登陆linux的用户能看到数据库的备份策略),还有就是可以通过查看表dba_scheduler_job_run_details获得每次调度的详细信息: SQL> SELECT log_date, status, req_start_date, actual_start_date, run_duration, additional_info FROM dba_scheduler_job_run_details WHERE job_name LIKE 'RMAN%' ORDER BY 1 DESC; |
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-558233/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9240380/viewspace-558233/