About Me

My photo
Bangalore, India
I am an Oracle Certified Professional working in SAP Labs. Everything written on my blog has been tested on my local environment, Please test before implementing or running in production. You can contact me at amit.rath0708@gmail.com.
Showing posts with label Cloning. Show all posts
Showing posts with label Cloning. Show all posts

Thursday, October 5, 2017

How to Clone Grid Infrastructure binaries for Oracle Server(Standalone)

Yesterday I was applying patch on one of our development servers and patch on Grid Home failed with space issue and binaries got corrupted.

I thought of reinstalling the grid binaries by cloning it from a fresh development server. PFB steps for that :-

1. Stop the source(fresh) grid binaries. Hostname is Source_server
2. Tar the binaries 
3. Scp to the target(corrupted) server.  Hostname is Target_server

4. Detach the grid home from the Central inventory in Corrupted server :-

==>./runInstaller.sh -silent -detachHome ORACLE_HOME=/opt/grid/12.1.0.2 ORACLE_HOME_NAME=" Ora11g_gridinfrahome1"
Starting Oracle Universal Installer...

Checking swap space: must be greater than 500 MB.   Actual 16383 MB    Passed
The inventory pointer is located at /etc/oraInst.loc
'DetachHome' was successful.
[target_server][oracle][]

5. Clone the grid home so that binaries are linked and grid home is attached to Central inventory

./runInstaller -clone -waitForCompletion  "ORACLE_HOME=/opt/grid/12.1.0.2" "ORACLE_HOME_NAME=OraHome1Grid" "INVENTORY_LOCATION=/opt/orainv/oraInventory" "LOCAL_NODE=target_server" "CRS=FASLE" "ORACLE_BASE=/opt/oracle" -silent -paramFile /opt/grid/12.1.0.2/clone/clone_oraparam.ini
Starting Oracle Universal Installer...

Checking Temp space: must be greater than 500 MB.   Actual 233206 MB    Passed
Checking swap space: must be greater than 500 MB.   Actual 16383 MB    Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2017-10-03_05-47-08AM. Please wait ...You can find the log of this install session at:
 /opt/orainv/oraInventory/logs/cloneActions2017-10-03_05-47-08AM.log
..................................................   5% Done.
..................................................   10% Done.
..................................................   15% Done.
..................................................   20% Done.
..................................................   25% Done.
..................................................   30% Done.
..................................................   35% Done.
..................................................   40% Done.
..................................................   45% Done.
..................................................   50% Done.
..................................................   55% Done.
..................................................   60% Done.
..................................................   65% Done.
..................................................   70% Done.
..................................................   75% Done.
..................................................   80% Done.
..................................................   85% Done.
..........Could not backup file /opt/grid/12.1.0.2/root.sh to /opt/grid/12.1.0.2/root.sh.ouibak
Could not backup file /opt/grid/12.1.0.2/rootupgrade.sh to /opt/grid/12.1.0.2/rootupgrade.sh.ouibak

Copy files in progress.

Copy files successful.

Link binaries in progress.

Link binaries successful.

Setup files in progress.

Setup files successful.

Setup Inventory in progress.

Setup Inventory successful.

Finish Setup successful.
The cloning of OraHome1Grid was successful.
Please check '/opt/orainv/oraInventory/logs/cloneActions2017-10-03_05-47-08AM.log' for more details.

Setup Oracle Base in progress.

Setup Oracle Base successful.
..................................................   95% Done.

As a root user, execute the following script(s):
        1. /opt/grid/12.1.0.2/root.sh


..................................................   100% Done.
[target_server][oracle][]

6. Execute the root.sh script

7. Configure your CRS instance on the cluster

While Configuring , I got below error :-

[root@target_server grid]# /opt/grid/12.1.0.2/perl/bin/perl -I/opt/grid/12.1.0.2/perl/lib -I/opt/grid/12.1.0.2/crs/install /opt/grid/12.1.0.2/crs/install/roothas.pl
Using configuration parameter file: /opt/grid/12.1.0.2/crs/install/crsconfig_params
2017/06/03 06:00:59 CLSRSC-350: Cannot configure two CRS instances on the same cluster

2017/10/03 06:00:59 CLSRSC-352: CRS is already configured on this node for the CRS home location /opt/grid/12.1.0.2

we have to deconfigure the existing one before configuring it again

8. Deconfigure the existing CRS 

[root@target_server install]# ./roothas.pl -deconfig -force
Using configuration parameter file: ./crsconfig_params
2017/10/03 06:13:02 CLSRSC-337: Successfully deconfigured Oracle Restart stack

9. Configure it again :-

