Navigation Bar

Wednesday, October 16, 2024

Oracle database cold backup - NOARCHIVELOG mode

In any commercial setup involving large volumnes and critcal data, a good backup strategy is very essential to ensure data security, availability and recoverability. 
There are two main backup methods
Hot Backup and Cold Backup

A Hot backup is taken when the database is online and users are accessing and modifying the data.
A hot backup is taken when High Availability is the main criteria for the database like in a banking or in healthcare scenario.

A Cold backup in oracle refers to the process of taking a backup when the database is in mount state or shutdown. During such a backup all the datafiles,  control files, redolog files etc are copied to the backup area when the database is not running, so it ensures a consistent snapshot of the database at the time the backup was initiated.  In this all the read/write datafiles, control files have the same SCN.   
Cold backups are generally taken by taking a downtime of the production database. Example - At night time or on weekends when users will not be accessing the database.

Below are the steps to take a cold backup using RMAN.
Set the required environment variables
set ORACLE_HOME=E:\install\21cXE\dbhomeXE
set ORACLE_SID=XE
set PATH=%ORACLE_HOME%/bin:%PATH%
set LD_LIBRARY_PATH=%ORACLE_HOME%/lib
E:\technical\blogs\RMAN>rman target sys/oracle123

Recovery Manager: Release 21.0.0.0.0 - Production on Tue Oct 15 08:51:23 2024
Version 21.3.0.0.0

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

connected to target database: XE (DBID=3051269637)

sql 'alter system checkpoint';
using target database control file instead of recovery catalog
sql statement: alter system checkpoint

RMAN> shutdown immediate;

database closed
database dismounted
Oracle instance shut down
Mount the database
RMAN> startup mount;
connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area    1610608792 bytes

Fixed Size                     9855128 bytes
Variable Size                973078528 bytes
Database Buffers             620756992 bytes
Redo Buffers                   6918144 bytes
In RMAN prompt or sqlplus prompt create the pfile. 
SQL> create pfile='E:\technical\blogs\RMAN\backup\pfileXE.ora' from spfile;
In RMAN run the rman script to backup the database and control file.
RMAN>
RUN {
ALLOCATE CHANNEL disk1 DEVICE TYPE DISK FORMAT 'E:\technical\blogs\RMAN\backup\%U';
ALLOCATE CHANNEL disk2 DEVICE TYPE DISK FORMAT 'E:\technical\blogs\RMAN\backup\%U';
ALLOCATE CHANNEL disk3 DEVICE TYPE DISK FORMAT 'E:\technical\blogs\RMAN\backup\%U';
BACKUP AS COMPRESSED BACKUPSET DATABASE;
BACKUP CURRENT CONTROLFILE FORMAT 'E:\technical\blogs\RMAN\backup/cntrl_%s_%p_%t';
RELEASE CHANNEL disk1;
RELEASE CHANNEL disk2;
RELEASE CHANNEL disk3;
}

Steps to restore a cold RMAN backup 

Once backup is created we can restore the database on the same server and directory path structure as follows. We drop the existing database.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount exclusive restrict;
ORACLE instance started.

Total System Global Area 1610608792 bytes
Fixed Size                  9855128 bytes
Variable Size             973078528 bytes
Database Buffers          620756992 bytes
Redo Buffers                6918144 bytes
Database mounted.
SQL> select name, open_mode from v$database;

NAME      OPEN_MODE
--------- --------------------
XE        MOUNTED

SQL> drop database;

Database dropped.

  We restore the database using RMAN commands as follows
RMAN>
run
{
startup pfile='E:\technical\blogs\RMAN\backup\PFILEXE.ORA' nomount;
restore controlfile from 'E:\technical\blogs\RMAN\backup\CNTRL_9_1_1182419316';
alter database mount;
restore database;
alter database open resetlogs;
}

Oracle instance started

Total System Global Area    1610608792 bytes

Fixed Size                     9855128 bytes
Variable Size                973078528 bytes
Database Buffers             620756992 bytes
Redo Buffers                   6918144 bytes


Starting restore at 17-OCT-24
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=137 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
output file name=E:\INSTALL\21CXE\ORADATA\XE\CONTROL01.CTL
output file name=E:\INSTALL\21CXE\ORADATA\XE\CONTROL02.CTL
Finished restore at 17-OCT-24

released channel: ORA_DISK_1
Statement processed

