Oracle12c RAC RMAN异机恢复

zhangchaoming 2019-12-24

########################################################

#编辑pfile文件initspdb.ora

vi /oracle/app/oracle/product/12.2.0/db_1/dbs/initspdb.ora

audit_file_dest=‘/oracle/app/oracle/admin/spdb/adump‘
audit_trail=‘db‘
compatible=‘12.2.0‘
control_files=‘/oracle/app/oracle/oradata/spdb/control.ctl‘
db_block_size=8192
db_name=‘spdb‘
diagnostic_dest=‘/oracle/app/oracle‘
dispatchers=‘(PROTOCOL=TCP) (SERVICE=spdbXDB)‘
enable_pluggable_database=true
log_archive_dest_1=‘LOCATION=/orabak/archivelog‘
open_cursors=300
pga_aggregate_target=5120m
processes=400
remote_login_passwordfile=‘exclusive‘
sga_target=10240m
undo_tablespace=‘UNDOTBS1‘
db_file_name_convert=‘+DATADG/SPDB/DATAFILE‘,‘/oracle/app/oracle/oradata/spdb/‘,‘+DATADG/SPDB/8E80F930196B6100E053E200A8C0AF9F/DATAFILE‘,‘/oracle/app/oracle/oradata/spdb/pdbseed/‘,‘+DATADG/SPDB/8E81C7A967C43CB7E053E300A8C06223/DATAFILE‘,‘/oracle/app/oracle/oradata/spdb/spdb1pdb/‘,‘+DATADG/SPDB/93BFEF75138BC79EE053E300A8C08BA1/DATAFILE‘,‘/oracle/app/oracle/oradata/spdb/kdlxpdb

#创建目录

mkdir -p /oracle/app/oracle/admin/spdb/adump

mkdir -p /orabak/archivelog

########################################################

#创建spfile

SQL> create spfile from pfile=‘/oracle/app/oracle/product/12.2.0/db_1/dbs/initspdb.ora‘

#进到nomount状态

SQL> startup nomount

--#恢复spfile文件

--RMAN> restore spfile from ‘/orabak/spfile_ORCL_1026474723_1096_1‘;

SQL> shutdown abort

cd /oracle/app/oracle/product/12.2.0/db_1/dbs/

rm initspdb.ora

$strings spfilespdb.ora

SQL> startup nomount

########################################################

#恢复control文件

RMAN> restore controlfile from ‘/orabak/control_ORCL_1026474721_1095_1‘;

#进到mount状态

SQL> alter database mount;

#删除backup

RMAN> list backup;

RMAN> crosscheck backup;

RMAN> delete backup;

RMAN> list backup;

########################################################

#恢复dbfile全备文件

RMAN> catalog start with ‘/orabak/backup/‘;

RMAN> list backup;

rman target /
run{
allocate channel ch1 type disk;
allocate channel ch2 type disk;
set newname for datafile 1 to ‘/oracle/app/oracle/oradata/spdb/system.dbf‘;
set newname for datafile 3 to ‘/oracle/app/oracle/oradata/spdb/sysaux.dbf‘;
set newname for datafile 5 to ‘/oracle/app/oracle/oradata/spdb/undotbs1.dbf‘;
set newname for datafile 7 to ‘/oracle/app/oracle/oradata/spdb/undotbs2.dbf‘;
set newname for datafile 8 to ‘/oracle/app/oracle/oradata/spdb/users.dbf‘;
set newname for datafile 2 to ‘/oracle/app/oracle/oradata/spdb/pdbseed/system.dbf‘;
set newname for datafile 4 to ‘/oracle/app/oracle/oradata/spdb/pdbseed/sysaux.dbf‘;
set newname for datafile 6 to ‘/oracle/app/oracle/oradata/spdb/pdbseed/undotbs1.dbf‘;
set newname for datafile 9 to ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/system.dbf‘;
set newname for datafile 10 to ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/sysaux.dbf‘;
set newname for datafile 11 to ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/undotbs1.dbf‘;
set newname for datafile 12 to ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/undo_2.dbf‘;
set newname for datafile 13 to ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/users.dbf‘;
set newname for datafile 14 to ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/spdata1.dbf‘;
set newname for datafile 15 to ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/spdata2.dbf‘;
set newname for datafile 16 to ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/managedata1.dbf‘;
set newname for datafile 18 to ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/managedata2.dbf‘;
set newname for datafile 17 to ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/clouddata1.dbf‘;
set newname for datafile 19 to ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/clouddata2.dbf‘;
set newname for datafile 20 to ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/cloudtestdata1.dbf‘;
set newname for datafile 21 to ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/cloudtestdata2.dbf‘;
set newname for datafile 28 to ‘/oracle/app/oracle/oradata/spdb/kdlxpdb/system.dbf‘;
set newname for datafile 29 to ‘/oracle/app/oracle/oradata/spdb/kdlxpdb/sysaux.dbf‘;
set newname for datafile 30 to ‘/oracle/app/oracle/oradata/spdb/kdlxpdb/undotbs1.dbf‘;
restore database;
switch datafile all;
switch tempfile all;
release channel ch1;
release channel ch2;
}

