Clone Database From NetBackup…Or..”Where Is The Tape, Watson?”

When cloning a live database, this has it’s impact on the live database..open door, I know, but still, it’s a fact. This is not always what we want, since the users can have a lot of issues and even on a test database, deadlines seem to apply.

To remedy this issue, and get the most out of our investment, we decided to clone a database (CLONE! not restore, this is another post on this blog!) from the latest backup we’ve had from the source database. Since we have it, why not using it?

The main reason? Speed. The source database was not loaded in any way at all, and the Netbackup infrastructure is basically not used during business hours, since the backups take place at night. When I try to sleep, or play with the XBox One..;-)

To get started, what do we need?

  • Empty storage to hold the cloned database.
  • The location of the database backup (backup server and backup client names).
  • Enough permissions to read the backup.
  • This blog. ūüėČ

First: check if the backup actually succeeded. Yes, you can asume, but this really is an issue when you have to restore and find out the version you need is not really accessible.

If there is some information that seems to “just be there”, like where is the control file listing coming from in this post, please search the blog, basically all key information is documented on this blog. Or just send me a message, and I’ll clarify and update this post.

Let’s roll!

Open a terminal on the server where the clone needs to be located. There we need to determine the backup we want to use for the clone:

$ /usr/openv/netbackup/bin/bplist -S backup_Server -C backup_client -t 4 -l -R  -I -keyword "*DUMMY*" /

This provides us with the following list:

-rw-rw---- oracle    dba          30932992 Nov 02 02:08 /c-377112624-20161102-02
-rw-rw---- oracle    dba          30932992 Nov 02 02:07 /ctrl_dDUMMY_uvprjsa2u_s3065_p1_t926820446
-rw-rw---- oracle    dba          30932992 Nov 02 02:06 /c-377112624-20161102-01
-rw-rw---- oracle    dba         736886784 Nov 02 02:05 /arch_dDUMMY_uvnrjs9uj_s3063_p1_t926820307
-rw-rw---- oracle    dba          30932992 Nov 02 02:04 /c-377112624-20161102-00
-rw-rw---- oracle    dba         281542656 Nov 02 00:35 /bk_dDUMMY_uvlrjs4n1_s3061_p1_t926814945
-rw-rw---- oracle    dba         327942144 Nov 01 23:00 /bk_dDUMMY_uvkrjrv4v_s3060_p1_t926809247
-rw-rw---- oracle    dba          30932992 Nov 01 02:08 /c-377112624-20161101-02
-rw-rw---- oracle    dba          30932992 Nov 01 02:07 /ctrl_dDUMMY_uvirjplmk_s3058_p1_t926734036
-rw-rw---- oracle    dba          30932992 Nov 01 02:06 /c-377112624-20161101-01
-rw-rw---- oracle    dba         756023296 Nov 01 02:04 /arch_dDUMMY_uvgrjplhv_s3056_p1_t926733887
-rw-rw---- oracle    dba          30932992 Nov 01 02:03 /c-377112624-20161101-00
-rw-rw---- oracle    dba         280494080 Nov 01 00:39 /bk_dDUMMY_uverjpgio_s3054_p1_t926728792
-rw-rw---- oracle    dba         325320704 Oct 31 23:00 /bk_dDUMMY_uvdrjpaot_s3053_p1_t926722845

Optionally the SPFILE can be restored and altered to be used by the clone as a startup, but since I maintain a standard template, it’s just as easy in our situation to create the pfile by hand. Saves a restore run. But use the step below if you want to restore the SPFILE also:

We want to use the latest backup, so select the following backupfile to restore:

/c-377112624-20161102-02

Create a connection to the netbackup server and restore the spfile.

RMAN> run {
allocate channel t1 type 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=client),SBT_LIBRARY=/usr/openv/netbackup/bin/libobk.so64';
send 'NB_ORA_SERV=server,NB_ORA_CLIENT=client';
restore spfile to '/tmp/spfile' from '/c-377112624-20161102-02';
release channel t1;
}

Copy the file over to the correct location, start an instance with this, create pfile, alter settings, create new spfile, start a new instance with this spfile..etc..You know the drill…

NOTE: Before we can restore the spfile, make sure the clone instance is available in NOMOUNT state! Otherwise RMAN cannot do much to help us..

NOTE: derived from some documentation, it might not hurt to set the following environment setting before starting RMAN:

$ export NB_ORA_CLIENT=client

In order to do the clone, we need to connect to the live database, however the data will be retrieved from the backup.

As such we need to connect RMAN like this:

$ rlwrap rman target sys/secret@exp04 auxiliary sys/secret@exp05

Recovery Manager: Release 11.2.0.4.0 - Production on Wed Nov 2 12:22:20 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: EXP04 (DBID=344562624)
connected to auxiliary database: EXP05 (not mounted)

