1. 程式人生 > >huangliang0703的專欄

huangliang0703的專欄

背景:生產環境是RAC (11.2.0.1) ,要搭建一個單例項的測試環境

實現方法:對生產環境做一個rman備份,然後在測試環境進行不完整恢復

一、rman 備份,備份指令碼如下:

[[email protected] ~]$ more  /home/oracle/scripts/zszjk_full.sh
#!/bin/sh
source /home/oracle/.bash_profilezjk
CUSER=`id |cut -d"(" -f2 | cut -d ")" -f1`
DT=`date +"%Y%m%d_%H%M%S"`
RMAN_LOG_FILE=/home/oracle/bak_dir/zszjk_full.out
echo >> $RMAN_LOG_FILE
chmod 666 $RMAN_LOG_FILE
echo Script $0 >> $RMAN_LOG_FILE
echo ==== started on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
rman target / nocatalog msglog $RMAN_LOG_FILE append << EOF
RUN {
#sql 'alter system archive log current';
allocate channel ch00 TYPE disk;
allocate channel ch01 TYPE disk;
allocate channel ch02 TYPE disk;
allocate channel ch03 TYPE disk;
allocate channel ch04 TYPE disk;
allocate channel ch05 TYPE disk;
#send 'NB_ORA_POLICY=Ora_DB_ecdb02_Full';
backup INCREMENTAL LEVEL 0  filesperset = 5 as compressed backupset database format '/home/oracle/bak_dir/full_
%d_%T_%U.rman';
#sql 'alter system archive log current';
backup  filesperset = 15 as compressed backupset archivelog all format '/home/oracle/bak_dir/arch_%d_%T_%U.rman
' delete input force;
DELETE noprompt OBSOLETE;
crosscheck backup;
delete noprompt expired backup;
release channel ch00;
release channel ch01;
release channel ch02;
release channel ch03;
release channel ch04;
release channel ch05;
#sql 'alter system archive log current';
ALLOCATE CHANNEL ch00 TYPE disk;
copy current controlfile to '/home/oracle/bak_dir/control.full_%d_%T.rman';
backup spfile format '/home/oracle/bak_dir/spfile_%d_%T';
release channel ch00;
}
EOF

二、在備庫進行恢復

1、恢復引數檔案、控制檔案(使用備份的控制檔案進行恢復)

2、restore 資料檔案,這裡需要對資料檔案路勁進行轉換  

run{
allocate channel ch00 TYPE disk;
allocate channel ch01 TYPE disk;
allocate channel ch02 TYPE disk;
allocate channel ch03 TYPE disk;
allocate channel ch04 TYPE disk;
allocate channel ch05 TYPE disk;
set newname for datafile '+DATA1/zjk/system01.dbf'     to   '/home/oracle/app/oradata/zszjk/system01.dbf'    ;
set newname for datafile '+DATA1/zjk/sysaux01.dbf'     to   '/home/oracle/app/oradata/zszjk/sysaux01.dbf'    ;
set newname for datafile '+DATA1/zjk/undotbs01.dbf'    to   '/home/oracle/app/oradata/zszjk/undotbs01.dbf'   ;
set newname for datafile '+DATA1/zjk/users01.dbf'      to   '/home/oracle/app/oradata/zszjk/users01.dbf'     ;
set newname for datafile '+DATA1/zjk/system02.dbf'     to   '/home/oracle/app/oradata/zszjk/system02.dbf'    ;
set newname for datafile '+DATA1/zjk/users02.dbf'      to   '/home/oracle/app/oradata/zszjk/users02.dbf'     ;
set newname for datafile '+DATA1/zjk/users03.dbf'      to   '/home/oracle/app/oradata/zszjk/users03.dbf'     ;
set newname for datafile '+DATA1/zjk/users04.dbf'      to   '/home/oracle/app/oradata/zszjk/users04.dbf'     ;
set newname for datafile '+DATA1/zjk/users05.dbf'      to   '/home/oracle/app/oradata/zszjk/users05.dbf'     ;
set newname for datafile '+DATA1/zjk/users16.dbf'      to   '/home/oracle/app/oradata/zszjk/users16.dbf'     ;
set newname for datafile '+DATA1/zjk/system06.dbf'     to   '/home/oracle/app/oradata/zszjk/system06.dbf'    ;
set newname for datafile '+DATA1/zjk/undotbs2.dbf'     to   '/home/oracle/app/oradata/zszjk/undotbs2.dbf'    ;
restore database;
switch datafile all;
release channel ch00;
release channel ch01;
release channel ch02;
release channel ch03;
release channel ch04;
release channel ch05;
}