[root@target_server install]# /opt/grid/12.1.0.2/perl/bin/perl -I/opt/grid/12.1.0.2/perl/lib -I/opt/grid/12.1.0.2/crs/install /opt/grid/12.1.0.2/crs/install/roothas.pl
Using configuration parameter file: /opt/grid/12.1.0.2/crs/install/crsconfig_params
LOCAL ADD MODE
Creating OCR keys for user 'oracle', privgrp 'sigdba'..
Operation successful.
LOCAL ONLY MODE
Successfully accumulated necessary OCR keys.
Creating OCR keys for user 'root', privgrp 'root'..
Operation successful.
CRS-4664: Node target_server successfully pinned.
2017/10/03 06:15:36 CLSRSC-330: Adding Clusterware entries to file 'oracle-ohasd.conf'


target_server 2017/10/03 06:16:02 /opt/grid/12.1.0.2/cdata/target_server/backup_20170603_061602.olr 3924561976
CRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on 'target_server'
CRS-2673: Attempting to stop 'ora.evmd' on 'target_server'
CRS-2677: Stop of 'ora.evmd' on 'target_server' succeeded
CRS-2793: Shutdown of Oracle High Availability Services-managed resources on 'target_server' has completed
CRS-4133: Oracle High Availability Services has been stopped.
CRS-4123: Oracle High Availability Services has been started.
2017/10/03 06:16:33 CLSRSC-327: Successfully configured Oracle Restart for a standalone server

9. Add the asm details and start the asm

==>srvctl add asm -d /dev/mapper/
[target_server][oracle][+ASM]
/dev/mapper$
==>
[target_server][oracle][+ASM]
/dev/mapper$
==>srvctl start asm
[target_server][oracle][+ASM]
/dev/mapper$

[target_server][oracle][+ASM]
/dev/mapper$
==>sqlplus  /as sysasm

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Automatic Storage Management option

SQL> alter diskgroup AMIT_GROUP mount;

Diskgroup altered.

10 . Add database to CRS 

==>srvctl add database -d amit -o /opt/oracle/product/database/12.1.0.2/
[target_server][oracle][amit]

/dev/mapper$
==>sqlplus /as sysdba

Connected to an idle instance.

SQL> startup mount
ORACLE instance started.

Total System Global Area 8589934592 bytes
Fixed Size                  7663544 bytes
Variable Size            3288334408 bytes
Database Buffers         3137339392 bytes
Redo Buffers                9113600 bytes
In-Memory Area           2147483648 bytes
Database mounted.
SQL> alter database open;

Database altered.

Cloning of Grid home binaries completed.

I hope this article helped you

Thanks
Amit Rath

Saturday, October 20, 2012

How to clone a Oracle Database using RMAN

Cloning of Database includes below mentioned steps :-

1. Take a fresh backup of your OLD database of which you want to make a clone.

Refer to this article for taking RMAN consistent or Inconsistent backups :-
How to backup of Oracle Database using RMAN

2. Create a pfile for OLD database.

SQL> create pfile='/home/cognos/pfileorcl.ora' from spfile;

File created.

3. PFB contents of OLD database pfile . 

Modify the parameters in green colour of this pfile according to the New Database server.

*.audit_file_dest='/u04/app/cognos/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.1.0.0.0'
*.control_files='+AMIT_R1/orcl/controlfile/current.261.790789011','+AMIT_R1/orcl/controlfile/current.260.790789011'
*.db_block_size=8192
*.db_create_file_dest='+AMIT_R1'
*.db_domain='com'
*.db_name='orcl'
*.db_recovery_file_dest='+AMIT_R1'
*.db_recovery_file_dest_size=2147483648
*.diagnostic_dest='/u04/app/cognos'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.java_pool_size=64m

*.log_archive_dest_1='LOCATION=/backup/orcl/'
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_max_size=1026870912
*.sga_target=1026870912
*.undo_tablespace='UNDOTBS1'


4. Move Backup pieces and pfile to new database server.

5. Use the above pfile to startup in nomount mode the NEW database. 
 
SQL> startup nomount pfile='/home/cognos/pfileorcl.ora'
ORACLE instance started.

Total System Global Area 1025298432 bytes
Fixed Size                  1341000 bytes
Variable Size             322963896 bytes
Database Buffers          696254464 bytes
Redo Buffers                4739072 bytes
SQL>


6. Restore control files of OLD database to new host database.

RMAN> restore controlfile from '/backup/BKPSETS_20OCT12_CONTROLFILE_0sno8cm4_1_1';

Starting restore at 20-OCT-12
using channel ORA_DISK_1

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:08
output file name=+EXAMPLE/orcl/controlfile/current.267.797196775
output file name=+
EXAMPLE/orcl/controlfile/current.268.797196777
Finished restore at 20-OCT-12



