Archive

Archive for the ‘Cloning’ Category

Oracle Cloning

October 20, 2011 Leave a comment

About Cloning
(From Oracle.com)
Cloning is the process of copying an existing Oracle installation to a different location and updating the copied bits to work in the new environment. The changes made by applying one-off patches on the source Oracle home are also present after the clone operation. The source and the destination path (host to be cloned) need not be the same. During cloning, OUI replays the actions that were run to install the home. Cloning is similar to installation, except that OUI runs the actions in a special mode referred to as clone mode. Some situations in which cloning is useful are:

Creating an installation that is a copy of a production, test, or development installation. Cloning enables you to create a new installation with all patches applied to it in a single step. This contrasts with going through the installation process by performing separate steps to install, configure, and patch the installation.

Rapidly deploying an instance and the applications that it hosts.

Preparing an Oracle home and deploying it to many hosts.

The cloned installation behaves the same as the source installation. For example, the cloned Oracle home can be removed using OUI or patched using OPatch. You can also use the cloned Oracle home as the source for another cloning operation. You can create a cloned copy of a test, development, or production installation by using the command-line cloning scripts. The default cloning procedure is adequate for most usage cases. However, you can also customize various aspects of cloning, for example, to specify custom port assignments, or to preserve custom settings.

The cloning process copies all of the files from the source Oracle home to the destination Oracle home. Thus, any files used by the source instance located outside the source Oracle home’s directory structure are not copied to the destination location.

The size of the binaries at the source and the destination may differ because these are relinked as part of the clone operation, and the operating system patch levels may also differ between these two locations. Additionally, the number of files in the cloned home would increase because several files copied from the source, specifically those being instantiated, are backed up as part of the clone operation.

OUI cloning is more beneficial than using the tarball approach, because cloning configures the Central Inventory and the Oracle home inventory in the cloned home. Cloning also makes the home manageable and allows the paths in the cloned home and the target home to be different.

1. Sign in as SYSDBA on the source system through SQL Plus and issue:

ALTER DATABASE BACKUP CONTROLFILE TO TRACE;

Create database syntax will be now placed in the trace file directory. The trace keyword tells oracle to generate a script containing a create controlfile command and store it in the trace directory identified in the user_dump_dest parameter of the init.ora file. It will look something like this:

Trace file:

— The following are current System-scope REDO Log Archival related
— parameters and can be included in the database initialization file.

— LOG_ARCHIVE_DEST=”
— LOG_ARCHIVE_DUPLEX_DEST=”

— LOG_ARCHIVE_FORMAT=ARC%S_%R.%T

— DB_UNIQUE_NAME=”TEST”

— LOG_ARCHIVE_CONFIG=’SEND, RECEIVE, NODG_CONFIG’
— LOG_ARCHIVE_MAX_PROCESSES=2
— STANDBY_FILE_MANAGEMENT=MANUAL
— STANDBY_ARCHIVE_DEST=%ORACLE_HOME%\RDBMS
— FAL_CLIENT=”
— FAL_SERVER=”

— LOG_ARCHIVE_DEST_10=’LOCATION=USE_DB_RECOVERY_FILE_DEST’
— LOG_ARCHIVE_DEST_10=’OPTIONAL REOPEN=300 NODELAY’
— LOG_ARCHIVE_DEST_10=’ARCH NOAFFIRM NOEXPEDITE NOVERIFY SYNC’
— LOG_ARCHIVE_DEST_10=’REGISTER NOALTERNATE NODEPENDENCY’
— LOG_ARCHIVE_DEST_10=’NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME’
— LOG_ARCHIVE_DEST_10=’VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)’
— LOG_ARCHIVE_DEST_STATE_10=ENABLE


— Below are two sets of SQL statements, each of which creates a new
— control file and uses it to open the database. The first set opens
— the database with the NORESETLOGS option and should be used only if
— the current versions of all online logs are available. The second
— set opens the database with the RESETLOGS option and should be used
— if online logs are unavailable.
— The appropriate set of statements can be copied from the trace into
— a script file, edited as necessary, and executed when there is a
— need to re-create the control file.

— Set #1. NORESETLOGS case

— The following commands will create a new control file and use it
— to open the database.
— Data used by Recovery Manager will be lost.
— Additional logs may be required for media recovery of offline
— Use this only if the current versions of all online logs are
— available.

— After mounting the created controlfile, the following SQL
— statement will place the database in the appropriate
— protection mode:
— ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE

STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE “TEST” NORESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\REDO01.LOG’ SIZE 50M,
GROUP 2 ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\REDO02.LOG’ SIZE 50M,
GROUP 3 ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\REDO03.LOG’ SIZE 50M
— STANDBY LOGFILE

DATAFILE
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\SYSTEM01.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\UNDOTBS01.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\SYSAUX01.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\USERS01.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\EXAMPLE01.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\TEST.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\USERS02.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\EXAMPLE2.DBF’
CHARACTER SET WE8MSWIN1252
;

— Commands to re-create incarnation table
— Below log names MUST be changed to existing filenames on
— disk. Any one log file from each branch can be used to
— re-create incarnation records.
— ALTER DATABASE REGISTER LOGFILE ‘C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\TEST\ARCHIVELOG\2011_10_17\O1_MF_1_1_%U_.ARC’;
— ALTER DATABASE REGISTER LOGFILE ‘C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\TEST\ARCHIVELOG\2011_10_17\O1_MF_1_1_%U_.ARC’;
— Recovery is required if any of the datafiles are restored backups,
— or if the last shutdown was not normal or immediate.
RECOVER DATABASE

— All logs need archiving and a log switch is needed.
ALTER SYSTEM ARCHIVE LOG ALL;

— Database can now be opened normally.
ALTER DATABASE OPEN;

— Commands to add tempfiles to temporary tablespaces.
— Online tempfiles have complete space information.
— Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\TEMP01.DBF’
SIZE 20971520 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
— End of tempfile additions.

— Set #2. RESETLOGS case

— The following commands will create a new control file and use it
— to open the database.
— Data used by Recovery Manager will be lost.
— The contents of online logs will be lost and all backups will
— be invalidated. Use this only if online logs are damaged.

— After mounting the created controlfile, the following SQL
— statement will place the database in the appropriate
— protection mode:
— ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE

STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE “TEST” RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\REDO01.LOG’ SIZE 50M,
GROUP 2 ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\REDO02.LOG’ SIZE 50M,
GROUP 3 ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\REDO03.LOG’ SIZE 50M
— STANDBY LOGFILE

DATAFILE
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\SYSTEM01.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\UNDOTBS01.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\SYSAUX01.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\USERS01.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\EXAMPLE01.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\TEST.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\USERS02.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\EXAMPLE2.DBF’
CHARACTER SET WE8MSWIN1252
;

— Commands to re-create incarnation table
— Below log names MUST be changed to existing filenames on
— disk. Any one log file from each branch can be used to
— re-create incarnation records.
— ALTER DATABASE REGISTER LOGFILE ‘C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\TEST\ARCHIVELOG\2011_10_17\O1_MF_1_1_%U_.ARC’;
— ALTER DATABASE REGISTER LOGFILE ‘C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\TEST\ARCHIVELOG\2011_10_17\O1_MF_1_1_%U_.ARC’;
— Recovery is required if any of the datafiles are restored backups,
— or if the last shutdown was not normal or immediate.
RECOVER DATABASE USING BACKUP CONTROLFILE

— Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS;

— Commands to add tempfiles to temporary tablespaces.
— Online tempfiles have complete space information.
— Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\TEMP01.DBF’
SIZE 20971520 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
— End of tempfile additions.

2. Shutdown source database.

3. Install Oracle server on new machine. Create directories ( bdump, udump and cdump and other directories as in source database system ) for the copy database on target system.

4. Copy all data files into the new directories on the new server. You may change the file names if you want, but you must edit the controlfile to reflect the new data files names on the new server.

5. Add database name to tnsnames.ora, listener.ora on target system.

6. Create database service with ORADIM ( If OS is Windows )

oradim -new -sid TEST -INTPWD mypassword -STARTMODE AUTO

7. On target system, set SID and use sqlplus to connect as SYSDBA

8. Delete the control files if any already copied over using OS commands

9. Rename trace file to ‘ DB_CREATE_CONTROLFILE.SQL ‘, edited, contents are as follows:

STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE “TEST” RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\REDO01.LOG’ SIZE 50M,
GROUP 2 ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\REDO02.LOG’ SIZE 50M,
GROUP 3 ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\REDO03.LOG’ SIZE 50M

DATAFILE
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\SYSTEM01.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\UNDOTBS01.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\SYSAUX01.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\USERS01.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\EXAMPLE01.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\TEST.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\USERS02.DBF’,
‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\EXAMPLE2.DBF’
CHARACTER SET WE8MSWIN1252
;

RECOVER DATABASE USING BACKUP CONTROLFILE

ALTER DATABASE OPEN RESETLOGS;

ALTER TABLESPACE TEMP ADD TEMPFILE ‘C:\ORACLE\PRODUCT\10.2.0\ORADATA\TEST\TEMP01.DBF’
SIZE 20971520 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;

10. Run the create control file script issuing:

@DB_CREATE_CONTROLFILE.SQL

If everything went OK and you see no errors, then execute:

SHUTDOWN IMMEDIATE;

11. Startup new database and verify it work fine.

Categories: Cloning Tags: , , ,