recover Receive Updates For This Category
November 22, 2011 Articles 0 0
Duplicate a Database Using RMAN in Oracle Database 11g Release 2
- Introduction
- Backup-Based Duplication
- Active Database Duplication
Introduction
RMAN has the ability to duplicate, or clone, a database from a backup or from an active database. It is possible to create a duplicate database on a remote server with the same file structure, a remote server will a different file structure or the local server with a different file structure.
The article assumes the duplicate database is being created on a separate server, using the same SID (DB11G) and the same file structure as the source database. Explanations of several other scenarios are available here.
Backup-Based Duplication
Create a backup of the source database, if a suitable one doesn8217;t already exist.
$ rman target=/ RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON; RMAN> BACKUP DATABASE PLUS ARCHIVELOG
All subsequent actions occur on the server running the duplicate database.
Create a password file for the duplicate instance.
$ orapwd file=/u01/app/oracle/product/11.2.0/db_1/dbs/orapwDB11G password=password entries=10
Add the appropriate entries into the 8220;tnsnames.ora8221; file in the 8220;$ORACLE_HOME/network/admin8221; directory to allow connections to the target database from the duplicate server.
# Added to the tnsnames.ora
DB11G-SOURCE =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ol5-112-dup1)(PORT = 1521))
)
(CONNECT_DATA =
(ORACLE_SID = DB11G)
)
)
Create a PFILE for the duplicate database. Since we are duplicating the database onto a separate server with the same filesystem as the original, we don8217;t need to convert the file names. In this case, the PFILE is called 8220;initDB11G.ora8221; and is placed in the 8220;$ORACLE_HOME/dbs8221; directory.
# Minimum Requirement. DB_NAME=DB11G # Convert file names to allow for different directory structure if necessary. #DB_FILE_NAME_CONVERT=(/u01/app/oracle/oradata/DB11G/,/u01/app/oracle/oradata/NEWSID/) #LOG_FILE_NAME_CONVERT=(/u01/app/oracle/oradata/DB11G/,/u02/app/oracle/oradata/NEWSID/)
Create any directories necessary for start the duplicate database.
$ mkdir -p /u01/app/oracle/oradata/DB11G $ mkdir -p /u01/app/oracle/fast_recovery_area/DB11G $ mkdir -p /u01/app/oracle/admin/DB11G/adump
Make the backup files from the source database available to the destination server. That can be done by either copying them to the matching location on the destination server, or placing them on a shared drive. If you are copying the files, you may want to use the following type of commands.
$ scp -r oracle@ol5-112-dup1:/u01/app/oracle/fast_recovery_area/DB11G/archivelog /u01/app/oracle/fast_recovery_area/DB11G $ scp -r oracle@ol5-112-dup1:/u01/app/oracle/fast_recovery_area/DB11G/backupset /u01/app/oracle/fast_recovery_area/DB11G $ scp -r oracle@ol5-112-dup1:/u01/app/oracle/fast_recovery_area/DB11G/autobackup /u01/app/oracle/fast_recovery_area/DB11G
Connect to the duplicate instance.
$ ORACLE_SID=DB11G; export ORACLE_SID $ sqlplus / as sysdba
Start the database in NOMOUNT mode.
SQL> STARTUP NOMOUNT;
With the duplicate database started we can now connect to it from RMAN. For the duplication to work we must connect to the duplicate database (AUXILIARY), but depending on the type of duplication we are doing we may optionally connect to the original database (TARGET) and/or the recovery catalog (CATALOG).
$ ORACLE_SID=DB11G; export ORACLE_SID $ rman AUXILIARY / $ rman TARGET sys/password@DB11G-SOURCE AUXILIARY / $ rman CATALOG rman/password@rman-catalog AUXILIARY / $ rman TARGET sys/password@DB11G-SOURCE CATALOG rman/password@rman-catalog AUXILIARY /
We can then duplicate the database using one of the following commands.
# Backup files are in matching location to that on the source server. # Duplicate database to TARGET's current state. DUPLICATE TARGET DATABASE TO DB11G SPFILE NOFILENAMECHECK; # Duplicate database to TARGET's state 4 days ago. DUPLICATE TARGET DATABASE TO DB11G UNTIL TIME 'SYSDATE-4' SPFILE NOFILENAMECHECK; # Backup files are in a different location to that on the source server. # Duplicate database to the most recent state possible using the provided backups. # Works with just an AUXILIARY connection only. DUPLICATE DATABASE TO DB11G SPFILE BACKUP LOCATION '/source/app/oracle/fast_recovery_area/DB11G' NOFILENAMECHECK;
The time it takes to complete varies depending on the size of the database and the specification of the server. Once the process is finished RMAN produces a completion message and you have your duplicate instance.
Active Database Duplication
Oracle 11g introduced the ability to create duplicate databases directly without the need for a backup. This is known as active database duplication. The process is similar to the backup-based duplication, with a few exceptions.
First, and most obviously, you don8217;t need a backup of the source system, but it does have to be in ARCHIVELOG mode.
The passwords in the password files must match for both servers, so remember to set the correct password when creating the password file on the destination server.
Both the source and destination database servers require a 8220;tnsnames.ora8221; entry for the destination database. In this case I added the following to each server. The destination server still requires the source entry shown in the previous section.
# Added to the tnsnames.ora on source and destination server.
DB11G-DESTINATION =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ol5-112-dup2)(PORT = 1521))
)
(CONNECT_DATA =
(ORACLE_SID = DB11G)
)
)
The destination server requires static listener configuration in a 8220;listener.ora8221; file. In this case I used the following configuration. Remember to restart or reload the listener.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = DB11G.WORLD)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = DB11G)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ol5-112-dup2.localdomain)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
When connecting to RMAN, you must use a connect string for both the target and auxiliary connections.
$ ORACLE_SID=DB11G; export ORACLE_SID $ rman TARGET sys/password@DB11G-SOURCE AUXILIARY sys/password@DB11G-DESTINATION
Include the FROM ACTIVE DATABASE clause in the DUPLICATE command.
DUPLICATE DATABASE TO DB11G FROM ACTIVE DATABASE SPFILE NOFILENAMECHECK;
For more information see:
Introduction
In this paper we will present a method for retrieving data from an Oracle database that cannot be opened normally because one or more datafiles is inconsistent with the others. An example of a scenario where you would find yourself in this situation is as follows:
A disk failed on our server and we lost a datafile. We restored the datafile from a hot backup taken a week ago, but it turns out we are missing a few redo logs archived since then. Oracle is complaining because we can8217;t produce the required archived redo logs, and we can8217;t open the database. The datafile in question contains our most important tables. Is there any way we can salvage our data?
Every DBA should know that there is a problem here. The missing archived redo logs contain transactions which affect the data in the database. So it’s a given that you’re going to lose some data, but the question is, “How much?” Oracle takes a hard-line position and will not let you open the database normally because a data integrity issue exists. However, you may be able to retrieve much of your data if you use non-traditional means to get Oracle to drop its hard-line attitude. Retrieving the data that can be salvaged with the understanding that some data will be lost could be a whole lot better than losing all of the data because a subset of it has been corrupted.
In the next section of this paper, we will look at an overview of how you might go about salvaging data from an inconsistent datafile and get the database back up and running properly again. In the succeeding sections of this paper, we’ll dig into each step of the process in greater detail.
Overview
If you’ve lost a datafile that contained only indexes for heap-organized tables, or other data that is easily recreated, then your best bet might be to drop the tablespace and recreate and repopulate it from scratch. But if you’ve lost a datafile that contained important data not easily recreated, and all you have is an old backup of the file without all of the intervening archived redo logs, then you will want to extract what data you can from the problem tablespace, drop the tablespace, and then recreate and repopulate the tablespace.
Although the exact steps will vary depending on the particular situation, the general steps involved are:
- Taking a cold backup of what you have now.
- Restoring the lost datafile from a backup and applying the archived redo logs that you do have.
- Setting an undocumented instance parameter which will allow you to open the database in its current state.
- Doing exports and selects to retrieve what data you can from the problem tablespace.
- Restoring the entire database from the cold backup taken earlier.
- Taking the damaged datafile offline.
- Doing exports and selects to retrieve additional data not salvaged in step 4.
- Restoring again from the cold backup.
- Dropping the problem tablespace.
- Recreating the problem tablespace.
- Rebuilding the data in the problem tablespace with the data extracted in steps 4 and 7.
Some of these steps can be quite tedious and time-consuming. You may choose to skip a few or even several of the steps depending on how much disk space, tedium, and database down time you are willing to pay in exchange for potentially salvaging more of the lost data.
As we discuss each of the steps in greater detail, we will walk through an example case where a datafile called ordtab03.dbf in tablespace ORDTAB was lost due to a disk crash. This datafile contained many extents of the ORDERS table. The datafile was restored from a hot backup taken July 4, 2004, but some of the archived redo logs between July 4 and the present day have been lost.
Step 1: Backup the Database
The first thing you should do is take a cold backup of whatever datafiles, online redo logs, and control files you currently have. If rebuilding everything from existing backups, then make sure you have a place to keep the backup files handy, as you’ll probably want them more than once. It’s best if you have cold backups. If you’ve just lost one or a few datafiles and the database is still open, make a hot backup of each of the remaining datafiles and save this somewhere (and make sure you keep the archived redo logs generated during and after the hot backup).
In a later step we will be using an undocumented and unsupported Oracle feature in order to make the best of a bad situation. Taking a backup of the database now, before we “cross the line” into unsupported territory, allows us to return to this side of the line in a later step.
After you’ve created the backup, it’s time to work on the database. Before you shut the database down, create a backup control file script:
ALTER DATABASE BACKUP CONTROLFILE TO TRACE RESETLOGS;
This will create a script in your user_dump_dest directory to create a new control file. The name of the file will be similar to that of other trace files—something like [instance_name]_ora_[PID].trc. Rename the file to newcontrol.sql.
Now we want to edit the file. Open it with a text editor such as vi or emacs. There will be about 15 lines at the top of the file with version and connection information. We don’t want these messing up our script, so delete all the lines above the first line beginning with a pound sign (#). (Instead of deleting these lines, you could make them comments by putting a pound sign at the beginning of each.)
Then delete the line that begins “RECOVER DATABASE…” toward the end of the file and save the file.
Step 2: Restore the Lost Datafile and Apply Archived Redo Logs
At this point you should restore the lost datafile from a backup and apply what archived redo logs you have in order to roll the datafile contents forward as far as possible. You will have to stop at the first missing archived redo log. In our example, we restored the ordtab03.dbf datafile from the July 4, 2004 hot backup and applied the archived redo logs that we had available.
If you were to try to open the database normally at this point, you would get an ORA-01589 error:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
If you then tried an ALTER DATABASE OPEN RESETLOGS command, you would get an ORA-01195 error:
ORA-01195: online backup of file %s needs more recovery to be consistent
This is where Oracle is taking its hard-line approach. The datafile restored from the backup was not recovered to a point in time consistent with the other datafiles in the database. Therefore data corruption may exist and Oracle will not let you open the database normally.
Step 3: Set an Undocumented Instance Parameter and Open the Database
At this point we leave the world of standard practice and cross the line into unsupported activity. It’s time to edit the database’s init.ora file or spfile. First, you’ll want to set job_queue_processes to 0 if it’s not already, as you don’t need jobs running while you’re extracting data. Then you need to set the parameter:
_allow_resetlogs_corruption=TRUE
This parameter is a “hidden” or undocumented parameter—one of those which you’re never supposed to use unless told to do so by Oracle Support. We probably should have pointed out earlier that you shouldn’t be doing this entire exercise unless you’ve failed with everything Oracle Support has told you to do. The description of this parameter reads “allow resetlogs even if it will cause corruption”. Some of the caveats to be found on Metalink regarding this parameter include:
Steps as mentioned here beneath are only applicable in a situation that no restore/recovery can be performed of the database in question. Applying beneath steps means that data will be exported from a database being in an inconsistent state (no instance recovery can be performed), this is true for user data as well for the data dictionary.
You should NOT use unsupported parameters without the advice from support.
Since you are using these undocumented parameters without specific instruction from Oracle Support, we can8217;t support this database. If someone did instruct you to set these parameters, then you may want to continue discussion on this issue with that individual.
If you are able to startup this database, it would be only to do a full export and recreate it. If you want to pursue this possibility, please log an itar. This issue cannot be handled through this forum.
That said, if you want to continue, after changing the parameter, then move to the directory where you saved your newcontrol.sql script in the first step. (If you didn’t move the script, it will still be in your user_dump_dest directory.) Connect to the database as SYSDBA and run the newcontrol.sql script.
Your database is now open (though NOT consistent). You can run queries and sometimes everything will appear perfectly normal:
SQL> SELECT COUNT(*) FROM OE.orders;
COUNT(*)
----------
403439
The database is in an inconsistent state and you are skating on thin ice. The above query worked fine because Oracle didn’t need to access any data blocks that were corrupt or referenced inconsistent undo entries. The query could have just as easily failed with an ORA-00600 error such as:
SQL> SELECT COUNT(*) FROM OE.orders;
SELECT COUNT(*) FROM OE.orders
*
ERROR at line 1:
ORA-00600: internal error code, arguments: [kcfrbd_2], [14],
[19081], [8], [1280], [1280], [], []
Step 4: Do Exports and Selects to Retrieve Data
As we saw in the previous step, some queries will work fine and some will fail right away. Still others will return partial results, quitting when an inconsistency is found:
SQL> SELECT order_id FROM OE.orders
2 WHERE entry_date > TO_DATE ('04-JUL-2004');
ORDER_ID
----------
496103
496104
496105
...
511325
511326
511327
511328
ERROR:
ORA-00600: internal error code, arguments: [kcfrbd_2], [14],
[19081], [8], [1280], [1280], [], []
15225 rows selected.
We can use this ability to “pick around” problem data blocks:
SQL> SELECT order_id FROM OE.orders
2 WHERE order_id > 511400;
ORDER_ID
----------
511401
511402
511403
...
513398
513399
513400
513401
2001 rows selected.
Database exports are now possible too, though some errors will occur:
About to export specified users ...
. exporting object type definitions for user OE
EXP-00090: cannot pin type "OE"."ORDER_ELEMENT_TYPE"
EXP-00056: ORACLE error 22303 encountered
OCI-22303: type "OE"."ORDER_ELEMENT_TYPE" not found
...
. about to export OE's tables via Conventional Path ...
. . exporting table BATCH_JOBSS 4382 rows exported
...
. . exporting table CUSTOMER_TYPES
EXP-00056: ORACLE error 600 encountered
ORA-00600: internal error code, arguments: [4146], [45144], [45124], [], [], [], [], []
. . exporting table DEFAULT_VALUES 391 rows exported
Even for the tables with errors, some data will likely be extracted and written to the export file. Moreover you can easily determine which tables you’re able to export all rows from, so you won’t have to make further extraction efforts with them.
Step 5: Restore the Database from Backup
This step, along with the next two, is optional. Together these three steps present another approach that may allow you to retrieve more of your data. Restoring the database from a backup at this point effectively undoes any damage caused by the use of the undocumented _allow_resetlogs_corruption instance parameter. This time through, we will not make any attempt to recover the lost datafile.
Step 6: Take the Damaged Datafile Offline
In this step you take the damaged datafile offline. The purpose here is to get the database to a point where everything is completely consistent, and the data that would be inconsistent is simply deemed unavailable.
This is fairly straightforward:
ALTER DATABASE DATAFILE '/u07/oradata/PRD/ordtab03.dbf' OFFLINE;
Step 7: Do Exports and Selects to Retrieve Additional Data
At this point you may be able to retrieve additional data for salvage that you were not able to get at earlier. For example, you may be able to fetch useful data from indexes belonging to tables that are damaged. If you inadvertently try to access the damaged datafile, you’ll get an ORA-00376 error:
ORA-00376: file 39 cannot be read at this time
ORA-01110: data file 39: '/u07/oradata/PRD/ordtab03.dbf'
Step 8: Restore the Database from Backup
Now you restore the database from backup for the last time. This step officially rolls the database back to a point in time before the use of the undocumented instance parameter, and therefore returns the database to a supported state. Note that if you restored the database from backup in step 5 and have not updated any data in the database since then, you may be able to skip this step.
Step 9: Drop the Problem Tablespace
First you’ll need to determine whether there are any referential integrity constraints from tables outside the problem tablespace which refer to primary or unique keys of tables inside the problem tablespace. You can use a query such as the following:
SELECT CR.constraint_name
FROM dba_constraints CR, dba_constraints CP,
dba_tables TP, dba_tables TR
WHERE CR.r_owner = CP.owner
AND CR.r_constraint_name = CP.constraint_name
AND CR.constraint_type = 'R'
AND CP.constraint_type IN ('P', 'U')
AND CP.table_name = TP.table_name
AND CP.owner = TP.owner
AND CR.table_name = TR.table_name
AND CR.owner = TR.owner
AND TR.tablespace_name <> 'ORDTAB'
AND TP.tablespace_name = 'ORDTAB';
If there were any such constraints, you would need to create scripts to recreate them (if you don’t already have them). If you are using export dumps to rebuild the data (in step 11), the constraints can possibly be restored from the export files.
Drop the tablespace containing the damaged datafile with a statement like:
DROP TABLESPACE ordtab INCLUDING CONTENTS CASCADE CONSTRAINTS;
Step 10: Recreate the Problem Tablespace
Here you simply want to recreate the tablespace so that in the next step you can repopulate it with the data you extracted earlier. You could consult an old export file in order to recreate the tablespace exactly as it was, or you could take this opportunity to switch to a locally managed tablespace, enable the autoallocate feature, adjust storage parameters, and so on.
Step 11: Rebuild the Data in the Problem Tablespace
At this time you are ready to reload the tablespace with the data that you salvaged earlier. If you used the export utility to extract data from some or all tables, you can use import to restore the schema objects and data. If export encountered an error while reading a table, import should still be able to recreate the rows that were successfully extracted before the error occurred. If you used queries to extract data into flat files, then you can use SQL*Loader or any number of other tools to put the data back into the database.
Now you will have a functional database with as much data as you were able to extract from the damaged database. If you are lucky you were able to get almost all of your data. If not, at least you were probably able to get some data and get your database working again.
The first thing you should do immediately after repopulating the tablespace is take a backup of this repaired database. The second thing you should do is implement proper procedures for backing up the database, storing the backups and archived redo logs for appropriate retention periods, and testing the backup/recovery process on a regular basis. Your data is too valuable to risk losing, and your time is too valuable to spend going through steps like these to try to recover some of it.
Conclusion
We have discussed a situation that no DBA should ever be in, and hopefully you will never need to use the information presented here. The scenario addressed here results from not having proper (and tested) backup procedures. This paper has been all about making the best of a bad situation.
The Oracle database is very good about protecting the integrity of your data—making sure you’re able to get all of your data in a time-consistent manner. That applies even if you’ve lost datafiles, as long as you have copies of the datafiles (either from cold or hot backups) and all of the archived redo logs from the time of the oldest datafile copy to the current time (or whatever time you want to recover to).
If you don’t have all of the required files, then there is no way of guaranteeing that all of your data is there and consistent with other data. So if you don’t have the necessary files, Oracle won’t allow you to open the database normally. With the _allow_resetlogs_corruption instance parameter, however, Oracle has given us a tool to recover some of the data if possible. This is a tool that you should hope to never have to use—but if you should need it, you’ll be glad it is there and you know something about how to use it.
Recovery Manager (RMAN)
Recovery manager is a platform non-specific utility for coordinating you backup and restoration procedures across multiple servers. In my opinion it8217;s value is limited if you only have on or two instances, but it comes into it8217;s own where large numbers of instances on multiple platforms are used. The reporting features alone mean that you should never find yourself in a position where your data is in danger due to failed backups.
The functionality of RMAN is too diverse to be covered in this article so I shall focus on the basic backup and recovery functionality.
- Create Recovery Catalog
- Register Database
- Cold Backup
- Hot Backup
- Restore & Recover The Whole Database
- Restore & Recover A Subset Of The Database
- Incomplete Recovery
- Lists And Reports
Create Recovery Catalog
First create a user to hold the recovery catalog:
CONNECT sys/password@TSH1 -- Create tablepsace to hold repository CREATE TABLESPACE "TOOLS" DATAFILE 'E:\ORACLE\ORADATA\DDBA1\TOOLS01.DBF' SIZE 10M AUTOEXTEND ON NEXT 1024K EXTENT MANAGEMENT LOCAL; -- Create rman schema owner CREATE USER rman IDENTIFIED BY rman TEMPORARY TABLESPACE temp DEFAULT TABLESPACE tools QUOTA UNLIMITED ON tools; GRANT connect, resource, recovery_catalog_owner TO rman;
Then create the recovery catalog:
c:> rman catalog rman/rman@tsh1 Recovery Manager: Release 8.1.7.0.0 - Production RMAN-06008: connected to recovery catalog database RMAN-06428: recovery catalog is not installed RMAN> create catalog tablespace tools; RMAN-06431: recovery catalog created RMAN> exit Recovery Manager complete. C:>
Register Database
Each database to be backed up by RMAN must be registered:
C:>rman target sys/password@tsh1 rcvcat rman/rman@dba1 msglog 'C:OracleBackupTSH1TSH1_Daily_Backup.log' Recovery Manager: Release 8.1.7.0.0 - Production RMAN-06005: connected to target database: TSH1 (DBID=955315395) RMAN-06008: connected to recovery catalog database RMAN> register database; RMAN-03022: compiling command: register RMAN-03023: executing command: register RMAN-08006: database registered in recovery catalog RMAN-03023: executing command: full resync RMAN-08002: starting full resync of recovery catalog RMAN-08004: full resync complete RMAN>
Existing user-created backups can be added to the catalog using:
catalog datafilecopy 'C:\Oracle\Oradata\TSH1.dbf'; catalog archivelog 'log1', 'log2', 'log3', ... 'logN';
Cold Backup
This RMAN script starts by doing a a clean mount of the database. It then backs up the datafiles, controlfile and archivelogs, with old archive logs deleted in the process. Finally the database is opened.
replace script 'TSH1_daily_backup' {
# make sure database is shutdown cleanly
shutdown immediate;
startup force dba pfile=c:\Oracle\Admin\TSH1\pfile\init.ora;
shutdown immediate;
#Mount the database and start backup
startup mount pfile=c:\Oracle\Admin\TSH1\pfile\init.ora;
# Backup datafile, controlfile and archivelogs
allocate channel ch1 type
disk format 'C:\Oracle\Backup\TSH1\%d_DB_%u_%s_%p';
backup database include current controlfile
tag = 'TSH1_daily_backup';
release channel ch1;
# Open the database
alter database open;
# Archive all logfiles including current
sql 'ALTER SYSTEM ARCHIVE LOG CURRENT';
# Backup outdated archlogs and delete them
allocate channel ch1 type
disk format 'C:\Oracle\Backup\TSH1\%d_ARCH_%u_%s_%p';
backup archivelog
until time 'Sysdate-2' all
delete input;
release channel ch1;
# Backup remaining archlogs
allocate channel ch1 type
disk format 'C:\Oracle\Backup\TSH1\%d_ARCH_%u_%s_%p';
backup archivelog all;
release channel ch1;
}
The file can be loaded as a stored script and run using the following commands:
RMAN> @c:\Oracle\Backup\TSH1_daily_backup.txt
RMAN> run {execute script TSH1_daily_backup; }
The RMAN output can be a bit unnerving at first. You should expect something like:
RMAN> run {execute script TSH1_daily_backup; }
RMAN-03021: executing script: TSH1_daily_backup
RMAN-03022: compiling command: shutdown
RMAN-06405: database closed
RMAN-06404: database dismounted
RMAN-06402: Oracle instance shut down
RMAN-03022: compiling command: startup
RMAN-06196: Oracle instance started
RMAN-06199: database mounted
RMAN-06400: database opened
Total System Global Area 13375516 bytes
Fixed Size 75804 bytes
Variable Size 12402688 bytes
Database Buffers 819200 bytes
Redo Buffers 77824 bytes
RMAN-03022: compiling command: shutdown
RMAN-06405: database closed
RMAN-06404: database dismounted
RMAN-06402: Oracle instance shut down
RMAN-03022: compiling command: startup
RMAN-06193: connected to target database (not started)
RMAN-06196: Oracle instance started
RMAN-06199: database mounted
Total System Global Area 13375516 bytes
Fixed Size 75804 bytes
Variable Size 12402688 bytes
Database Buffers 819200 bytes
Redo Buffers 77824 bytes
RMAN-03022: compiling command: allocate
RMAN-03023: executing command: allocate
RMAN-08030: allocated channel: ch1
RMAN-08500: channel ch1: sid=14 devtype=DISK
RMAN-03022: compiling command: backup
RMAN-03023: executing command: backup
RMAN-08008: channel ch1: starting full datafile backupset
RMAN-08502: set_count=51 set_stamp=437320255 creation_time=09-AUG-01
RMAN-08010: channel ch1: specifying datafile(s) in backupset
RMAN-08522: input datafile fno=00001 name=C:\ORACLE\ORADATA\TSH1\SYSTEM01.DBF
RMAN-08011: including current controlfile in backupset
RMAN-08522: input datafile fno=00009 name=C:\ORACLE\ORADATA\TSH1\DES601.DBF
RMAN-08522: input datafile fno=00002 name=C:\ORACLE\ORADATA\TSH1\RBS01.DBF
RMAN-08522: input datafile fno=00008 name=C:\ORACLE\ORADATA\TSH1\OEM_REPOSITORY.ORA
RMAN-08522: input datafile fno=00003 name=C:\ORACLE\ORADATA\TSH1\USERS01.DBF
RMAN-08522: input datafile fno=00004 name=C:\ORACLE\ORADATA\TSH1\TEMP01.DBF
RMAN-08522: input datafile fno=00006 name=C:\ORACLE\ORADATA\TSH1\INDX01.DBF
RMAN-08522: input datafile fno=00007 name=C:\ORACLE\ORADATA\TSH1\DR01.DBF
RMAN-08522: input datafile fno=00005 name=C:\ORACLE\ORADATA\TSH1\TOOLS01.DBF
RMAN-08013: channel ch1: piece 1 created
RMAN-08503: piece handle=C:\ORACLE\BACKUP\TSH1\TSH1_DB_1JD11UHV_51_1 comment=NONE
RMAN-08525: backup set complete, elapsed time: 00:05:52
RMAN-03023: executing command: partial resync
RMAN-08003: starting partial resync of recovery catalog
RMAN-08005: partial resync complete
RMAN-03022: compiling command: release
RMAN-03023: executing command: release
RMAN-08031: released channel: ch1
RMAN-03022: compiling command: alter db
RMAN-06400: database opened
RMAN-03022: compiling command: sql
RMAN-06162: sql statement: ALTER SYSTEM ARCHIVE LOG CURRENT
RMAN-03023: executing command: sql
RMAN-03022: compiling command: allocate
RMAN-03023: executing command: allocate
RMAN-08030: allocated channel: ch1
RMAN-08500: channel ch1: sid=14 devtype=DISK
RMAN-03022: compiling command: backup
RMAN-03025: performing implicit partial resync of recovery catalog
RMAN-03023: executing command: partial resync
RMAN-08003: starting partial resync of recovery catalog
RMAN-08005: partial resync complete
RMAN-03023: executing command: backup
RMAN-08009: channel ch1: starting archivelog backupset
RMAN-08502: set_count=52 set_stamp=437320626 creation_time=09-AUG-01
RMAN-08014: channel ch1: specifying archivelog(s) in backup set
RMAN-08504: input archivelog thread=1 sequence=226 recid=11 stamp=437307841
RMAN-08504: input archivelog thread=1 sequence=227 recid=12 stamp=437309722
RMAN-08504: input archivelog thread=1 sequence=228 recid=13 stamp=437316806
RMAN-08504: input archivelog thread=1 sequence=229 recid=14 stamp=437317665
RMAN-08504: input archivelog thread=1 sequence=230 recid=15 stamp=437319111
RMAN-08504: input archivelog thread=1 sequence=231 recid=16 stamp=437320622
RMAN-08013: channel ch1: piece 1 created
RMAN-08503: piece handle=C:\ORACLE\BACKUP\TSH1\TSH1_ARCH_1KD11UTI_52_1 comment=NONE
RMAN-08525: backup set complete, elapsed time: 00:00:04
RMAN-03023: executing command: partial resync
RMAN-08003: starting partial resync of recovery catalog
RMAN-08005: partial resync complete
RMAN-03022: compiling command: release
RMAN-03023: executing command: release
RMAN-08031: released channel: ch1
RMAN> exit
Recovery Manager complete.
The recovery catalog should be resyncronized on a regular basis so that changes to the database structure and presence of new archive logs is recorded. Some commands perform partial and full resyncs implicitly, but a full resync should be scheduled at regular intervals.
resync catalog;
Hot Backup
Hot backups using RMAN are very simple. There is no need to alter the tablespace or database mode.
run {
allocate channel ch1 type disk format 'd:\oracle\backup%d_DB_%u_%s_%p';
backup database;
backup archivelog all;
release channel ch1;
}
Restore & Recover The Whole Database
Recovering from a media failure is as simple as:
run {
startup mount pfile=c:\Oracle\Admin\TSH1\pfile\init.ora;
allocate channel ch1 type disk;
restore database;
recover database;
release channel ch1;
}
This will result in all datafiles being restored then recovered. RMAN will apply archive logs as necessary until the recovery is complete. The sort of results you should expect are:
Recovery Manager: Release 8.1.7.0.0 - Production
RMAN-06005: connected to target database: TSH1 (DBID=955315395)
RMAN-06008: connected to recovery catalog database
RMAN> run {
2> startup mount pfile=c:\Oracle\Admin\TSH1\pfile\init.ora;
3>
4> allocate channel ch1 type disk;
5>
6> restore database;
7> recover database;
8>
9> release channel ch1;
10>}
RMAN-03022: compiling command: startup
RMAN-06193: connected to target database (not started)
RMAN-06196: Oracle instance started
RMAN-06199: database mounted
Total System Global Area 13375516 bytes
Fixed Size 75804 bytes
Variable Size 12402688 bytes
Database Buffers 819200 bytes
Redo Buffers 77824 bytes
RMAN-03022: compiling command: allocate
RMAN-03023: executing command: allocate
RMAN-08030: allocated channel: ch1
RMAN-08500: channel ch1: sid=14 devtype=DISK
RMAN-03022: compiling command: restore
RMAN-03022: compiling command: IRESTORE
RMAN-03023: executing command: IRESTORE
RMAN-08016: channel ch1: starting datafile backupset restore
RMAN-08502: set_count=51 set_stamp=437320255 creation_time=09-AUG-01
RMAN-08089: channel ch1: specifying datafile(s) to restore from backup set
RMAN-08523: restoring datafile 00001 to C:\ORACLE\ORADATA\TSH1\SYSTEM01.DBF
RMAN-08523: restoring datafile 00002 to C:\ORACLE\ORADATA\TSH1\RBS01.DBF
RMAN-08523: restoring datafile 00003 to C:\ORACLE\ORADATA\TSH1\USERS01.DBF
RMAN-08523: restoring datafile 00004 to C:\ORACLE\ORADATA\TSH1\TEMP01.DBF
RMAN-08523: restoring datafile 00005 to C:\ORACLE\ORADATA\TSH1\TOOLS01.DBF
RMAN-08523: restoring datafile 00006 to C:\ORACLE\ORADATA\TSH1\INDX01.DBF
RMAN-08523: restoring datafile 00007 to C:\ORACLE\ORADATA\TSH1\DR01.DBF
RMAN-08523: restoring datafile 00008 to C:\ORACLE\ORADATA\TSH1\OEM_REPOSITORY.ORA
RMAN-08523: restoring datafile 00009 to C:\ORACLE\ORADATA\TSH1\DES601.DBF
RMAN-08023: channel ch1: restored backup piece 1
RMAN-08511: piece handle=C:\ORACLE\BACKUP\TSH1\TSH1_DB_1JD11UHV_51_1 tag=TSH1_DAILY_BACKUP params=NULL
RMAN-08024: channel ch1: restore complete
RMAN-03023: executing command: partial resync
RMAN-08003: starting partial resync of recovery catalog
RMAN-08005: partial resync complete
RMAN-03022: compiling command: recover
RMAN-03022: compiling command: recover(1)
RMAN-03022: compiling command: recover(2)
RMAN-03022: compiling command: recover(3)
RMAN-03023: executing command: recover(3)
RMAN-08054: starting media recovery
RMAN-08055: media recovery complete
RMAN-03022: compiling command: recover(4)
RMAN-03022: compiling command: release
RMAN-03023: executing command: release
RMAN-08031: released channel: ch1
RMAN> exit
Recovery Manager complete.
Once this process us complete the database can be opened using the ALTER DATABASE OPEN; command.
Restore & Recover A Subset Of The Database
A subset of the database can be restored in a similar fashion:
run {
sql 'ALTER TABLESPACE users OFFLINE IMMEDIATE';
restore tablespace users;
recover tablespace users;
sql 'ALTER TABLESPACE users ONLINE';
}
Incomplete Recovery
As you would expect, RMAN allows incomplete recovery to a specified time, SCN or sequence number:
run
{
set until time 'Nov 15 2000 09:00:00';
# set until scn 1000; # alternatively, you can specify SCN
# set until sequence 9923; # alternatively, you can specify log sequence number
restore database;
recover database;
}
alter database open resetlogs;
The incomplete recovery requires the database to be opened using the RESETLOGS option.
Lists And Reports
RMAN has extensive listing and reporting functionality allowing you to monitor you backups and maintain the recovery catalog. Here are a few useful commands:
# Show all backup details list backup; # Show items that beed 7 days worth of # archivelogs to recover completely report need backup days = 7 database; # Show/Delete items not needed for recovery report obsolete; delete obsolete; # Show/Delete items not needed for point-in-time # recovery within the last week report obsolete recovery window of 7 days; delete obsolete recovery window of 7 days; # Show/Delete items with more than 2 newer copies available report obsolete redundancy = 2 device type disk; delete obsolete redundancy = 2 device type disk; # Show datafiles that connot currently be recovered report unrecoverable database; report unrecoverable tablespace 'USERS';
It8217;s worth spending some time looking at all the reporting capabilities whilst deciding whether you should switch from shell scripting to RMAN. It might just influence your decision.