7. Mount your New Database.

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1


8. Catalog all Backup pieces of OLD database server to new database server.

RMAN> catalog backuppiece '/backup/BKPSETS_20OCT12_0ino8cf8_1_1','/backup/BKPSETS_20OCT12_0lno8cfa_1_1','/backup/BKPSETS_20OCT12_0kno8cf8_1_1','/backup/BKPSETS_20OCT12_0rno8cm2_1_1','/backup/BKPSETS_20OCT12_0sno8cm4_1_1';

cataloged backup piece
backup piece handle=/backup/BKPSETS_20OCT12_0ino8cf8_1_1 RECID=29 STAMP=797197934
cataloged backup piece
backup piece handle=/backup/BKPSETS_20OCT12_0lno8cfa_1_1 RECID=30 STAMP=797197935
cataloged backup piece
backup piece handle=/backup/BKPSETS_20OCT12_0kno8cf8_1_1 RECID=31 STAMP=797197935
cataloged backup piece
backup piece handle=/backup/BKPSETS_20OCT12_0rno8cm2_1_1 RECID=32 STAMP=797197935
cataloged backup piece
backup piece handle=/backup/BKPSETS_20OCT12_0sno8cm4_1_1 RECID=33 STAMP=797197935


 9. Run the restore command to restore the datafiles.

TO run restore command you need the details of the datafiles of OLD database.
Login into the OLD database and get below mentioned details:-

SQL> Select file_id,file_name from dba_data_files;

   FILE_ID FILE_NAME
---------- --------------------------------------------------------------------------------                  

         6 +AMIT_R1/orcl/datafile/amit.271.795743985
         5 +AMIT_R1/orcl/datafile/example.269.790789095
         4 +AMIT_R1/orcl/datafile/users.259.790788813
         3 +AMIT_R1/orcl/datafile/undotbs1.258.790788813
         2 +AMIT_R1/orcl/datafile/sysaux.257.790788811
         1 +AMIT_R1/orcl/datafile/system.256.790788811

6 rows selected.



Now run the resore command in NEW database host in RMAN prompt :-

RMAN> run
2> {
3> set newname for datafile 1 to '
+EXAMPLE';
4> set newname for datafile 2 to '+
EXAMPLE';
5> set newname for datafile 4 to '+
EXAMPLE';
6> set newname for datafile 3 to '+
EXAMPLE';
7> set newname for datafile 5 to '+
EXAMPLE';
8> set newname for datafile 6 to '+
EXAMPLE';
9> restore database;
10> switch datafile all;
11> }


The Command will give you below mentioned output:-

RMAN> run
 {
set newname for datafile 1 to '
+EXAMPLE';
 set newname for datafile 2 to '+
EXAMPLE';
 set newname for datafile 4 to '+
EXAMPLE';
 set newname for datafile 3 to '+
EXAMPLE';
 set newname for datafile 5 to '+
EXAMPLE';
 set newname for datafile 6 to '+
EXAMPLE';
 restore database;
 switch datafile all;
  }2> 3> 4> 5> 6> 7> 8> 9> 10> 11>

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 20-OCT-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=23 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00003 to +EXAMPLE

channel ORA_DISK_1: restoring datafile 00004 to +EXAMPLE
channel ORA_DISK_1: reading from backup piece +AMIT_R1/orcl/backupset/2012_10_20/nnndf0_tag20121020t182444_0.275.797192689
channel ORA_DISK_1: piece handle=+AMIT_R1/orcl/backupset/2012_10_20/nnndf0_tag20121020t182444_0.275.797192689 tag=TAG20121020T182444
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:15
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00002 to +EXAMPLE

channel ORA_DISK_1: restoring datafile 00006 to +EXAMPLE
channel ORA_DISK_1: reading from backup piece +AMIT_R1/orcl/backupset/2012_10_20/nnndf0_tag20121020t182444_0.276.797192687
channel ORA_DISK_1: piece handle=+AMIT_R1/orcl/backupset/2012_10_20/nnndf0_tag20121020t182444_0.276.797192687 tag=TAG20121020T182444
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:46
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to +EXAMPLE

channel ORA_DISK_1: restoring datafile 00005 to +EXAMPLE
channel ORA_DISK_1: reading from backup piece +AMIT_R1/orcl/backupset/2012_10_20/nnndf0_tag20121020t182444_0.274.797192711
channel ORA_DISK_1: piece handle=+AMIT_R1/orcl/backupset/2012_10_20/nnndf0_tag20121020t182444_0.274.797192711 tag=TAG20121020T182444
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:45
Finished restore at 20-OCT-12

