RMAN备份

10G R2 backup plan rman catalog & linux


Connect.rcv(该文件只有两句话)

connect catalog rmanuser/rman@digoal;
connect target sys/oracle@clonedb;

catalog的通用脚本

rman cmdfile=/rmanbak/script/connect.rcv(在rman中使用外部脚本)
rman catalog rmanuser/rman@digoal target sys/oracle@clonedb


删除不必要的备份

replace global script global_del{

allocate channel d1 device type disk;
delete obsolete recovery window of 15 days;
release channel d1;
}

list global script names;(查看RMAN所有的全局脚本)

RMAN>print global script global_bkctl;(查看global_bkctl中的内容)

{allocate channel d1 device type disk;
backup as compressed backupset
format='/rmanbak/backupctl.ctl'
tag='bkctl'
channel=d1
current controlfile reuse;
release channel d1;
}

replace global script global_arch comment "backup archivelog as well as delete it" {
 allocate channel d1 device type disk;
 sql "alter database archive log current"; 备份我们当前的联机日志
 set limit channel d1 readrate=10240(10M);
 set limit channel d1 kbytes=4096000;(备份片的大小)
 backup as compressed backupset
 format='/rmanbak/arch_%d_%U'
 tag='bkarch'
 channel=d1
 archivelog all delete input;
 release channel d1;
}

通过脚本建立完毕

list global script names; (列出所有的脚本)

删除脚本
delete globals script: global_inc0;

replace global script global_inc0 comment "backup database as incrmental level 0"{
execute global script global_del;
allocate channel d1 deviece type disk;
set limit channel d1 readrate=10240;
set limit channel d1 kbytes=4096000;
backup as compressed backupset
incrmental level=0
format='/rmanbak/inc0_%d_%U'
tag='inc0'
channel=d1
database ;
release channel d1;
execute global script global_arch;
execute global script global_bkctl;
}

replace global script global_inc1 comment "backup database as incrmental level 1"{
execute global script global_del;
allocate channel d1 deviece type disk;
set limit channel d1 readrate=10240;
set limit channel d1 kbytes=4096000;
backup as compressed backupset
incrmental level=1
format='/rmanbak/inc1_%d_%U'
tag='inc1'
channel=d1
database ;
release channel d1;
execute global script global_arch;
execute global script global_bkctl;
}

replace global script global_inc2 comment "backup database as incrmental level 2"{
execute global script global_del;
allocate channel d1 deviece type disk;
set limit channel d1 readrate=10240;
set limit channel d1 kbytes=4096000;
backup as compressed backupset
incrmental level=2
format='/rmanbak/inc2_%d_%U'
tag='inc1'
channel=d1
database ;
release channel d1;
execute global script global_arch;
execute global script global_bkctl;
}

在rman中检验在rman中写的脚本global_inc0、global_inc1、global_inc2,因为RMAN不会自动检查,下面的语句用来执行脚本(检验)

RMAN> run{
  execute global script global_inc0;
  execute global script global_inc1;
  execute global script global_inc2;
}

list backupset summary;(查看一下备份是否完成)


建立shell脚本,让linux自动执行脚本

1. vi inc0.rcv,inc1.rcv ,inc2.rcv

 @@(rman下的脚本去调用其他脚本用@@符号)/rmanbak/script/connect.rcv(调用脚本不需要分号)
 run{
 execute global script gloal_inc0;
}
exit;

 

2. vi inc0.sh
nohup(在后台执行,&)  $ORACLE_HOME/bin/rman  cmdfile=/rmanbak/script/inc0.rcv log=/rmanbak/script/inc0.log append
&

inc1.sh

nohup(在后台执行,&)  $ORACLE_HOME/bin/rman  cmdfile=/rmanbak/script/inc1.rcv log=/rmanbak/script/inc0.log append
&

inc2.sh
nohup(在后台执行,&)  $ORACLE_HOME/bin/rman  cmdfile=/rmanbak/script/inc2.rcv log=/rmanbak/script/inc0.log append
&

 

Crontal -e 建立一个备份计划

#min    hour    date  mon  day(星期)    command
0         1      *     *    0           /rmanbak/script/inc0.sh
0         1      *     *    1           /rmanbak/script/inc2.sh
0         1      *     *    2           /rmanbak/script/inc2.sh
0         1      *     *    3           /rmanbak/script/inc2.sh
0         1      *     *    4           /rmanbak/script/inc1.sh
0         1      *     *    5           /rmanbak/script/inc2.sh
0         1      *     *    6           /rmanbak/script/inc2.sh


Chmod u+x*.sh 给shell脚本加权限

试一下脚本有没有用:  例如./inc0.sh

德哥的经验分享:

1.backup controlfile in each scripts tail (在脚本的尾部备份控制文件)

2.Delete obsolete backupset in each scripts threshold (删除旧的备份)

3.Switch logfile before backup database; (在数据库备份以前切换日志,备份联机重做日志)

4.Chmod u+x*.sh

你可能感兴趣的:(oracle,sql,linux,脚本)