RMAN> run {
allocate channel t1 type 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=client),SBT_LIBRARY=/usr/openv/netbackup/bin/libobk.so64';
allocate auxiliary channel stby01 type disk;
allocate auxiliary channel chan01 type 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=client),SBT_LIBRARY=/usr/openv/netbackup/bin/libobk.so64';

send 'NB_ORA_SERV=server,NB_ORA_CLIENT=client';
SET NEWNAME FOR DATABASE TO '+DATA5DG';
DUPLICATE DATABASE TO exp05
NOFILENAMECHECK;
}

sent command to channel: stby01
sent command to channel: chan01

executing command: SET NEWNAME

Starting Duplicate Db at 02-NOV-16

contents of Memory Script:
{
sql clone "alter system set  control_files =
''+DATA5DG/EXP05/controlfile/current.258.926857701'', ''+FRA5DG/EXP05/controlfile/current.257.926857701'' comment=
''Set by RMAN'' scope=spfile";
sql clone "alter system set  db_name =
''EXP04'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set  db_unique_name =
''EXP05'' comment=
''Modified by RMAN duplicate'' scope=spfile";
shutdown clone immediate;
startup clone force nomount
restore clone primary controlfile;
alter clone database mount;
}
executing Memory Script

sql statement: alter system set  control_files =   ''+DATA5DG/EXP05/controlfile/current.258.926857701'', ''+FRACCDM5DG/EXP05/controlfile/current.257.926857701'' comment= ''Set by RMAN'' scope=spfile

sql statement: alter system set  db_name =  ''EXP04'' comment= ''Modified by RMAN duplicate'' scope=spfile

sql statement: alter system set  db_unique_name =  ''EXP05'' comment= ''Modified by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area   12827369472 bytes

Fixed Size                     2265224 bytes
Variable Size               3925872504 bytes
Database Buffers            8858370048 bytes
Redo Buffers                  40861696 bytes
allocated channel: stby01
channel stby01: SID=926 device type=DISK
allocated channel: chan01
channel chan01: SID=992 device type=SBT_TAPE
channel chan01: Veritas NetBackup for Oracle - Release 7.6 (2013111313)

Starting restore at 02-NOV-16

channel chan01: starting datafile backup set restore
channel chan01: restoring control file
channel chan01: reading from backup piece c-377112624-20161102-02
} channel chan01: piece handle=c-377112624-20161102-02 tag=TAG20161102T020823
channel chan01: restored backup piece 1
channel chan01: restore complete, elapsed time: 00:01:05
output file name=+DATA5DG/EXP05/controlfile/current.258.926857701
output file name=+FRA5DG/EXP05/controlfile/current.257.926857701
Finished restore at 02-NOV-16

database mounted

contents of Memory Script:
{
set until scn  6402052692;
set newname for datafile  1 to
"+DATA5DG";
set newname for datafile  2 to


executing command: SET NEWNAME
Starting restore at 02-NOV-16

channel chan01: starting datafile backup set restore
channel chan01: specifying datafile(s) to restore from backup set
channel chan01: restoring datafile 00002 to +DATA05DG
channel chan01: reading from backup piece bk_dEXP04_usjrjha6t_s2963_p1_t926460125
...

As is visible above: the controlfile is restored from tape, and the rest of the restore also gets the data from the backup lib, NOT from the live database, although we do have a connection to this.

After the data reading from tape is done, the output should look like the following:

...
datafile 77 switched to datafile copy
input datafile copy RECID=76 STAMP=926872015 file name=+DATA5DG/EXP05/datafile/za_indx.314.926870347
datafile 78 switched to datafile copy
input datafile copy RECID=77 STAMP=926872015 file name=+DATA5DG/EXP05/datafile/es_indx.315.926870413

Reenabling controlfile options for auxiliary database
Executing: alter database force logging

contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 02-NOV-16
released channel: t1
released channel: stby01
released channel: chan01

RMAN>

And that’s it! When the process is complete, and has no errors (most will be related with running out of storage space, so check this first).

Note: This is a very careful approach, but it’s up to the DBA to allocate a lot more channels to speed up this process. I normally hit the four channels and complete the process a lot quicker than with just one..

Advertisements

About GemsOfProgramming

Beeing a previously enthusiastic Java programmer, I rolled into the Oracle Database Administration world. It turned out I got a knack for this, and since approx. 2000 I'm a full time DBA. My experiences touches lot of Oracle products like Forms and Reports 9/10, JDAPI, Application Server, Weblogic Fusion and of course: Oracle Enterprise Databases, JavaFX, Swing and other Java components.
This entry was posted in ASM, backup, Databases, Technical Stuff and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s