datafile 1 switched to datafile copy
input datafile copy RECID=7 STAMP=797201985 file name=+
EXAMPLE/orcl/datafile/system.260.797201879
datafile 2 switched to datafile copy
input datafile copy RECID=8 STAMP=797201985 file name=+
EXAMPLE/orcl/datafile/sysaux.269.797201773
datafile 3 switched to datafile copy
input datafile copy RECID=9 STAMP=797201985 file name=+
EXAMPLE/orcl/datafile/undotbs1.268.797201697
datafile 4 switched to datafile copy
input datafile copy RECID=10 STAMP=797201986 file name=+
EXAMPLE/orcl/datafile/users.267.797201699
datafile 5 switched to datafile copy
input datafile copy RECID=11 STAMP=797201986 file name=+
EXAMPLE/orcl/datafile/example.261.797201879
datafile 6 switched to datafile copy
input datafile copy RECID=12 STAMP=797201986 file name=+
EXAMPLE/orcl/datafile/amit.256.797201773 

10. Recover the database

RMAN> recover database;

Starting recover at 20-OCT-12
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 8 is already on disk as file +AMIT_R1/orcl/onlinelog/group_2.264.790789023
archived log for thread 1 with sequence 9 is already on disk as file +AMIT_R1/orcl/onlinelog/group_3.266.790789027
archived log for thread 1 with sequence 10 is already on disk as file +AMIT_R1/orcl/onlinelog/group_1.262.790789015
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=7
channel ORA_DISK_1: reading from backup piece /backup/BKPSETS_20OCT12_0rno8cm2_1_1
channel ORA_DISK_1: piece handle=/backup/BKPSETS_20OCT12_0rno8cm2_1_1 tag=TAG20121020T182818
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/backup/orcl/1_7_796679647.dbf thread=1 sequence=7
archived log file name=+AMIT_R1/orcl/onlinelog/group_2.264.790789023 thread=1 sequence=8
archived log file name=+AMIT_R1/orcl/onlinelog/group_3.266.790789027 thread=1 sequence=9
archived log file name=+AMIT_R1/orcl/onlinelog/group_1.262.790789015 thread=1 sequence=10
media recovery complete, elapsed time: 00:00:26
Finished recover at 20-OCT-12


Exit from RMAN and login with SQLPLUS

11. Rename the ONLINE redo logs file

 SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------      


+AMIT_R1/orcl/onlinelog/group_3.266.790789027
+AMIT_R1/orcl/onlinelog/group_3.267.790789029
+AMIT_R1/orcl/onlinelog/group_2.264.790789023
+AMIT_R1/orcl/onlinelog/group_2.265.790789025
+AMIT_R1/orcl/onlinelog/group_1.262.790789015
+AMIT_R1/orcl/onlinelog/group_1.263.790789019

6 rows selected.


Rename all logfiles :-

SQL> alter database rename file '+AMIT_R1/orcl/onlinelog/group_3.266.790789027' to '+EXAMPLE/fingate/redo03a.log';
Database altered.

SQL> alter database rename file '
+AMIT_R1/orcl/onlinelog/group_1.262.790789015' to '+EXAMPLE/fingate/redo01.log';
Database altered.

SQL> alter database rename file '
+AMIT_R1/orcl/onlinelog/group_1.263.790789019' to '+EXAMPLE/fingate/redo01a.log';
Database altered.

.
.
.
like this reaname all logfiles .

SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------        

+EXAMPLE/fingate/redo01.log+EXAMPLE/fingate/redo01a.log+EXAMPLE/fingate/redo03a.log+EXAMPLE/fingate/redo03.log+EXAMPLE/fingate/redo4.log+EXAMPLE/fingate/redo4a.log

6 rows selected.


12. Open your clone database

SQL> alter database open resetlogs;

Database altered.

SQL> select name from v$database;

NAME
---------
ORCL


13. Rename Temp tablespace.

SQL> select name from v$tempfile;

NAME
--------------------------------------------------------------------------------  

+AMIT_R1/orcl/tempfile/temp.268.790789087

SQL> create temporary tablespace temp1 tempfile '+
EXAMPLE';

Tablespace created.

SQL> alter database default temporary tablespace temp1;

Database altered.

SQL> drop tablespace temp including contents and datafiles;

Tablespace dropped.

SQL> select name from v$tempfile;

NAME
--------------------------------------------------------------------------------             

+EXAMPLE/orcl/tempfile/temp1.270.797205367

Cloning of ORCL database on a NEW HOST completed.

I Hope this article helped you.

Regards,
Amit Rath