oracle rman
创建使用带catalog的rman
大致步骤
1、 设置归档模式
2、 创建rman使用的表空间,建议300m
3、 创建rman使用的用户并授权
4、 备份控制文件,
alter database backup controlfile to trace
create pfile from spfile;
alter system set log_archive_dest_1='location=/archiverman' scope=spfile;
shutdown
startup mount
alter database archivelog;
alter database open;
create tablespace tbs_rman datafile '/opt/oracle/oradata/dba/tbs_rman.dbf' size 230m;
create user rman identified by rman default tablespace tbs_rman temporary tablespace temp;
grant recovery_catalog_owner to rman;
alter user rman quota unlimited on tbs_rman;
select * from session_privs;
select * from seesion_roles;
rman catalog rman/rman@target
create catalog tablespace tbs_rman;
connect target sys/oracle@source
register database;
list backuoset; /*查看备份集
list incarnation /*查看化身
report schema; /*查看库结构
crosscheck backupset; /*查看备份的有效性,EXPIRED
delete expired backupset;/*删除过期的备份集
crosscheck copy; /*检查copy
delete expired copy; /*删除过期的copy
validate backupset; /*检验备份集是否能用。
delete expired backupset /*删除过期的备份
crosscheck copy of archivelog all;
show all;
RMAN> configure controlfile autobackup on;
rman 可以做full,增量备份,备份单独数据文件等功能。
fullbackup 1
run{
2> allocate channel d1 device type disk; format'/opt/oracle/spfile.bak';
3> backup as compressed backupset
4> format '/opt/oracle/oradata/bak/full_%d%U'
5> tag='fullbak' including current controlfile;
6> channel=d1
7> database plus archivelog delete input;
8> }
fullbackup 2
RMAN> run {
2> allocate channel d1 device type disk;
3> backup as compressed backupset
4> format '/opt/oradata/oradata/rman/full_%d%U'
5> tag='fullbak'
6> channel=d1
7> database plus archivelog delete input;
8> }
incremental level=0
RMAN> run{
2> allocate channel d1 device type disk;
3> backup as compressed backupset
4> format='/opt/oradata/oradata/inc1_%d_%U'
5> tag='inc0'
6> incremental level=0
7> database;
8> }
bakcup datafile
RMAN> run{
2> allocate channel d1 device type disk;
3> backup as compressed backupset
4> format='/opt/oradata/oradata/df_%d_%U'
5> tag='dfile'
6> channel=d1
7> datafile 1;
8> }
backup arch from scn
run{
allocate channel d1 device type disk;
backup
format='/opt/oradtata/oradata/arch_%d_%U'
tag='arch'
channel=d1
archivelog from scn 1219672 ;
}
copy database
run{
allocate channel d1 device type disk;
backup as copy
format='/opt/oradata/oradata/copy_%d_%U'
tag='copybak'
database;
}
恢复规则:
nomount状态:controlfile,all database file
mount状态:system tablespace& online redo log file
mount、open状态:non-system tbs & undo tbs
1、模拟丢失一个非system数据文件。
删除数据文件,在数据库里alter database dataifle 4 online; 在rman 里 report schema 可以看到file id
在rman里输入命令去恢复:
run{
allocate channel d1 devcie type disk;
sql "alter database datafile 4 offline"; ### 不执行这个,就会报独占错误。
restore datafile 4;
recover dataifle 4;
sql "alter database datafile 4 online";
}
2 模拟丢失undo数据文件(undo不能offline,read-only)
sqlplus :
alter database offline;
alter database online;
rman:
run{
allocate channel d1 device type disk;
restore datafile 2;
recover datafile 2;
}
sql:select * from v$datafile;
recover datafile 2;
3 模拟系统表空间丢失:
首先把数据库切换到mount状态:
sql>startup mount force;
rman>run{
allocate channel d1 device type disk;
restore datafile 1;
recover datafile 1;
sql "alter database open";
}
4 控制文件丢失:
sql:startup nomount force;
rman
run{
allocate channel d1 device type disk;
restore controlfile;
sql "alter database mount";
recover database;
sql "alter database open noresetlogs";
}
一个可以自动执行的脚本:
[oracle@rac01 ~]$ ls
database fullbak.rcv full.sh
[oracle@rac01 ~]$ more full.sh
export ORACLE_BASE=/u01
export ORACLE_HOME=/u01/app/oracle
export ORACLE_SID=rac01
rman cmdfile = /home/oracle/fullbak.rcv
[oracle@rac01 ~]$ more fullbak.rcv
connect target /
run{
allocate channel d1 device type disk;
backup as compressed backupset
format '/u01/oradata/full_%d%U'
tag='fullbak'
channel=d1
database plus archivelog delete input;
}
[oracle@rac01 ~]$
大数据量的数据库可能会碰到这样的问题:由于某些原因造成本来该早上8点之前完成的备份没有完成,结果造成正常业务造成很大影响。但是又不可能每天晚上看着本该自动执行的备份。
刚刚发现,原来rman有个duration参数可以使rman在指定时间无论完成与否都中止备份。
引用官方文档里的例子:
For example, run the following command at 2:00 a.m. to specify that the backup
should run until 6:00 a.m.:
BACKUP
DURATION 4:00
TABLESPACE users;
继续扩展 参数paptial和filesperset
BACKUP
DURATION 4:00 PARTIAL
TABLESPACE users
FILESPERSET 1;
上面的例子指定:每个文件对应备份集,并且4小时备份如果没有完成rman不会提示错误,而是提示哪个文件还没有备份,这样一来可以手动将未备份的
RMAN
精选 转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
rman异机恢复报错RMAN-06026 RMAN-06023
rman异机恢复报错RMAN-06026 RMAN-06023
oracle sed 备份文件 -
RMAN 系列(六) ---- RMAN 高级恢复
<br />这几天心情不太好,这周连续加上3天班,有点累,但是不管怎样,学习不能放下,在当下的社会,要改变自己的
数据库 disk oracle 2010 system