recover database,最後有錯誤提示,找不到 sequence 為112565   的歸檔日誌,那我就指定應用完sequence 為112564的歸檔日誌截止。

RMAN> recover database;

Starting recover at 09-NOV-18
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=2 sequence=29
channel ORA_DISK_1: reading from backup piece /home/oracle/bak_dir/arch_ZSZJK_20181107_aithkfb8_1_1.rman
channel ORA_DISK_1: piece handle=/home/oracle/bak_dir/arch_ZSZJK_20181107_aithkfb8_1_1.rman tag=TAG20181107T133640
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=112564
channel ORA_DISK_1: reading from backup piece /home/oracle/bak_dir/arch_ZSZJK_20181107_ajthkfb8_1_1.rman
channel ORA_DISK_1: piece handle=/home/oracle/bak_dir/arch_ZSZJK_20181107_ajthkfb8_1_1.rman tag=TAG20181107T133640
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
archived log file name=/oracle/database/11.2/db_1/dbs/arch1_112564_919583396.dbf thread=1 sequence=112564
archived log file name=/oracle/database/11.2/db_1/dbs/arch2_29_919583396.dbf thread=2 sequence=29
unable to find archived log
archived log thread=1 sequence=112565
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 11/09/2018 10:34:07
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 112565 and starting SCN of 862714094743
RMAN> recover database until sequence 112565;

Starting recover at 09-NOV-18
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 09-NOV-18

3、resetlogs 開啟資料庫報錯,檢視告警日誌,怎麼還是從asm 裡面去讀資料檔案,網上查資料,需要重建控制檔案 


SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-03113: end-of-file on communication channel
Process ID: 15386
Session ID: 66 Serial number: 7
Errors in file /home/oracle/app/diag/rdbms/zszjkst/zszjk/trace/zszjk_ora_15150.trc:
ORA-19625: error identifying file +DATA1/zjk/system01.dbf
ORA-17503: ksfdopn:2 Failed to open file +DATA1/zjk/system01.dbf
ORA-15001: diskgroup "DATA1" does not exist or is not mounted
ORA-15077: could not locate ASM instance serving a required diskgroup
ORA-29701: unable to connect to Cluster Synchronization Service
Switch of datafile 1 complete to datafile copy 

4、重建控制檔案

alter database backup controlfile to trace as '/home/oracle/control_new.trc';

CREATE CONTROLFILE REUSE DATABASE "ZSZJK" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 40
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 74752
LOGFILE
  GROUP 4 '/home/oracle/app/oradata/zszjk/redo04.log'  SIZE 500M BLOCKSIZE 512,
  GROUP 5 '/home/oracle/app/oradata/zszjk/redo05.log'  SIZE 500M BLOCKSIZE 512,
  GROUP 6 '/home/oracle/app/oradata/zszjk/redo06.log'  SIZE 500M BLOCKSIZE 512
-- STANDBY LOGFILE
--   GROUP 8 '/home/oracle/app/oradata/zszjk/redo8'  SIZE 1024M BLOCKSIZE 512,
--   GROUP 9 '/home/oracle/app/oradata/zszjk/redo9'  SIZE 1024M BLOCKSIZE 512,
--   GROUP 10 '/home/oracle/app/oradata/zszjk/redo10'  SIZE 1024M BLOCKSIZE 512,
--   GROUP 11 '/home/oracle/app/oradata/zszjk/redo11'  SIZE 1024M BLOCKSIZE 512
DATAFILE
  '/home/oracle/app/oradata/zszjk/system01.dbf',
  '/home/oracle/app/oradata/zszjk/sysaux01.dbf',
  '/home/oracle/app/oradata/zszjk/undotbs01.dbf',
  '/home/oracle/app/oradata/zszjk/users01.dbf',
  '/home/oracle/app/oradata/zszjk/system02.dbf',
  '/home/oracle/app/oradata/zszjk/users02.dbf',
  '/home/oracle/app/oradata/zszjk/users03.dbf',
  '/home/oracle/app/oradata/zszjk/users04.dbf',
  '/home/oracle/app/oradata/zszjk/users05.dbf',
  '/home/oracle/app/oradata/zszjk/users16.dbf',
  '/home/oracle/app/oradata/zszjk/system06.dbf',
  '/home/oracle/app/oradata/zszjk/undotbs2.dbf'
CHARACTER SET AL32UTF8
;

再次開啟資料庫,成功了

SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-38856: cannot mark instance UNNAMED_INSTANCE_2 (redo thread 2) as enabled