Please see my other blog for Oracle EBusiness Suite Posts - EBMentors

Search This Blog

Note: All the posts are based on practical approach avoiding lengthy theory. All have been tested on some development servers. Please don’t test any post on production servers until you are sure.

Monday, February 25, 2013

RMAN: Taking Cold backup using RMAN and restore it


Cold backup is particular useful when you plan to test some changes on the database and in case something goes wrong you can always fall back to this Cold backup.

Cold backup is a consistent backup when the database has been shutdown immediate or Shutdown Normal.If the database is shutdown with abort option then its not a consistent backup.
Cold backup can be taken by RMAN in mount stage after database has been shutdown immediate.




Backup
1- Ensure all files are online and none of the files are in recovery status
SQL> select distinct(status),count(*) from v$datafile group by status;

STATUS    COUNT(*)
------- ----------
ONLINE           6
SYSTEM           1

Should show system and Online. System status is for datafiles from the system tablespace.Other datafiles should show status online
Once confirmed all files are online . Spool details of the database
SQL> spool c:\temp\dbdetail.txt
SQL>Select name ,file#,ts#,status$ from v$datafile ;
SQL>Select * from v$logfile ;
SQL> select * from v$controlfile;
SQL> Spool off


2- Shutdown immediate the database and Startup mount. If database is RAC, ensure you shutdown immediate all the instance and startup mount only one instance after that.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size                  2262048 bytes
Variable Size             624954336 bytes
Database Buffers          436207616 bytes
Redo Buffers                5513216 bytes
Database mounted.

3- Now connect with RMAN, ensure controlfile autobackup is set to on. If not set it to On

C:\Users\inam.HOME>rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on Mon Feb 25 11:43:33 2013
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database: ORCL (DBID=1336013077, not open)

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;

using target database control file instead of recovery catalog
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored

4- Take the database backup using RMAN script.
run{
    allocate channel c1 device type disk;
        backup database tag 'coldbackup20130225';
    }


If you want to use format option to backup the database to a specific location you can use the following syntax

rman> backup database format 'C:\temp\backup\%U';
rman> backup database format '+DBDATA';

RMAN> spool log to 'C:\temp\rmanbkpORCL.log'




RMAN> SPOOL LOG OFF;
Spooling for log turned off
Recovery Manager11.2.0.3.0

5- Verify the backup validity

RMAN> list backup tag 'COLDBACKUP20130225';
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1 Full 1.06G DISK 00:00:40 25-FEB-13
BP Key: 1 Status: AVAILABLE Compressed: NO Tag: COLDBACKUP20130225
Piece Name: C:\APP\INAM\FAST_RECOVERY_AREA\ORCL\BACKUPSET\2013_02_25\O1_MF_NNNDF_COLDBACKUP20130225_8LP9BZGX_.BKP
List of Datafiles in backup set 1
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 1109935 25-FEB-13 C:\APP\INAM\ORADATA\ORCL\SYSTEM01.DBF
2 Full 1109935 25-FEB-13 C:\APP\INAM\ORADATA\ORCL\SYSAUX01.DBF
3 Full 1109935 25-FEB-13 C:\APP\INAM\ORADATA\ORCL\UNDOTBS01.DBF
4 Full 1109935 25-FEB-13 C:\APP\INAM\ORADATA\ORCL\USERS01.DBF
5 Full 1109935 25-FEB-13 C:\APP\INAM\ORADATA\ORCL\EXAMPLE01.DBF
6 Full 1109935 25-FEB-13 C:\APP\INAM\ORADATA\ORCL\TS01.DBF
7 Full 1109935 25-FEB-13 C:\APP\INAM\ORADATA\ORCL\TSNEW.DBF

RMAN> validate backupset 1;
Starting validate at 25-FEB-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting validation of datafile backup set
channel ORA_DISK_1: reading from backup piece C:\APP\INAM\FAST_RECOVERY_AREA\ORCL\BACKUPSET\2013_02_25\O1_MF_NNNDF_COLDB
ACKUP20130225_8LP9BZGX_.BKP
channel ORA_DISK_1: piece handle=C:\APP\INAM\FAST_RECOVERY_AREA\ORCL\BACKUPSET\2013_02_25\O1_MF_NNNDF_COLDBACKUP20130225
_8LP9BZGX_.BKP tag=COLDBACKUP20130225
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: validation complete, elapsed time: 00:00:15
Finished validate at 25-FEB-13


6- Take a backup of your redo logs also using OS command(Optional)
In addition to take cold backup of database, also take backup of online redo logs.(Cold backup normally does not require this )

SQL>Select member from v$logfile ;
Take a OS level copy of the same.

Once done shutdown immediate.
Ensure you keep a copy of the spfile also.
Also keep a binary copy of controlfile

Restore
Assuming in this case the cold backup has been taken with Tag 'COLDBACKUP20130225' as above.

1- Nomount the database
SQL> startup nomount
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size 2262048 bytes
Variable Size 624954336 bytes
Database Buffers 436207616 bytes
Redo Buffers 5513216 bytes



2- Restore controlfile from the backuppiece using RMAN.

RMAN> restore controlfile from 'C:\app\Inam\fast_recovery_area\orcl\AUTOBACKUP\2013_02_25\O1_MF_S_808314079_8LP9DGR9_.BKP';

Starting restore at 25-FEB-13
using channel ORA_DISK_1

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=C:\APP\INAM\ORADATA\ORCL\CONTROL01.CTL
output file name=C:\APP\INAM\FAST_RECOVERY_AREA\ORCL\CONTROL02.CTL
Finished restore at 25-FEB-13


3- Mount the database
RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

4- Restore database
RMAN> restore database from tag 'coldbackup20130225';
++++++++++


5- Open the database with restelogs
RMAN> alter database open resetlogs;

database opened

No comments: