oracle
RMANを使って全損からの復旧。
RMANで取得したバックアップがあるとして
*本来ならバックアップの定義(何を取ったか)に応じて下記も違うのだろうけど..
障害は、オラクルを停止して、oradataフォルダの削除、REDOログファイルの場所の削除、制御ファイルの削除、初期化ファイルの削除を行って状態を作る
1. RMANを起動させる†
| [oracle@o ~]$ rman target sys/manager@AERS nocatalog
Recovery Manager: Release 11.2.0.1.0 - Production on Sun Oct 6 21:42:14 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database (not started)
RMAN>
|
注意 $ORACLE_HOME/dbs/orapw<SID> のファイルによる認証がないとRMANプロンプトまで辿り着けない。っで、全損であれば、当然このファイルも存在してなく、RMANによるバックアップにこれが含まれるわけでもない。この場合は、このファイルを作り直すことになる。
orapw<SID>を再作成するには、下記コマンドで作る
[oracle@o ~]$ orapwd file=/opt/oracle/product/11.2/dbhome_1/dbs/orapwAERS password=hogehoge
こうすると
| [oracle@o ~]$ rman target sys/hogehoge@AERS nocatalog
|
でRMANに入れる。
2. 初期化ファイルを復活†
オラクルの稼働パラメータらを記述したファイルを取り戻す
| RMAN> startup nomount
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/opt/oracle/product/11.2/dbhome_1/dbs/initAERS.ora'
starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started
Total System Global Area 158662656 bytes
Fixed Size 2211448 bytes
Variable Size 88080776 bytes
Database Buffers 62914560 bytes
Redo Buffers 5455872 bytes
RMAN>
|
初期化ファイルSPFILEもPFILEもないので当然startupは無理なのだが、nomountオプションを付けて起動させる。
この状態で下記コマンドでバックアップされたファイルから、初期化ファイルを取り戻す。
| RMAN> restore spfile from '/o2/backup/c-2982693672-20131006-00';
Starting restore at 06-OCT-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=17 device type=DISK
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /o2/backup/c-2982693672-20131006-00
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 06-OCT-13
RMAN>
|
これでSPFILEは取り戻せた。要ファイル存在確認。バックアップのファイルは何を指定すればいいのか?となるが、それはバックアップの取得方法にもなるが、RMANの設定ではshow allにて得られる。
:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F';
:
とコントロールファイル・初期化ファイルの自動バックアップが有効なら取れてはいる。
3. 制御ファイルを取り戻す†
ここで一旦オラクルを停止させ、取り戻した初期化ファイルで起動し直す。
| RMAN> shutdown
Oracle instance shut down
RMAN> startup nomount
connected to target database (not started)
Oracle instance started
Total System Global Area 2471931904 bytes
Fixed Size 2215864 bytes
Variable Size 1627390024 bytes
Database Buffers 838860800 bytes
Redo Buffers 3465216 bytes
RMAN>
|
パラメータの値は当然違っている。そして、先ほどと同じバックアップファイルから制御ファイルを取り戻す
| RMAN> restore controlfile from '/o2/backup/c-2982693672-20131006-00'; Starting restore at 06-OCT-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/o1/oradata/AERS/control01.ctl
output file name=/o2/oradata/AERS/control02.ctl
Finished restore at 06-OCT-13
RMAN>
|
これで制御ファイルcontrol01.ctlとcontrol02.ctlが戻せた。
4. リストア†
バックアップファイルから、ファイルの戻しである。
mountモードで行うので、一端停止させてから再起動させる。
| RMAN> shutdown
Oracle instance shut down
RMAN> startup mount
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area 2471931904 bytes
Fixed Size 2215864 bytes
Variable Size 1627390024 bytes
Database Buffers 838860800 bytes
Redo Buffers 3465216 bytes
RMAN>
|
そして、
| RMAN> restore database;
Starting restore at 06-OCT-13
Starting implicit crosscheck backup at 06-OCT-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 06-OCT-13
Starting implicit crosscheck copy at 06-OCT-13
using channel ORA_DISK_1
Finished implicit crosscheck copy at 06-OCT-13
searching for all files in the recovery area
cataloging files...
no files cataloged
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /o1/oradata/AERS/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /o1/oradata/AERS/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /o1/oradata/AERS/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /o1/oradata/AERS/users01.dbf
channel ORA_DISK_1: reading from backup piece /o2/backup/0jolok3a_1_1
channel ORA_DISK_1: piece handle=/o2/backup/0jolok3a_1_1 tag=BACKUP_AERS_000045_100613090421
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 06-OCT-13
RMAN>
|
これでファイルは戻る....
5. リカバリ†
ファイルは戻せたが、それはデータベースファイルのみ。障害直前までデータベースを引き上げるには、データベースファイルに記載されていないアーカイブREDOログファイル、REDOログファイルの適用が必要。
| RMAN> recover database;
Starting recover at 06-OCT-13
using channel ORA_DISK_1
starting media recovery
unable to find archived log archived log thread=1 sequence=22
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 10/06/2013 22:41:45
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 22 and starting SCN of 3075908
RMAN>
|
*注意*ここでは、全損。つまりバックアップのみから復元することを想定している。本来なら(rman)backup database plus archivelogでデータベースファイルらと共にアーカイブREDOログファイルもバックアップしていれば問題ないのに、バックアップジョブ作成時に「拡張:またすべてのアーカイブ・ログもディスクにバックアップする(backup archivelog)」を有効にしていないと、アーカイブREDOログファイルはバックアップされず、全損時には喪失となる。
一応、不完全リカバリを行ったがどうしても駄目だった。
recover database noredo;でも駄目(noredoはNOARCHIVELOGモードの時のリカバリなのだけど)。

rmanで実行されるバックアップスクリプトを下記のように変更して採取。
| backup device type disk tag '%TAG' database plus archivelog delete all input;
allocate channel for maintenance type disk;
delete noprompt obsolete device type disk;
release channel;
|
そして、上述の通りリストアを終えて、recover databaseを実施。
| RMAN> recover database;
Starting recover at 07-OCT-13
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=1 sequence=26
channel ORA_DISK_1: reading from backup piece /o2/backup/0oolq3sk_1_1
channel ORA_DISK_1: piece handle=/o2/backup/0oolq3sk_1_1 tag=BACKUP_AERS_000067_100713103808
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/o2/oradata/ARCHIVED_REDO_LOG/1_26_827717513.dbf thread=1 sequence=26
unable to find archived log
archived log thread=1 sequence=27
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 10/07/2013 11:26:32
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 27 and starting SCN of 3110240
RMAN>
|
とまたしてもunable to find archived logと言われてしまう。アーカイブREDOログファイルはあるが、REDOログファイルはリストアされていない。ではどこまでREDOログファイルから作られるアーカイブREDOログファイルがあるかというと、
| [oracle@o ~]$ sqlplus sys/hogehoge@AERS as sysdba
SQL> select GROUP#,SEQUENCE#,STATUS,FIRST_CHANGE#,NEXT_CHANGE# from v$log;
GROUP# SEQUENCE# STATUS FIRST_CHANGE# NEXT_CHANGE#
1 25 INACTIVE 3108624 3109697
3 27 CURRENT 3110240 2.8147E+14
2 26 ACTIVE 3109697 3110240
SQL>
|
STATUS値からシーケンス番号(SEQUENCE#)25のアーカイブREDOログファイルがあれば戻せそうである。
- INACTIVE
そのREDOログファイルは、アーカイブREDOログに移っていて現在使われていない。
- CURRENT
今まさにREDOログファイルとして使用されている。なのでまだアーカイブREDOログには移っていない。
完全リカバリには必要なファイルですな。
- ACTIVE
REDOログファイルとして現在使用されていないが、アーカイブREDOログに移っている最中かな。これも完全リカバリの際には必要
ってこのシーケンス番号25のアーカイブREDOログファイルがバックアップされているのかが大事。
*rmanによるバックアップ後にも次々REDOログファイルからアーカイブREDOログファイルは順次作成されるのでv$logの結果からだけではどこまで実際に戻せるかは未定。
っで、調べるにはrmanでlist backupコマンドを使う。
| RMAN> list backup
(中略)
BS Key Size Device Type Elapsed Time Completion Time
16 979.61M DISK 00:00:44 07-OCT-13
BP Key: 16 Status: AVAILABLE Compressed: NO Tag: BACKUP_AERS_000067_100713103808
Piece Name: /o2/backup/0molq3pe_1_1
List of Archived Logs in backup set 16
Thrd Seq Low SCN Low Time Next SCN Next Time
(中略)
1 25 3108624 07-OCT-13 3109697 07-OCT-13
(中略)
|
と一応シーケンス番号25は、/o2/backup/0molq3pe_1_1に含まれて使えそうである。もしシーケンス番号が24までしかなければ、24までは戻せる。
っで、
| RMAN> run {
2> set until sequence = 25;
3> restore database;
4> recover database;
5> }
executing command: SET until clause
Starting restore at 07-OCT-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /o1/oradata/AERS/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /o1/oradata/AERS/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /o1/oradata/AERS/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /o1/oradata/AERS/users01.dbf
channel ORA_DISK_1: reading from backup piece /o2/backup/0jolok3a_1_1
channel ORA_DISK_1: piece handle=/o2/backup/0jolok3a_1_1 tag=BACKUP_AERS_000045_100613090421
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:58
Finished restore at 07-OCT-13
Starting recover at 07-OCT-13
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=1 sequence=22
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=23
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=24
channel ORA_DISK_1: reading from backup piece /o2/backup/0molq3pe_1_1
channel ORA_DISK_1: piece handle=/o2/backup/0molq3pe_1_1 tag=BACKUP_AERS_000067_100713103808
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
archived log file name=/o2/oradata/ARCHIVED_REDO_LOG/1_22_827717513.dbf thread=1 sequence=22
archived log file name=/o2/oradata/ARCHIVED_REDO_LOG/1_23_827717513.dbf thread=1 sequence=23
archived log file name=/o2/oradata/ARCHIVED_REDO_LOG/1_24_827717513.dbf thread=1 sequence=24
media recovery complete, elapsed time: 00:00:08
Finished recover at 07-OCT-13
RMAN>
RMAN> alter database open resetlogs;
database opened
RMAN>
|
で完了。