26 July, 2015

RMAN -- 5c : (Some More) Useful KEYWORDs and SubClauses

Here are a few more useful KEYWORDs and SubClauses


AS COPY  and   COPY OF
Unlike the BACKUPSET format that is the default for an RMAN Backup, Image Copy backups (those that would be akin to backups created as User Managed Backups without RMAN) can be created in RMAN using the AS COPY specifer.   COPY OF allows backups of such backup copies.

Thus, I take an Image Copy backup of a datafile while the database is OPEN :

RMAN> backup as copy datafile 7 ;       

Starting backup at 26-JUL-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=35 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst90jct_.dbf
output file name=/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9s6b4o_.dbf tag=TAG20150726T214649 RECID=2 STAMP=886110422
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
Finished backup at 26-JUL-15

Starting Control File and SPFILE Autobackup at 26-JUL-15
piece handle=/NEW_FS/oracle/FRA/HEMANTDB/autobackup/2015_07_26/o1_mf_s_886110425_bv9s6trt_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 26-JUL-15

RMAN> 

Did you note how datafile 7 was copied to '/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9s6b4o_.dbf' by the BACKUP AS COPY command ?
Without me specifying a FORMAT, it created the copy in the datafile location under the FRA, not in the backupset location.
Next, I take a backup of this Image Copy backup.

RMAN> backup copy of datafile 7;

Starting backup at 26-JUL-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: including datafile copy of datafile 00007 in backup set
input file name=/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9s6b4o_.dbf
channel ORA_DISK_1: starting piece 1 at 26-JUL-15
channel ORA_DISK_1: finished piece 1 at 26-JUL-15
piece handle=/NEW_FS/oracle/FRA/HEMANTDB/backupset/2015_07_26/o1_mf_nnndf_TAG20150726T214939_bv9scm4h_.bkp tag=TAG20150726T214939 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 26-JUL-15

Starting Control File and SPFILE Autobackup at 26-JUL-15
piece handle=/NEW_FS/oracle/FRA/HEMANTDB/autobackup/2015_07_26/o1_mf_s_886110582_bv9scp9w_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 26-JUL-15

RMAN> 

This time the copy in the datafile location was backed up to a backupset location.  This new backup is not an Image Copy format of datafile 7.  Note the differences in the filenames.   The Image Copy done with BACKUP AS COPY has an OMF filename similar to that of the source datafile.  The BackupSet format includes the TAG as part of the BackupPiece filename.

Let's run some checks, from RMAN and SQLPlus :

SQL> select file_name from dba_data_files where file_id=7;

FILE_NAME
--------------------------------------------------------------------------------
/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst90jct_.dbf

SQL>

RMAN> list backup of datafile 7 completed after "trunc(sysdate)";

using target database control file instead of recovery catalog

List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
91      Full    7.40M      DISK        00:00:01     26-JUL-15      
        BP Key: 103   Status: AVAILABLE  Compressed: YES  Tag: TAG20150726T214939
        Piece Name: /NEW_FS/oracle/FRA/HEMANTDB/backupset/2015_07_26/o1_mf_nnndf_TAG20150726T214939_bv9scm4h_.bkp
  List of Datafiles in backup set 91
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  7       Full 14141418   26-JUL-15 /home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst90jct_.dbf

RMAN> list copy of datafile 7;

List of Datafile Copies
=======================

Key     File S Completion Time Ckp SCN    Ckp Time       
------- ---- - --------------- ---------- ---------------
2       7    A 26-JUL-15       14141418   26-JUL-15      
        Name: /NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9s6b4o_.dbf
        Tag: TAG20150726T214649


RMAN>              

The LIST BACKUP command shows me the BackupSet backup of the Image Copy. If I want to see the Image Copy that I created first, I must run the command LIST COPY. LIST BACKUP shows BackupSets, not Image Copies themselves. Image Copies are displayed by the LIST COPY.

What is the advantage of Image Copy Backups ?  There are a few.
1)  You can integrate this with your User Managed Backups methods.
2)  You can "clone" a database without having to run a RESTORE(yes, with BACKUP AS COPY DATABASE)
3)  You can selectively relocate one or more datafiles with additonal usage of the SWITCH DATAFILE TO COPY command (see my previous post "BACKUP AS COPY")

Let me demonstrate advantage 3 with a tablespace.

SQL> select file_name from dba_data_files where tablespace_name = 'HEMANT';

FILE_NAME
--------------------------------------------------------------------------------
/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst9o4vt_.dbf
/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst90jct_.dbf
/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst9o4x0_.dbf
/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst90jf1_.dbf
/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst9o4x5_.dbf

SQL> 

RMAN> backup as copy tablespace HEMANT;