Starting restore at 17-OCT-24
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=137 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 00001 to E:\INSTALL\21CXE\ORADATA\XE\SYSTEM01.DBF
channel ORA_DISK_1: restoring datafile 00007 to E:\INSTALL\21CXE\ORADATA\XE\USERS01.DBF
channel ORA_DISK_1: reading from backup piece E:\TECHNICAL\BLOGS\RMAN\BACKUP\0137KI7S_1_1_1
channel ORA_DISK_1: piece handle=E:\TECHNICAL\BLOGS\RMAN\BACKUP\0137KI7S_1_1_1 tag=TAG20241015T094634
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:55
...
...
...
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 00005 to E:\INSTALL\21CXE\ORADATA\XE\PDBSEED\SYSTEM01.DBF
channel ORA_DISK_1: reading from backup piece E:\TECHNICAL\BLOGS\RMAN\BACKUP\0737KIB1_7_1_1
channel ORA_DISK_1: piece handle=E:\TECHNICAL\BLOGS\RMAN\BACKUP\0737KIB1_7_1_1 tag=TAG20241015T094634
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00: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 00008 to E:\INSTALL\21CXE\ORADATA\XE\PDBSEED\UNDOTBS01.DBF
channel ORA_DISK_1: reading from backup piece E:\TECHNICAL\BLOGS\RMAN\BACKUP\0837KIBG_8_1_1
channel ORA_DISK_1: piece handle=E:\TECHNICAL\BLOGS\RMAN\BACKUP\0837KIBG_8_1_1 tag=TAG20241015T094634
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
Finished restore at 17-OCT-24

Statement processed  

Steps to backup and restore the physical oracle datafiles at OS Level
We first query the v$datafile data dictionary view to find the location of all the datafiles, redolog files, control files etc.
select name "DATAFILE NAME" from v$datafile;
DATAFILE NAME
E:\INSTALL\21CXE\ORADATA\XE\SYSTEM01.DBF
E:\INSTALL\21CXE\ORADATA\XE\SYSAUX01.DBF
E:\INSTALL\21CXE\ORADATA\XE\UNDOTBS01.DBF
E:\INSTALL\21CXE\ORADATA\XE\PDBSEED\SYSTEM01.DBF
E:\INSTALL\21CXE\ORADATA\XE\PDBSEED\SYSAUX01.DBF
E:\INSTALL\21CXE\ORADATA\XE\USERS01.DBF
E:\INSTALL\21CXE\ORADATA\XE\PDBSEED\UNDOTBS01.DBF
E:\INSTALL\21CXE\ORADATA\XE\XEPDB1\SYSTEM01.DBF
E:\INSTALL\21CXE\ORADATA\XE\XEPDB1\SYSAUX01.DBF
E:\INSTALL\21CXE\ORADATA\XE\XEPDB1\UNDOTBS01.DBF
E:\INSTALL\21CXE\ORADATA\XE\XEPDB1\USERS01.DBF
E:\INSTALL\21CXE\ORADATA\XE\XEPDB1\HR.DBF
select member from v$logfile; 
REDOLOG MEMBER
E:\INSTALL\21CXE\ORADATA\XE\REDO03.LOG
E:\INSTALL\21CXE\ORADATA\XE\REDO02.LOG
E:\INSTALL\21CXE\ORADATA\XE\REDO01.LOG
select name from v$controlfile; 
CONTROLFILE NAME
E:\INSTALL\21CXE\ORADATA\XE\CONTROL01.CTL
E:\INSTALL\21CXE\ORADATA\XE\CONTROL02.CTL

Copy all these files from the directory paths shown above to the backup folder path
Source folder of oradata file
E:\install\21cXE\oradata\XE

Backup folder
E:\database\cold_backup\XE

Restore the physical oracle datafiles at OS Level
Startup the database in mount exclusive restrict mode and drop the database
Now the datafiles, redolog files, control files will all be deleted.
Copy the datafiles, redolog files and control files from the backup folder to the source folder.
Startup the database.
The database will open
SQL> startup
ORACLE instance started.

Total System Global Area 1610608792 bytes
Fixed Size                  9855128 bytes
Variable Size             973078528 bytes
Database Buffers          620756992 bytes
Redo Buffers                6918144 bytes
Database mounted.
Database opened.

References
RMAN cold backup and restore
Oracle physical database cold backup and restore

Thought for the day
Whoever digs a pit will fall into it; And a stone will come back on the one who starts it rolling. 
A lying tongue hates those its victims, and a flattering mouth works ruin.

Proverbs26:27-28

No comments:

Post a Comment