Run
{
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
----将备份保留7天,过期则自动删除
Allocate channel c1 type disk;--分配磁盘通道,如果压力不大可以多分配,分配的通道越多,对硬盘的I/0压力越大,
Allcoalte channel c2 type disk;
Backup database filesperset 4 format ‘/oracle/full_%d_%T_%s_%p’;
---filesperset备份集文件,多分配通道,备份集少的话可以快速回复
Sql ‘alter system archive log current’;
Backup archivelog all format ‘/oracle/arch_%d_%T_%s_%p’ delete input; --把当前备份好的归档删除
Backup current controlfile format ‘/oracle/ctl_%d_%T_%s_%p’;
delete archivelog until time "sysdate - 7";--删除7天前的归档日志
}
EOF
可以将该脚本编辑成.sh文件,可以直接在linux下执行。
1.2.3备份脚本-归档
Export ORACLE_SID=zytk35
Export ORACLE_HOME=/ora/app/oracle/product/11.2./dbhome_1
Export PATH=$ORACLE_HOME/binPATH
Rman target / log /tmp/rman_arch.log append<<EOF
Run
{
Allocate channel c1 type disk;
Allocate channel c2 type disk;
Sql ‘alter system archive log current’;
Backup archivelog all format ‘/oracle/arch_%d_%T_%s_%p’; delete input;
Backup current controlfile formt ‘/oracle/ctl_%d_%T_%s_%p’;
}
EOF
脚本:
Export ORACLE_SID=zytk35
Export ORACLE_HOME=/ora/app/oracle/product/11.2.0/db_home
Export PATH=$ORACLE_HOME/binPATH
Rman target /log /tmp/rman_delete.log append <<EOF
Run
{
Allocate channel for maintenance type disk;--指磁盘通道
Allocate channel for maintenance type sbt_tape;--磁带通道
Crosscheck archivelog all;--校验归档日志
Crosschenk backup; --备份归档日志
Delete noprompt obsolete;--删除冗余
EOF
}
删除备份脚本总结:
rman的删除语句如下:
run {
delete noprompt obsolete;
crosscheck backup;
delete noprompt expired backup;
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog all completed before 'SYSDATE - 7';
}
1.2.5备份方案
全库备份脚本
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup full tag 'dbfull' format '/u01/oradata/backup/full%u_%s_%p' database
include current controlfile;
sql 'alter system archive log current';
backup fileaperset 3 format '/u01/oradata/backup/arch%u_%s_%p'
archivelog all delete input; #备份归档可选,可以单独定期备份
release channel c1;
release channel c2;
release channel c3;
}
零级备份脚本
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup incremental level 0 tag 'db0' format '/u01/oradata/backup/db0%u_%s_%p'
database skip readonly;
sql 'alter system archive log current';
backup fileaperset 3 format '/u01/oradata/backup/arch%u_%s_%p'
archivelog all delete input; #备份归档可选,可以单独定期备份
release channel c1;
release channel c2;
release channel c3;
}
一级备份脚本
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
backup incremental level 1 tag 'db1' format '/u01/oradata/backup/db1%u_%s_%p'
database skip readonly;
sql 'alter system archive log current';
backup fileaperset 3 format '/u01/oradata/backup/arch%u_%s_%p'
archivelog all delete input; #备份归档可选,可以单独定期备份
release channel c1;
release channel c2;
release channel c3;
}
1.星期天晚上 -level 0 backup performed(全备份)
2.星期一晚上 -level 2 backup performed
3.星期二晚上 -level 2 backup performed
4.星期三晚上 -level 1 backup performed
5.星期四晚上 -level 2 backup performed
6.星期五晚上 -level 2 backup performed
7.星期六晚上 -level 2 backup performed
Rman target / log /tmp/rman_control.log append <EOF
Run
{
Allocate channel c1 type disk;
Restore controlfile ‘/oracle/control_backup_set’;--指定到控制文件可以查看输出归档日志
EOF
}
2.2自动控制文件备份没有打开--(备份到磁带上)
Rman target / log /tmp/rman_control.log append <EOF
Run
{
Allocate channel c1 type sbt_tape;
Restore controlfile from ‘ctl_.......’;指定路径下的控制文件
EOF
}
2.3 自动控制文件备份打开(默认位置)从磁盘恢复
Rman target /
Rman>configure controlfile autobackup on;
Rman>conigure controlfile autobackup format for device type disk to ‘%F’;
数据库恢复:
Rman target /nocatalog
Rman>
Run
{
Allcoate channel c1 type disk;
Restore controlfile from auto backup;
}
2.4 自动控制文件备份打开(非默认位置)从磁盘恢复
Rman target /
Rman>configure controlfile autobackup on;
Rman>conigure controlfile autobackup format for device type disk to ‘/oracle/%F’;
数据库恢复:
Rman target /nocatalog
Rman>
Run
{
conigure controlfile autobackup format for device type disk to ‘/oracle/%F’;
Restore controlfile from auto backup;