Starting backup at 26-JUL-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst9o4vt_.dbf
output file name=/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9tkkj1_.dbf tag=TAG20150726T220953 RECID=4 STAMP=886111799
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst90jct_.dbf
output file name=/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9tkrl9_.dbf tag=TAG20150726T220953 RECID=5 STAMP=886111807
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00008 name=/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst9o4x0_.dbf
output file name=/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9tkzo0_.dbf tag=TAG20150726T220953 RECID=6 STAMP=886111825
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile file number=00009 name=/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst90jf1_.dbf
output file name=/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9tlrr3_.dbf tag=TAG20150726T220953 RECID=7 STAMP=886111843
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00011 name=/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst9o4x5_.dbf
output file name=/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9tm7z2_.dbf tag=TAG20150726T220953 RECID=8 STAMP=886111860
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
Finished backup at 26-JUL-15

Starting Control File and SPFILE Autobackup at 26-JUL-15
piece handle=/NEW_FS/oracle/FRA/HEMANTDB/autobackup/2015_07_26/o1_mf_s_886111863_bv9tmq38_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 26-JUL-15

RMAN> 
RMAN> sql 'alter tablespace HEMANT offline';

sql statement: alter tablespace HEMANT offline

RMAN> switch tablespace HEMANT to copy;

datafile 6 switched to datafile copy "/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9tkkj1_.dbf"
datafile 7 switched to datafile copy "/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9tkrl9_.dbf"
datafile 8 switched to datafile copy "/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9tkzo0_.dbf"
datafile 9 switched to datafile copy "/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9tlrr3_.dbf"
datafile 11 switched to datafile copy "/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9tm7z2_.dbf"

RMAN> recover tablespace HEMANT;

Starting recover at 26-JUL-15
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 26-JUL-15

RMAN> sql 'alter tablespace HEMANT online';

sql statement: alter tablespace HEMANT online

RMAN> 

SQL> select file_name from dba_data_files where tablespace_name = 'HEMANT';

FILE_NAME
--------------------------------------------------------------------------------
/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9tkkj1_.dbf
/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9tkrl9_.dbf
/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9tkzo0_.dbf
/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9tlrr3_.dbf
/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9tm7z2_.dbf

SQL> 

Note how all the datafiles of the tablespace were copied and then the active copy of the datafiles has been switched to the new location (/NEW_FS/oracle/FRA/HEMANTDB/datafile/). Have the old datafiles (/home/oracle/app/oracle/oradata/HEMANTDB/datafile/) been deleted ?
Let's see :

RMAN> list copy of tablespace HEMANT;

List of Datafile Copies
=======================

Key     File S Completion Time Ckp SCN    Ckp Time       
------- ---- - --------------- ---------- ---------------
9       6    A 26-JUL-15       14142997   26-JUL-15      
        Name: /home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst9o4vt_.dbf

10      7    A 26-JUL-15       14142997   26-JUL-15      
        Name: /home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst90jct_.dbf

2       7    A 26-JUL-15       14141418   26-JUL-15      
        Name: /NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9s6b4o_.dbf
        Tag: TAG20150726T214649

11      8    A 26-JUL-15       14142997   26-JUL-15      
        Name: /home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst9o4x0_.dbf

12      9    A 26-JUL-15       14142997   26-JUL-15      
        Name: /home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst90jf1_.dbf

13      11   A 26-JUL-15       14142997   26-JUL-15      
        Name: /home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst9o4x5_.dbf


RMAN> 
RMAN> delete copy of tablespace HEMANT;

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=44 device type=DISK
List of Datafile Copies
=======================

Key     File S Completion Time Ckp SCN    Ckp Time       
------- ---- - --------------- ---------- ---------------
9       6    A 26-JUL-15       14142997   26-JUL-15      
        Name: /home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst9o4vt_.dbf

10      7    A 26-JUL-15       14142997   26-JUL-15      
        Name: /home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst90jct_.dbf

2       7    A 26-JUL-15       14141418   26-JUL-15      
        Name: /NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9s6b4o_.dbf
        Tag: TAG20150726T214649

11      8    A 26-JUL-15       14142997   26-JUL-15      
        Name: /home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst9o4x0_.dbf

12      9    A 26-JUL-15       14142997   26-JUL-15      
        Name: /home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst90jf1_.dbf

13      11   A 26-JUL-15       14142997   26-JUL-15      
        Name: /home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst9o4x5_.dbf


Do you really want to delete the above objects (enter YES or NO)? YES
deleted datafile copy
datafile copy file name=/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst9o4vt_.dbf RECID=9 STAMP=886111907
deleted datafile copy
datafile copy file name=/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst90jct_.dbf RECID=10 STAMP=886111907
deleted datafile copy
datafile copy file name=/NEW_FS/oracle/FRA/HEMANTDB/datafile/o1_mf_hemant_bv9s6b4o_.dbf RECID=2 STAMP=886110422
deleted datafile copy
datafile copy file name=/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst9o4x0_.dbf RECID=11 STAMP=886111907
deleted datafile copy
datafile copy file name=/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst90jf1_.dbf RECID=12 STAMP=886111907
deleted datafile copy
datafile copy file name=/home/oracle/app/oracle/oradata/HEMANTDB/datafile/o1_mf_hemant_bst9o4x5_.dbf RECID=13 STAMP=886111907
Deleted 6 objects


