High Availbility

OS & Virtualization

Thursday, June 21, 2007

Cloning a Database

I routinely refresh development and test databases, and they will sometimes need to clone databases to test backup and recovery strategies.

  • By using the RMAN DUPLICATE command
  • By using the OEM Database Control
  • By manually performing the copy with SQL
Using RMAN to Clone a Database
RMAN provides the DUPLICATE command, which uses the backups of a database to create a newdatabase. The files are restored to the target database, after which an incomplete recovery is performedand the new database is opened with the OPEN RESETLOGS command.
  1. Create a new init.ora file for the auxiliary database. The init.ora file should have the following parameters, with the data files and log file parameters changed to ensure that theoriginal database files arent used for the new database:

    - DB_FILE_NAME_CONVERT
    - LOG_FILE_NAME_CONVERT
  2. Start the target database instance.

    SQL > startup nomount
  3. Connect the recovery catalog to the target database and the auxiliary database

    RMAN > CONNECT target / catalog rman/rman1@catalog_db auxiliary sys/password@auxiliary_db
  4. Issue the RMAN DUPLICATE command, as follows:

    RMAN> DUPLICATE TARGET DATABASE TO auxiliary_db
    pfile =/u01/app/oracle/10.2.0/db_1/dbs/init_auxiliary_db;
  5. Opens the duplicated database with the RESETLOGS

    SQL> alter database open resetlogs
Manually Cloning a Database
To clone a database manually, you need to first use the operating system to copy all of the source database files to the target location.
  1. Copy the prod database files to the target location.
  2. Prepare a text file for the creation of a control file for the new database as follows:

    SQL> ALTER DATABASE BACKUP CONTROLFILE TO TRACE RESETLOGS;
  3. On the target location, create all the directories for the various files.
  4. change SID, path, of the backup control trace file controlfile_open.sql
  5. Run the following command

    SQL> startup nomount;
    SQL> @controlfile_open.sql

No comments: