9 在/home/NACEC/BackupDatabase/下创建backuplevel0.rcv和backuplevel1.rcv脚本
backuplevel0.rcv内容:
# script.:bakuplevel0.rcv
# creater:liu shiming
# date:2010/6/28
# desc:backup level0 database datafile in archive with rman
# connect database
#!/bin/bash
export ORACLE_BASE=/home/DBSoftware/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_SID=NACEC
export PATH=/home/DBSoftware/oracle/product/10.2.0/db_1/bin:$PATH
rman target / << EOF_RMAN
run{
allocate channel c1 type disk;
backup incremental level 0 tag 'db0' format '/home/liusm/BackupDatabase/rmanbackup/db0_%d_%T_%s' database include current controlfile;
sql'alter system archive log current';
backup filesperset 3 format '/home/liusm/BackupDatabase/rmanbackup/arch0_%d_%T_%s' archivelog all delete input;
release channel c1;
}
# end
backuplevel1.rcv内容:
# script.:bakuplevel1.rcv
# creater:liu shiming
# date:2010/6/27
# desc:backup level1 database datafile in archive with rman
# connect database
#!/bin/bash
export ORACLE_BASE=/home/DBSoftware/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_SID=NACEC
export PATH=/home/DBSoftware/oracle/product/10.2.0/db_1/bin:$PATH
rman target/ << EOF_RMAN
run{
allocate channel c1 type disk;
backup incremental level 1 tag 'db1' format '/home/liusm/BackupDatabase/rmanbackup/db1_%d_%T_%s' database include current controlfile;
sql'alter system archive log current';
backup filesperset 3 format '/home/liusm/BackupDatabase/rmanbackup/arch1_%d_%T_%s' archivelog all delete input;
release channel c1;
}
# end
给这两个脚本授予执行的权限:
[oracle@NACEC BackupDatabase]$ chmod +x *.rcv
(注意:要试运行脚本:./backuplevel1.rcv)
11 用crontab指定执行时间
[oracle@NACEC BackupDatabase]$ crontab -e
crontab: installing new crontab
[oracle@NACEC BackupDatabase]$ crontab -l
0 1 * * 0 /home/NACEC/BackupDatabase/backuplevel0.rcv
0 1 * * 3 /home/NACEC/BackupDatabase/backuplevel0.rcv
0 1 * * 1-2 /home/NACEC/BackupDatabase/backuplevel1.rcv
0 1 * * 4-6 /home/NACEC/BackupDatabase/backuplevel1.rcv
周日和周三凌晨1:00执行0级备份,周一、二、四、五、六凌晨1:00执行1级备份
内容:
0 1 * * 0 /home/NACEC/BackupDatabase/backuplevel0.rcv
0 1 * * 3 /home/NACEC/BackupDatabase/backuplevel0.rcv
0 1 * * 1-2 /home/NACEC/BackupDatabase/backuplevel1.rcv
0 1 * * 4-6 /home/NACEC/BackupDatabase/backuplevel1.rcv
或者建立基于数据库的自动备份,使用JOB完成
begin
dbms_scheduler.create_job(
job_name=>'nacec_job0',
job_type=>'executable',
job_action=>'/home/NACEC/BackupDatabase/backuplevel0.sh',
repeat_interval=>'freq=weekly;byday=SUN,WED;byhour=01;byminute=00');
end;
/
exec dbms_scheduler.enable('nacec_job0');
begin
dbms_scheduler.create_job(
job_name=>'nacec_job1',
job_type=>'executable',
job_action=>'/home/NACEC/BackupDatabase/backuplevel1.sh',
repeat_interval=>'freq=weekly;byday=MON,TUS,THE,FRI,SAT;byhour=01;byminute=00');
end;
/
exec dbms_scheduler.enable('nacec_job1');
![](http://img.blog.itpub.net/blog/attachment/201704/19/31448824_14925646782YcS.png?x-oss-process=style/bb)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31448824/viewspace-2137525/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31448824/viewspace-2137525/