常用的备份命令可以保存到本地文件上,当我们需要的时候可以直接调用。也可以保存到catalog中。下面我们看看怎样在catalog中创建和使用脚本。
1,创建一个零级别全备份
create script b_whole_inc0 {
allocate channel c1 type disk;
allocate channel c2 type disk;
backup incremental level=0 cumulative
database
format '/backup/db0_%d_%s_%p_%t'
tag='whole_inc0';
release channel c1;
release channel c2;
}
2,创建一个1级增量备份
create script b_whole_inc1 {
allocate channel c1 type disk;
allocate channel c2 type disk;
backup incremental level=1 cumulative
database
format '/backup/db1_%d_%s_%p_%t'
tag='whole_inc1';
release channel c1;
release channel c2;
}
3,归档当前的联机重做日志
create script archive_log_current{
sql "alter system archive log current";
}
4,备份最近两天内的归档日志
create script b_archive_2days{
allocate channel c1 type disk;
execute script archive_log_current;
backup archivelog
from time 'SYSDATE-2'
format '/backup/ar_%d_%s_%p_%t';
release channel c1;
}
5,备份最近两天内的归档日志,删除两天前已经备份过的归档
create script archive_delete3{
allocate channel c1 type disk;
execute script archive_log_current;
backup archivelog
from time 'SYSDATE-3' until time 'SYSDATE-2'
delete input;
release channel c1;
}
在SQLPLUS下查看脚本catalog保存的脚本,可以从rman中通过host切换
RMAN>host;
sqlplus \nolog
connect rmanadmin/rmanadmin@rcat
col SCRIPT_NAME for a20
col SCRIPT_COMMENT for a20
select * from rc_stored_script;
DB_KEY DB_NAME SCRIPT_NAME SCRIPT_COMMENT
---------- -------- -------------------- --------------------
1 PRACTICE b_whole_inc0
1 PRACTICE b_whole_inc1
1 PRACTICE archive_log_current
1 PRACTICE b_archive_2days
1 PRACTICE archive_delete3
exit
exit;
重新回到rman提示符下
查看script脚本
RMAN> print script archive_log_current;
printing stored script: archive_log_current
{sql "alter system archive log current";
}
执行并删除存储脚本
run{
execute script b_whole_inc0;
execute script b_whole_inc1;
execute script b_archive_2days;
1,创建一个零级别全备份
create script b_whole_inc0 {
allocate channel c1 type disk;
allocate channel c2 type disk;
backup incremental level=0 cumulative
database
format '/backup/db0_%d_%s_%p_%t'
tag='whole_inc0';
release channel c1;
release channel c2;
}
2,创建一个1级增量备份
create script b_whole_inc1 {
allocate channel c1 type disk;
allocate channel c2 type disk;
backup incremental level=1 cumulative
database
format '/backup/db1_%d_%s_%p_%t'
tag='whole_inc1';
release channel c1;
release channel c2;
}
3,归档当前的联机重做日志
create script archive_log_current{
sql "alter system archive log current";
}
4,备份最近两天内的归档日志
create script b_archive_2days{
allocate channel c1 type disk;
execute script archive_log_current;
backup archivelog
from time 'SYSDATE-2'
format '/backup/ar_%d_%s_%p_%t';
release channel c1;
}
5,备份最近两天内的归档日志,删除两天前已经备份过的归档
create script archive_delete3{
allocate channel c1 type disk;
execute script archive_log_current;
backup archivelog
from time 'SYSDATE-3' until time 'SYSDATE-2'
delete input;
release channel c1;
}
在SQLPLUS下查看脚本catalog保存的脚本,可以从rman中通过host切换
RMAN>host;
sqlplus \nolog
connect rmanadmin/rmanadmin@rcat
col SCRIPT_NAME for a20
col SCRIPT_COMMENT for a20
select * from rc_stored_script;
DB_KEY DB_NAME SCRIPT_NAME SCRIPT_COMMENT
---------- -------- -------------------- --------------------
1 PRACTICE b_whole_inc0
1 PRACTICE b_whole_inc1
1 PRACTICE archive_log_current
1 PRACTICE b_archive_2days
1 PRACTICE archive_delete3
exit
exit;
重新回到rman提示符下
查看script脚本
RMAN> print script archive_log_current;
printing stored script: archive_log_current
{sql "alter system archive log current";
}
执行并删除存储脚本
run{
execute script b_whole_inc0;
execute script b_whole_inc1;
execute script b_archive_2days;