In my previous post on this topic, I noted that you could use the snapshot time
on the recover database command to recover the database from a SAN snapshot.
I realise that there are different possible scenarios and my write up wasn’t clear
on which approach is applicable when. Also, the test I did was unrealistic as I
used the logs after the snapshot was taken, and the whole point of using
SAN snapshots is that they contain everything required for a crash consistent
recovery.
Start up in place
If you had a crash consistent snapshot, this can be mounted in the place of the
original and started. Oracle will recover as if the database had crashed, and
all is well. Easy!
Start up a copy
More often, a table will be accidentally corrupted, and we will be asked to
restore it from the snapshot, but we want to keep the rest of the data in the
database is good, we want to leave that as it is. This is more tricky, and is
where the new command comes in.
Here it is really useful to have the create controlfile command. It is possible
to construct it from the files on the snapshot, but this is fiddly. It would
be worth having a cron job to periodically issue:
find . -type f -name \*.dbf | whileread aline
doif grep $aline CONTROLFILE.sql
thenecho$aline found
elseecho'****'$aline missing
fidone
Now I am pretty confident in the commands. Ensure an init,ora exists for the database,
and is correct, then run the controlfile command. This will start up the database, create
the controlfile, but fail to recover because it doesn’t know where the redo is.
SQL>@CONTROLFILE
ORACLE instance started.
Total SystemGlobal Area 2147483648 bytes
Fixed Size3712904 bytes
VariableSize1694500984 bytes
Database Buffers 436207616 bytes
Redo Buffers 13062144 bytes
Control file created.
ORA-00279: change 15295737437889generatedat01/19/201812:02:30 needed forthread 1ORA-00289: suggestion : /RECO/archive/RECO_80_1_963178734.arc
ORA-00280: change 15295737437889for thread 1isin sequence #80ORA-00308: cannot open archived log '/RECO/archive/RECO_80_1_963178734.arc'ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3Database altered.
Database altered.
ALTERDATABASEOPEN RESETLOGS
*ERROR at line 1:
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/RECO/system/system01.dbf'ALTER TABLESPACE TEMP ADD TEMPFILE '/RECO/temp/temp01.dbf'*ERROR at line 1:
ORA-01109: databasenotopen
Next I made an interesting mistake. If the snapshot time is too early, the database
will tell you. If this happens you can add a second until it works. Or in my case, just
specify the correct year!
SQL> recover databaseuntil cancel using backup controlfile snapshot time '19-JAN-2017 13:19:01';
ORA-00283: recovery session canceled due to errors
ORA-19839: snapshot datafile checkpoint time is greater than snapshot time
ORA-01110: data file 1: '/RECO/system/system01.dbf'
The database needs to use the online redo log from the old database and it doesn’t
know about this because of the new controlfile. To prove it needs recovery from the redo log I will
try to cancel it.
SQL> recover databaseuntil cancel using backup controlfile snapshot time '19-JAN-2018 13:19:01';
ORA-00279: change 15295737437889generatedat01/19/201812:02:30 needed forthread 1ORA-00289: suggestion : /RECO/archive/RECO_80_1_963178734.arc
ORA-00280: change 15295737437889for thread 1isin sequence #80Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
CANCEL
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/RECO/system/system01.dbf'ORA-01112: media recovery not started
So, I specify the latest online redo log, and it recovers OK.