Wednesday, 30 August 2017

12c Oracle Database recovery from RMAN Full Backup step by step



---------Full database backup and restore on same server--------------

Backing up Databases in Oracle

In layman’s words, a data backup is a copy of the data that we keep so as to restore our original data in the case of events such as data loss.
Needless to say, if we are running a business or even if we have some data on our computer that we wouldn’t want to lose, taking the backup of the data is considered the best practice. 
Backup is key to providing a secure and reliable database environment

Now, data loss can be caused due to various reasons, which are why taking backups becomes so important. Some of the reasons for data loss are:

1) Accidentally misplacing or deleting data
2) Virus attacks
3) Hardware crashes
4) Moving data from one system to another, and so on.

1)Take RMAN Full backup of Database

[oracle@exacell01 dbs]$
[oracle@exacell01 dbs]$ rman

Recovery Manager: Release 12.1.0.2.0 - Production on Sun Feb 7 13:49:15 2016

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

RMAN> connect target

connected to target database: CDB3 (DBID=600505155)

RMAN> exit


Recovery Manager complete.
[oracle@exacell01 dbs]$ rman target / nocatalog

Recovery Manager: Release 12.1.0.2.0 - Production on Sun Feb 7 13:50:21 2016

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

connected to target database: CDB3 (DBID=600505155)
using target database control file instead of recovery catalog

RMAN> backup database;

Starting backup at 07-FEB-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/CDB3/DATAFILE/system01.dbf
input datafile file number=00003 name=/u01/CDB3/DATAFILE/sysaux01.dbf
input datafile file number=00005 name=/u01/CDB3/DATAFILE/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 07-FEB-16
channel ORA_DISK_1: finished piece 1 at 07-FEB-16
piece handle=/u01/CDB3/backupset/2016_02_07/o1_mf_nnndf_TAG20160207T135041_ccfzlt4b_.bkp tag=TAG20160207T135041 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/CDB3/DATAFILE/pdbseed/system01.dbf
input datafile file number=00004 name=/u01/CDB3/DATAFILE/pdbseed/sysaux01.dbf
channel ORA_DISK_1: starting piece 1 at 07-FEB-16
channel ORA_DISK_1: finished piece 1 at 07-FEB-16
piece handle=/u01/CDB3/2B28F662D23A22C2E053FEFF76097A52/backupset/2016_02_07/o1_mf_nnndf_TAG20160207T135041_ccfzmm91_.bkp tag=TAG20160207T135041 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-FEB-16

Starting Control File Autobackup at 07-FEB-16
piece handle=/u01/CDB3/autobackup/2016_02_07/o1_mf_n_903189068_ccfzmogf_.bkp comment=NONE
Finished Control File Autobackup at 07-FEB-16

--------------------Check backup details---------------------

RMAN> list backup of database;


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


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1       Full    409.59M    DISK        00:00:05     07-FEB-16    
        BP Key: 1   Status: AVAILABLE  Compressed: NO  Tag: TAG20160207T135041
        Piece Name: /u01/CDB3/backupset/2016_02_07/o1_mf_nnndf_TAG20160207T135041_ccfzlt4b_.bkp
  List of Datafiles in backup set 1
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 388110     07-FEB-16 /u01/CDB3/DATAFILE/system01.dbf
  3       Full 388110     07-FEB-16 /u01/CDB3/DATAFILE/sysaux01.dbf
  5       Full 388110     07-FEB-16 /u01/CDB3/DATAFILE/undotbs01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2       Full    11.81M     DISK        00:00:00     07-FEB-16    
        BP Key: 2   Status: AVAILABLE  Compressed: NO  Tag: TAG20160207T135041
        Piece Name: /u01/CDB3/2B28F662D23A22C2E053FEFF76097A52/backupset/2016_02_07/o1_mf_nnndf_TAG20160207T135041_ccfzmm91_.bkp
  List of Datafiles in backup set 2
  Container ID: 2, PDB Name: PDB$SEED
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  2       Full 27538      07-FEB-16 /u01/CDB3/DATAFILE/pdbseed/system01.dbf
  4       Full 27538      07-FEB-16 /u01/CDB3/DATAFILE/pdbseed/sysaux01.dbf

RMAN>

RMAN>

RMAN>

RMAN> backup format 'arch_u%% u_s%s_p%p_t%t' archive  log all delete input;

Starting backup at 07-FEB-16
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=22 RECID=1 STAMP=903187943
input archived log thread=1 sequence=23 RECID=2 STAMP=903187958
input archived log thread=1 sequence=24 RECID=3 STAMP=903189793
channel ORA_DISK_1: starting piece 1 at 07-FEB-16
channel ORA_DISK_1: finished piece 1 at 07-FEB-16
piece handle=/u01/app/oracle/product/12.1.0.2/db_1/dbs/arch_u04qtb591_s4_p1_t903189793 tag=TAG20160207T140313 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/CDB3/archivelog/2016_02_07/o1_mf_1_22_ccfyjh1w_.arc RECID=1 STAMP=903187943
archived log file name=/u01/CDB3/archivelog/2016_02_07/o1_mf_1_23_ccfyjyop_.arc RECID=2 STAMP=903187958
archived log file name=/u01/CDB3/archivelog/2016_02_07/o1_mf_1_24_ccg0b931_.arc RECID=3 STAMP=903189793
Finished backup at 07-FEB-16

Starting Control File Autobackup at 07-FEB-16
piece handle=/u01/CDB3/autobackup/2016_02_07/o1_mf_n_903189796_ccg0bf18_.bkp comment=NONE
Finished Control File Autobackup at 07-FEB-16