RMAN> recover database;

Oracle12c RAC RMAN异机恢复

#recover报错,需要指定SCN

RMAN> recover database until scn 233086903;      #全量备份的SCN

Oracle12c RAC RMAN异机恢复

#将归档日志及增量备份数据文件拷贝至/orabak/backup/目录并追加

RMAN> catalog start with ‘/orabak/backup/‘;

RMAN> list backup;

#找到对应增量备份节点的SCN进行恢复,建议根据备份策略依次恢复(优先读取增量文件其次归档日志)。

RMAN> recover database until scn 234809384;      #归档日志恢复第一天增量

Oracle12c RAC RMAN异机恢复

RMAN> recover database until scn 237672420;    #增量文件及归档日志恢复第二天增量

Oracle12c RAC RMAN异机恢复

Oracle12c RAC RMAN异机恢复

#第二天增量恢复完成,接着恢复第三天增量报错。备份期间生成过数据文件,可通过恢复单独数据文件恢复,因隔天忘记恢复第三天增量数据。

RMAN> recover database until scn 241710899;      #第三天增量恢复

Oracle12c RAC RMAN异机恢复

RMAN> restore datafile 31; 

########################################################

#数据库open

SQL> alter database open;

Oracle12c RAC RMAN异机恢复

SQL> alter database open resetlogs;

Oracle12c RAC RMAN异机恢复

#ASM磁盘和集群报错,需要调整控制文件

SQL> alter database backup controlfile to trace as ‘/home/oracle/ctl.control‘;

SQL> shutdown abort;

vi /home/oracle/ctl.control

STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "SPDB" RESETLOGS ARCHIVELOG
    MAXLOGFILES 192
    MAXLOGMEMBERS 3
    MAXDATAFILES 1024
    MAXINSTANCES 32
    MAXLOGHISTORY 584
LOGFILE
  GROUP 1 ‘/oracle/app/oracle/oradata/spdb/redo1.log‘  SIZE 200M BLOCKSIZE 512,
  GROUP 2 ‘/oracle/app/oracle/oradata/spdb/redo2.log‘  SIZE 200M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  ‘/oracle/app/oracle/oradata/spdb/system.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/pdbseed/system.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/sysaux.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/pdbseed/sysaux.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/undotbs1.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/pdbseed/undotbs1.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/undotbs2.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/users.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/system.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/sysaux.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/undotbs1.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/undo_2.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/users.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/spdata1.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/spdata2.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/managedata1.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/clouddata1.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/managedata2.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/clouddata2.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/cloudtestdata1.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/spdb1pdb/cloudtestdata2.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/kdlxpdb/system.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/kdlxpdb/sysaux.dbf‘,
  ‘/oracle/app/oracle/oradata/spdb/kdlxpdb/undotbs1.dbf‘
CHARACTER SET AL32UTF8
;
--RECOVER DATABASE

--All logs need archiving and a log switch is needed.
--ALTER SYSTEM ARCHIVE LOG ALL;-- Database can now be opened normally.
--ALTER DATABASE OPEN;

-- Open all the PDBs.
--ALTER PLUGGABLE DATABASE ALL OPEN;

#编辑控制文件,重新生成控制文件

SQL> @/home/oracle/ctl.control

Oracle12c RAC RMAN异机恢复

SQL> alter database open RESETLOGS;

Oracle12c RAC RMAN异机恢复

#生成thread 2 redo日志文件

SQL> ALTER DATABASE ADD LOGFILE THREAD 2 GROUP 3 ‘/oracle/app/oracle/oradata/spdb/redo03.log‘ SIZE 50M,GROUP 4 ‘/oracle/app/oracle/oradata/spdb/redo04.log‘ SIZE 50M;

SQL> alter database open RESETLOGS;

Oracle12c RAC RMAN异机恢复

SQL> alter database open;

SQL> alter pluggable database all open;

Oracle12c RAC RMAN异机恢复

至此RAC的RMAN异机恢复就完成了。恢复过程中遇到问题就针对解决吧,Good Luck!!!

########################################################

注常用命令:

RMAN> list backup;

RMAN> crosscheck backupset;

RMAN> delete backupset;

RMAN> delete backup;

RMAN> restore database;

RMAN> restore datafile 31; 

RMAN> recover database until SCN XXX;

RMAN> list archivelog all;

RMAN> list copy;

RMAN> catalog start with ‘/orabak/backup‘;

相关推荐