Wednesday, May 21, 2025

Backup Oracle database using rman

Backup an Oracle database using RMAN


1. Connect to RMAN

Open a terminal or command prompt and connect to RMAN as a user with the necessary privileges:


rman target /


2. Perform a Full Database Backup

At the RMAN prompt, run:


BACKUP DATABASE;


3. (Optional) Backup Archive Logs

To include archived redo logs in your backup:


BACKUP DATABASE PLUS ARCHIVELOG;


4. (Optional) Specify Backup Location

To specify a different backup location:


BACKUP DATABASE FORMAT '/backup/yourdb_%U.bkp';


5. (Optional) Backup Control File Separately



BACKUP CURRENT CONTROLFILE;



Note:


Make sure your database is in ARCHIVELOG mode for point-in-time recovery.

Schedule regular backups as per your organization’s policy.



Example 


RMAN> backup database ;


Starting backup at 21-MAY-25

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=42 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/app/oracle/oradata/DB1/system01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/DB1/sysaux01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/DB1/undotbs01.dbf

input datafile file number=00007 name=/u01/app/oracle/oradata/DB1/users01.dbf

channel ORA_DISK_1: starting piece 1 at 21-MAY-25

channel ORA_DISK_1: finished piece 1 at 21-MAY-25

piece handle=/u01/app/oracle/fast_recovery_area/DB1/backupset/2025_05_21/o1_mf_nnndf_TAG20250521T121502_n2vjy7y0_.bkp tag=TAG20250521T121502 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00010 name=/u01/app/oracle/oradata/DB1/pdb/sysaux01.dbf

input datafile file number=00009 name=/u01/app/oracle/oradata/DB1/pdb/system01.dbf

input datafile file number=00011 name=/u01/app/oracle/oradata/DB1/pdb/undotbs01.dbf

input datafile file number=00012 name=/u01/app/oracle/oradata/DB1/pdb/users01.dbf

channel ORA_DISK_1: starting piece 1 at 21-MAY-25

channel ORA_DISK_1: finished piece 1 at 21-MAY-25

piece handle=/u01/app/oracle/fast_recovery_area/DB1/2FACECCE69615207E0630400040AB366/backupset/2025_05_21/o1_mf_nnndf_TAG20250521T121502_n2vjzns9_.bkp tag=TAG20250521T121502 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=00017 name=/u01/app/oracle/oradata/demo1/sysaux01.dbf

input datafile file number=00016 name=/u01/app/oracle/oradata/demo1/system01.dbf

input datafile file number=00018 name=/u01/app/oracle/oradata/demo1/undotbs01.dbf

channel ORA_DISK_1: starting piece 1 at 21-MAY-25

channel ORA_DISK_1: finished piece 1 at 21-MAY-25

piece handle=/u01/app/oracle/fast_recovery_area/DB1/33E6395D57264163E0630400040A2C41/backupset/2025_05_21/o1_mf_nnndf_TAG20250521T121502_n2vk0g8j_.bkp tag=TAG20250521T121502 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=00006 name=/u01/app/oracle/oradata/DB1/pdbseed/sysaux01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/DB1/pdbseed/system01.dbf

input datafile file number=00008 name=/u01/app/oracle/oradata/DB1/pdbseed/undotbs01.dbf

channel ORA_DISK_1: starting piece 1 at 21-MAY-25

channel ORA_DISK_1: finished piece 1 at 21-MAY-25

piece handle=/u01/app/oracle/fast_recovery_area/DB1/2FAC79D13BBE3BB3E0630400040A98FA/backupset/2025_05_21/o1_mf_nnndf_TAG20250521T121502_n2vk17nv_.bkp tag=TAG20250521T121502 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25

Finished backup at 21-MAY-25


Starting Control File and SPFILE Autobackup at 21-MAY-25

piece handle=/u01/app/oracle/fast_recovery_area/DB1/autobackup/2025_05_21/o1_mf_s_1201695424_n2vk22pc_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 21-MAY-25