RMAN>   

(Note how datafile 7 had two datafile copies). I could delete the old copies of the datafiles.

 Note : The example with tablespace HEMANT uses OMF files. If I had non-OMF files, I could use the "%b" FORMAT modifier -- as demonstrated here.



ARCHIVELOG LIKE
The LIKE Keyword allows you to identify individual or groups of ArchiveLogs.

RMAN> list archivelog all;

List of Archived Log Copies for database with db_unique_name HEMANTDB
=====================================================================

Key     Thrd Seq     S Low Time 
------- ---- ------- - ---------
14      1    628     A 13-JUN-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_04/o1_mf_1_628_bsgrjztp_.arc

18      1    629     A 04-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_04/o1_mf_1_629_bsgrk0tw_.arc

16      1    630     A 04-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_04/o1_mf_1_630_bsgrk48j_.arc

22      1    631     A 04-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_04/o1_mf_1_631_bsgv6f02_.arc

17      1    631     A 04-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_04/o1_mf_1_631_bsgrk49w_.arc

23      1    632     A 04-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_04/o1_mf_1_632_bsgv6f1y_.arc

15      1    632     A 04-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_04/o1_mf_1_632_bsgrk8od_.arc

24      1    633     A 04-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_04/o1_mf_1_633_bsgv6f36_.arc

25      1    1       A 04-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_08/o1_mf_1_1_bst8r4yr_.arc

26      1    2       A 08-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_08/o1_mf_1_2_bstbf4nw_.arc

27      1    3       A 08-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_26/o1_mf_1_3_bv9vbq7c_.arc

28      1    4       A 26-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_26/o1_mf_1_4_bv9vbr1p_.arc

29      1    5       A 26-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_26/o1_mf_1_5_bv9vbtwz_.arc


RMAN> list archivelog like '%2015_07_26%';

List of Archived Log Copies for database with db_unique_name HEMANTDB
=====================================================================

Key     Thrd Seq     S Low Time 
------- ---- ------- - ---------
27      1    3       A 08-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_26/o1_mf_1_3_bv9vbq7c_.arc

28      1    4       A 26-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_26/o1_mf_1_4_bv9vbr1p_.arc

29      1    5       A 26-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_26/o1_mf_1_5_bv9vbtwz_.arc


RMAN> list archivelog like '%_6%';

List of Archived Log Copies for database with db_unique_name HEMANTDB
=====================================================================

Key     Thrd Seq     S Low Time 
------- ---- ------- - ---------
14      1    628     A 13-JUN-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_04/o1_mf_1_628_bsgrjztp_.arc

18      1    629     A 04-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_04/o1_mf_1_629_bsgrk0tw_.arc

16      1    630     A 04-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_04/o1_mf_1_630_bsgrk48j_.arc

22      1    631     A 04-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_04/o1_mf_1_631_bsgv6f02_.arc

17      1    631     A 04-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_04/o1_mf_1_631_bsgrk49w_.arc

23      1    632     A 04-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_04/o1_mf_1_632_bsgv6f1y_.arc

15      1    632     A 04-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_04/o1_mf_1_632_bsgrk8od_.arc

24      1    633     A 04-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_04/o1_mf_1_633_bsgv6f36_.arc

27      1    3       A 08-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_26/o1_mf_1_3_bv9vbq7c_.arc

28      1    4       A 26-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_26/o1_mf_1_4_bv9vbr1p_.arc

29      1    5       A 26-JUL-15
        Name: /NEW_FS/oracle/FRA/HEMANTDB/archivelog/2015_07_26/o1_mf_1_5_bv9vbtwz_.arc


RMAN> 

I can take advantage of this to backups of selective archivelogs.

RMAN> backup as compressed backupset archivelog like '%2015_07_26%';

Starting backup at 26-JUL-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=3 RECID=27 STAMP=886112599
input archived log thread=1 sequence=4 RECID=28 STAMP=886112600
input archived log thread=1 sequence=5 RECID=29 STAMP=886112602
channel ORA_DISK_1: starting piece 1 at 26-JUL-15
channel ORA_DISK_1: finished piece 1 at 26-JUL-15
piece handle=/NEW_FS/oracle/FRA/HEMANTDB/backupset/2015_07_26/o1_mf_annnn_TAG20150726T222529_bv9vgs8r_.bkp tag=TAG20150726T222529 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 26-JUL-15

Starting Control File and SPFILE Autobackup at 26-JUL-15
piece handle=/NEW_FS/oracle/FRA/HEMANTDB/autobackup/2015_07_26/o1_mf_s_886112730_bv9vgtc5_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 26-JUL-15

RMAN> 

This is useful if you have been switching the archivelog destination to different locations during the course of the day.
.
.
.

2 comments:

Anonymous said...

...and you can even 'backup as copy copy of...'. I would have expected that after issuing 'backup as copy...' the resulting file had the same name as the input file, but it didn't!

Unknown said...
This comment has been removed by a blog administrator.