- 配置基于时间的备份保留策略
RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
- 恢复spfile
RMAN> restore spfile from '/bk/xxxxxx'; 如果在Oracle10g里这里就是控制文件,因为在备份控制文件的时候会自动备份参数文件,但是在oracl11g里我做的时候控制文件找不到 所以要从另外一个文件里找到的参数文件恢复出来的;这一步成功在之后你的$ORACLE_HONE/dbs/下已经有了二进制参数文件和控制文件了,但是这个参数文件是生产库的参数文件跟你的服务器上所对应的目录不一定一样,所以你要修改参数文件。
- 开始恢复control file,进而得到备份集的信息:
RMAN> restore controlfile from '/u02/20190324_HIS_25210_1.ctl';
- 列出备份集:
RMAN> list backup of database;
- 删除过期的备份介质.
RMAN> delete obsolete(nopormt指定无需确认立即删除)
- RMAN的备份记录中依然存在,清除这些信息。
RMAN> crosscheck backup;
- 删除过期的备份信息。
RMAN> delete expired backup;
- 指定还原的路径:
catalog start with '/backup/his/';
- 指定还原的文件名:
alter database mount;
set newname for datafile 1 to "/ora/u01/data/users.dbf";
set newname for datafile 2 to "/ora/u01/data/undotbs1.dbf";
set newname for datafile 3 to "/ora/u01/data/sysaux01.dbf";
set newname for datafile 4 to "/ora/u01/data/system01.dbf";
set newname for datafile 5 to "/ora/u01/data/undotbs2.dbf";
set newname for datafile 6 to "/ora/u01/data/hisdata.dbf";
- 数据文件不同路径的还原:
run{
set newname for database to '/ora/u00/oracle/oradata/his/%b';
restore database;
switch datafile all;
recover database;
alter database open;
}
- 不完全恢复
set until time "to_date('07/01/2015 15:00:00', 'mm/dd/yyyy hh24:mi:ss')";
restore database;
recover database;
alter database open;
}
RMAN> recover database until cancel;
恢复数据到某个序列号
RMAN> recover database until sequence 46101 thread 1;
查看日志文件
[oracle@histest ~]$ cd $ORACLE_BASE
[oracle@histest oracle]$ cd diag/rdbms/
his/ histest/ unknown/
[oracle@histest oracle]$ cd diag/rdbms/his/
HIS/ i_1.mif
[oracle@histest oracle]$ cd diag/rdbms/his/HIS/trace/
[oracle@histest trace]$ tail -200f alert_HIS.log
===========================以下为后台还原数据库===============================
数据库还原脚本:
rman target / <<EOF
run{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
set newname for database to '/ora/u00/oracle/oradata/his/%b';
restore database;
RECOVER database;
sql 'alter database open resetlogs';
sql 'alter database open';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
EOF
~
添加权限
[root@histest oracle]# chown oracle:oinstall rman.sh
[root@histest oracle]# chmod 775 rman.sh
查看数据库状态为mount
[root@histest ~]# su - oracle
[oracle@histest ~]$ su - oracle
Password:
[oracle@histest ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Apr 11 16:04:53 2019
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
HIS MOUNTED
开启后台执行脚本
[root@histest ~]# su - oracle
[oracle@histest ~]$ /home/oracle/rman.sh >> /home/oracle/out.log 2>&1 &
踩坑一例:
在做RMAN还原时,总提示找不到某个日志文件,致使还原不成功。
最后经过分析,原来是RAC集群里日志保留的时间过短,数据库太大,在做RMAN全备份时,当全备份做完,日志文件已部分被清,导致备份集里的备份的日志文件在做RMAN还原时找不到日志文件。
解决办法:由于库太大,做一次还原时间太长,选择根据SCN号做一次增备和控制文件备份,再进行还原的最省时间策略。