RMAN>

Recovery Window and Redundancy in RMAN

In Oracle RMAN (Recovery Manager), the recovery window is a key concept used to define your backup retention policy. It specifies the period of time (in days) for which you want to be able to recover your database to any point in time. RMAN uses this window to determine which backups and archived logs to retain and which can be deleted.



What is the Recovery Window?


The recovery window is the number of days into the past that you want your database to be recoverable.

For example, if you set a recovery window of 7 days, RMAN will keep all backups and archived logs needed to restore and recover the database to any point within the last 7 days.


How Recovery Window Works?


RMAN considers a backup as obsolete if it is no longer needed to satisfy the recovery window.

When you run DELETE OBSOLETE, RMAN removes backups and archived logs that are outside the recovery window.


Setting the Recovery Window

You set the recovery window using the CONFIGURE RETENTION POLICY command:


This tells RMAN to retain all backups and archived logs required for point-in-time recovery within the last 7 days.


Example Scenario

Suppose today is May 21, and you set a recovery window of 7 days.


RMAN will keep all backups and archived logs needed to recover the database to any point between May 14 and May 21.

Any backups or logs older than May 14 that are not needed for recovery within this window are considered obsolete.


Checking the Retention Policy

You can check your current retention policy with:

RMAN> SHOW RETENTION POLICY;


Deleting Obsolete Backups

To remove backups and archived logs that are outside the recovery window, use:

RMAN> DELETE OBSOLETE;


Recovery Window vs. Redundancy


Recovery Window: Retains backups based on time (e.g., last 7 days).

Redundancy: Retains a specific number of backup copies (e.g., last 2 backups).

You can only have one retention policy active at a time (either recovery window or redundancy).


Best Practices

Set the recovery window based on your business requirements for point-in-time recovery.

Regularly run DELETE OBSOLETE to free up storage.

Monitor backup and recovery operations to ensure compliance with your retention policy.


Multiple ways to connect with rman - Oracle database

Multiple ways to connect with rman to oracle database 


1->

[oracle@orcl dbs]$

[oracle@orcl dbs]$

[oracle@orcl dbs]$ rman target "' / as sysdba'"


Recovery Manager: Release 19.0.0.0.0 - Production on Wed May 21 11:38:04 2025

Version 19.3.0.0.0


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


connected to target database: DB1 (DBID=1788905834)


RMAN>


2->


[oracle@orcl dbs]$

[oracle@orcl dbs]$

[oracle@orcl dbs]$ rman target /


Recovery Manager: Release 19.0.0.0.0 - Production on Wed May 21 11:38:26 2025

Version 19.3.0.0.0


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


connected to target database: DB1 (DBID=1788905834)


RMAN>



3->


[oracle@orcl dbs]$

[oracle@orcl dbs]$

[oracle@orcl dbs]$ rman target /


Recovery Manager: Release 19.0.0.0.0 - Production on Wed May 21 11:38:26 2025

Version 19.3.0.0.0


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


connected to target database: DB1 (DBID=1788905834)


RMAN>



4->


[oracle@orcl dbs]$

[oracle@orcl dbs]$

[oracle@orcl dbs]$ rman target sys/sys


Recovery Manager: Release 19.0.0.0.0 - Production on Wed May 21 11:42:47 2025

Version 19.3.0.0.0


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


connected to target database: DB1 (DBID=1788905834)


RMAN>


RMAN>


How to configure the size of Fast Recovery Area (FRA) in Oracle database ?

Configure the size of FRA 

 


SQL>

SQL>

SQL> show parameter db_recovery


NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

db_recovery_file_dest                string      /u01/app/oracle/fast_recovery_

                                                 area

db_recovery_file_dest_size           big integer 12732M

SQL>

SQL>

SQL> alter system set db_recovery_file_dest_size=12G scope=both ;


System altered.


SQL> show parameter db_recovery_file_dest_size;


NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

db_recovery_file_dest_size           big integer 12G

SQL>