RMAN> backup current controlfile;

Starting backup at 07-FEB-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 07-FEB-16
channel ORA_DISK_1: finished piece 1 at 07-FEB-16
piece handle=/u01/CDB3/backupset/2016_02_07/o1_mf_ncnnf_TAG20160207T140444_ccg0f5y4_.bkp tag=TAG20160207T140444 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-FEB-16

Starting Control File Autobackup at 07-FEB-16
piece handle=/u01/CDB3/autobackup/2016_02_07/o1_mf_n_903189887_ccg0f756_.bkp comment=NONE
Finished Control File Autobackup at 07-FEB-16

RMAN> list backup of controlfile;


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


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3       Full    17.17M     DISK        00:00:01     07-FEB-16    
        BP Key: 3   Status: AVAILABLE  Compressed: NO  Tag: TAG20160207T135108
        Piece Name: /u01/CDB3/autobackup/2016_02_07/o1_mf_n_903189068_ccfzmogf_.bkp
  Control File Included: Ckp SCN: 388277       Ckp time: 07-FEB-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
5       Full    17.17M     DISK        00:00:01     07-FEB-16    
        BP Key: 5   Status: AVAILABLE  Compressed: NO  Tag: TAG20160207T140316
        Piece Name: /u01/CDB3/autobackup/2016_02_07/o1_mf_n_903189796_ccg0bf18_.bkp
  Control File Included: Ckp SCN: 389098       Ckp time: 07-FEB-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
6       Full    17.17M     DISK        00:00:01     07-FEB-16    
        BP Key: 6   Status: AVAILABLE  Compressed: NO  Tag: TAG20160207T140444
        Piece Name: /u01/CDB3/backupset/2016_02_07/o1_mf_ncnnf_TAG20160207T140444_ccg0f5y4_.bkp
  Control File Included: Ckp SCN: 389156       Ckp time: 07-FEB-16

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
7       Full    17.17M     DISK        00:00:00     07-FEB-16    
        BP Key: 7   Status: AVAILABLE  Compressed: NO  Tag: TAG20160207T140447
        Piece Name: /u01/CDB3/autobackup/2016_02_07/o1_mf_n_903189887_ccg0f756_.bkp
  Control File Included: Ckp SCN: 389163       Ckp time: 07-FEB-16

RMAN>

-----------------Backup database with Archive log ------------

RMAN> backup database plus archivelog;


Starting backup at 07-FEB-16
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=25 RECID=4 STAMP=903190203
channel ORA_DISK_1: starting piece 1 at 07-FEB-16
channel ORA_DISK_1: finished piece 1 at 07-FEB-16
piece handle=/u01/CDB3/backupset/2016_02_07/o1_mf_annnn_TAG20160207T141004_ccg0q43o_.bkp tag=TAG20160207T141004 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-FEB-16

Starting backup at 07-FEB-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/CDB3/DATAFILE/system01.dbf
input datafile file number=00003 name=/u01/CDB3/DATAFILE/sysaux01.dbf
input datafile file number=00005 name=/u01/CDB3/DATAFILE/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 07-FEB-16
channel ORA_DISK_1: finished piece 1 at 07-FEB-16
piece handle=/u01/CDB3/backupset/2016_02_07/o1_mf_nnndf_TAG20160207T141005_ccg0q59m_.bkp tag=TAG20160207T141005 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/CDB3/DATAFILE/pdbseed/system01.dbf
input datafile file number=00004 name=/u01/CDB3/DATAFILE/pdbseed/sysaux01.dbf
channel ORA_DISK_1: starting piece 1 at 07-FEB-16
channel ORA_DISK_1: finished piece 1 at 07-FEB-16
piece handle=/u01/CDB3/2B28F662D23A22C2E053FEFF76097A52/backupset/2016_02_07/o1_mf_nnndf_TAG20160207T141005_ccg0qnfl_.bkp tag=TAG20160207T141005 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-FEB-16

Starting backup at 07-FEB-16
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=26 RECID=5 STAMP=903190221
channel ORA_DISK_1: starting piece 1 at 07-FEB-16
channel ORA_DISK_1: finished piece 1 at 07-FEB-16
piece handle=/u01/CDB3/backupset/2016_02_07/o1_mf_annnn_TAG20160207T141021_ccg0qolc_.bkp tag=TAG20160207T141021 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 07-FEB-16

Starting Control File Autobackup at 07-FEB-16
piece handle=/u01/CDB3/autobackup/2016_02_07/o1_mf_n_903190222_ccg0qps8_.bkp comment=NONE
Finished Control File Autobackup at 07-FEB-16

RMAN> exit


Recovery Manager complete.


----------------------Recover the complete Database from Full RMAN Backup-------------------


If the controlfiles and online redo logs are still present a whole database recovery can be achieved by running the following script.


[oracle@exacell01 dbs]$ rman target / nocatalog

Recovery Manager: Release 12.1.0.2.0 - Production on Sun Feb 7 14:26:21 2016

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

connected to target database: CDB3 (DBID=600505155, not open)
using target database control file instead of recovery catalog


RMAN> RUN {
  SHUTDOWN IMMEDIATE; # use abort if this fails
  STARTUP MOUNT;
  RESTORE DATABASE;
  RECOVER DATABASE;
  
}

Starting recover at 07-FEB-16
using channel ORA_DISK_1

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

Finished recover at 07-FEB-16

RMAN> alter database open;

Statement processed

RMAN> report schema;


Recovery Manager complete.

[oracle@exacell01 dbs]$

---------------------------End of Recovery-----------------


No comments:

Post a Comment