In the previous instalment of this exciting series, we completed the full (complete) recovery of the database, tablespaces and data files, as well as looking at recovering individual blocks.
In this article, we will perform incomplete recovery where we restore and recover the databases to a specific point in time that is previous to “now”.
Note that in the following examples I’m using the until time option and specifying a date and time. You can restore to a particular SCN, or archive log number etc. See the manual for all the options.
It is possible that data will be lost with this kind of recovery. It is not possible to perform incomplete recovery on tablespaces or data files, you are limited to restoring and recovering the entire database. Although, this is not quite true, read on …
Incomplete Recovery of the Database
As the whole database is being restored, the SYSTEM
and UNDO
tablespaces will be restored and recovered, so the database will need to be in a mounted
state. You cannot carry out incomplete recovery on an open database.
First of all, let’s add a new row to our test table which we use to show progress etc.
|
|
Now, restore and recover the database back to a time that is about 15 minutes ago. The first stage is to get the database into a mount
state.
|
|
Next, we restore the database to our chosen time.
|
|
|
|
I’ve trimmed the usual RMAN verbose output from the above to save you falling asleep reading it! ;-)
Next, we need to recover the database to the same time.
|
|
|
|
Again, I’ve trimmed the output. RMAN will restore to disc any archived logs it requires to carry out the recovery if it determines that they are not available online.
The final stage is to reopen the database. You must use the resetlogs option because you’ve carried out an incomplete recovery.
|
|
So, the restore and recovery went well, did it really work?
|
|
So, our most recent row in the table is no longer present, we now have 6 rows instead of the 7 that we had at the start of this recovery. The database has been restored back in time.
You will note that in both the restore database
and the recover database
commands, I had to specify the same time. There is a short cut that you can use to save typing.
|
|
|
|
Now you can open the database in resetlogs
mode as above.
Restoring a Database Through a Resetlogs
In the past it wasn’t possible to restore a database that had been opened with resetlogs
specified. RMAN used to treat this as a new incarnation of the database, so you had to make sure you took a fresh backup as soon as the database was opened.
RMAN in 11g is much more forgiving and it is now possible to restore through a resetlogs
. You do this by restoring a backup from the previous incarnation and do a recover. If you watch the recovery phase carefully, you will see the archived logs files being applied from before and after the resetlogs
.
The following assume that you haven’t taken a backup of the new incarnation yet. If you have, you must restore the controlfile from a named backup as opposed to letting RMAN work it out.
The first step is to restore the controlfile.
|
|
|
|
|
|
|
|
Now that we are on an old controlfile and the database is mounted, we can restore and recover the database in the normal manner.
|
|
|
|
Now all we have to do is the recover. As mentioned above, watch the thread and sequence numbers closely.
|
|
|
|
You can hopefully see, in the above, that the sequence number dropped from 20 to 1 as we recovered through the resetlogs. Talking of which, we need another one now.
|
|
Tablespace Incomplete Recovery
It was never possible to do a tablespace point in time recovery without cloning the database first and using the clone to export the data. However, with 11g it is now possible to perform incomplete recovery on a tablespace (or tablespaces) as RMAN takes care of all the cloning etc.
First of all, create a working area for the clone, as root.
|
|
Next, check our test table to see how far back we can recover the users tablespace.
|
|
Obviously your decision criteria for the actual time to restore back to will be a little more scientific than mine! But I’m going to select a date of just after 16/02/2012 17:26:20, lets call it 16/02/2012 17:30:00.
The first problem we may happen across is whether there are any objects in the tablespace to be restored which have constraints etc in other tablespaces. We check the SYS.TS_PITR_CHECK
.
|
|
In this case as we are about to restore the users tablespace, we have to see if there are relationships from users to other tablespaces and also if there are relationships from other tablespaces to users.
There are none, but if there had been, we would either need to temporarily drop those constraints or include the other tablespace(s) in the recovery.
The next problem is those objects that exist in the database now, that didn’t at the time of the recovery point in time. Again we can find a list of those by checking SYS.TS_PITR_OBJECTS_TO_BE_DROPPED
and giving the date and time we intend to use.
|
|
So far so good. Had there been any objects listed, we would need to run an export of those objects using data pump to preserve them across the recovery.
We are now ready to carry out a point in time restore of the users tablespace to the working area instead of to the normal database area. You do not need to take the tablespace offline, RMAN does that for you.
Note, in the following command
_recover_
is correct. Do not use_restore_
as it will not work.
|
|
|
|
You will note that there is a lot of output from RMAN as it builds a clone database and recovers the tablespace to the specified time.
You cannot recover a tablespace to a time previous to the last resetlogs time. If you try, you will get the following error message:
RMAN-03002: failure of recover command at 05/15/2012 15:55:53
RMAN-20207: UNTIL TIME or RECOVERY WINDOW is before RESETLOGS time
After the tablespace has been cloned and recovered, you must back it up and then bring it online.
|
|
If you do not have an RMAN catalogue in use, you are not permitted to carry out more than one of these tablespace point in time recovery operations because the controlfile no longer knows about the previous incarnations of the recovered tablespace(s).
This is one of the reasons why you must backup the tablespace immediately after recovering it.
If, on the other hand, you do use a catalogue, then multiple recoveries of the same tablespace(s) are permitted.