RMAN

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

RMAN RUNBOOK

G, Neeraj 2/26/19 DBA


What is Oracle Backup and its Different Types
A database backup is a copy of data that can be used to reconstruct the
data. Oracle backup types can be divided into two categories.
 Physical backups.
Physical backups are copies of the physical files. These files include
datafiles, control files, and archived redo logs. Every physical backup is
a copy of files that store database information to another location,
whether on disk or on offline storage media such as tape.
 Logical backups.
Logical backups contain logical data such as tables and stored procedures.
Logical backups are a useful supplement to physical backups in many
circumstances but are not sufficient protection against data loss without
physical backups.
Physical backups are the foundation of any sound backup and recovery
strategy. Logical backups are a useful supplement to physical backups.
The term "backup" as used in the oracle backup and recovery refers to
physical backups, and to back up part or all of your database is to take
some kind of physical backup.

Consistent and inconsistent backups


A physical backup can be classified by being a consistent or an inconsistent
backup.
Consistent backup
1. All datafiles have the same SCN; in other words, all changes in the redo logs
have been applied to the datafiles.
2. It is rare that an open database backup can be considered consistent.
3. Consistent backups are taken when the database is shut down normally or in a
MOUNT state.
Inconsistent backup
1. Is performed while the database is open and users are accessing the database.
2. Typically, SCNs of the datafiles typically do not match when an inconsistent
backup is taking place, a recovery operation performed using an inconsistent
backup must rely on both archived and online redo log files to bring the
database into a consistent state before it is opened.
3. Database must be in ARCHIVELOG mode to use an inconsistent backup method.

Full and Incremental Backups


Full backups

 Include all blocks of every datafile within a tablespace or a database;


 it is essentially a bit-for-bit copy of one or more datafiles in the database.
 Can be created with RMAN or with OS-level file copy commands

Incremental backups
Backup of block level changes to database made after previous
incremental/full backup. can be level 0 or level 1.

 “Level 0? Incremental backup - This backs up all blocks in database. This is


equivalent to full backup.

 “level 1? Incremental backup- This backs up database block changes after previous
incremental backup. If there is no level 0 incremental backup and you run
level 1 incremental backup, RMAN will automatically make level 0
incremental backup.

Cumulative incremental backup –


level 1 incremental backup which includes all blocks changed since most
recent level 0 incremental backup. cumulative backups may take more time
and space than non- cumulative, however only one cumulative backup from
any level will be needed for recovery
Differential incremental backup –
level 1 incremental backup which includes only block changed since most
recent incremental backup. By default, incremental backups are
differential

 A distinct advantage to using an incremental backup in a recovery strategy


is that archived and online redo log files may not be necessary to restore
a database or tablespace to a consistent state
 The incremental backups may have some or all of the blocks needed.
 Incremental backups can only be performed within RMAN.
 incremental backups can only be performed on datafiles, and not on control
files or archived redo logs.
 if the incremental keyword is not included, by default recovery manager
will perform a full backup.
 During recovery, incremental backups are chosen by recovery manager, and
applied automatically
 in the case that archived redo logs were not successfully backed up (or
were corrupted), incremental backups offer a way of making the datafile
newer without needing this redo. conversely, if the tape that an
incremental backup resides on is corrupt, archived redo logs can be used
to roll forward.
 Incremental backups can be applied in parallel to multiple datafiles
concurrently.
 Much less redo is applied during recovery.
Online Database Backup (HOT BACKUP)
An online backup or also known as an open backup or Hot backup, is a
backup in which all read-write datafiles and control files have not been
check pointed with respect to the same SCN. For example, one read-write
datafile header may contain an SCN of 100 while other read-write datafile
headers contain an SCN of 95 or 90. Oracle cannot open the database until
all of these header SCNs are consistent, that is, until all changes
recorded in the online redo logs have been saved to the datafiles on disk.
If the database must be up and running 24 hours a day, 7 days a week, then
you have no choice but to perform online backups of a whole database which
is in ARCHIVELOG mode.

Offline Database Backup (COLD BACKUP)


Backup taken while Oracle database is down or in mount state NOT OPEN. In
this backup, all datafiles and control files are consistent to the same
point in time - consistent with respect to the same SCN, for example. The
only tablespaces in a consistent backup that are allowed to have older
SCNs are read-only and offline-normal tablespaces, which are consistent
with the other datafiles in the backup. This type of backup allows the
user to open the set of files created by the backup without applying redo
logs, since the data is already consistent. The only way to perform this
type of backup is to shut down the database cleanly and make the backup
while the database is closed. A consistent whole database backup is the
only valid backup option for databases running in NOARCHIVELOG mode.

Image Copies

 Image copy is a bit-for-bit identical copy of a DB file


 Image copies are full backups created by operating system commands or RMAN
backup as copy commands.
 Image copies are the default backup file format in RMAN.
 By creating image copies using RMAN, all datafiles will automatically be
included in the backup.

Backupsets and Backup Pieces

 Backup set is a collection of files called backup pieces, each of which


may contain the backup of one or several database files
 Backupsets can be created and restored only with RMAN.
 Each backup piece belongs to only one backupset.
 All Backupsets and pieces are recorded in the RMAN repository
Compressed Backups

 Compression is available to reduce the amount of disk space or tape needed


to store the backup.
 Compressed backups are only usable by RMAN
 Need no special processing when used in a recovery operation;
 RMAN automatically decompresses the backup.
 Creating compressed backups is as easy [as compressed backupset]

Whole Database Backup


The most common type of backup, a whole database backup contains the
control file along with all database files that belong to a database. If
operating in ARCHIVELOG mode, the DBA also has the option of backing up
different parts of the database over a period of time, thereby
constructing a whole database backup piece by piece.

Tablespace Backups
A tablespace backup is a subset of the database. Tablespace backups are
only valid if the database is operating in ARCHIVELOG mode. The only time
a tablespace backup is valid for a database running in NOARCHIVELOG mode
is when that tablespace is read-only or offline-normal.

Datafile Backups
A datafile backup is a backup of a single datafile. Datafile backups,
which are not as common as tablespace backups and are only valid if the
database is run in ARCHIVELOG mode. The only time a datafile backup is
valid for a database running in NOARCHIVELOG mode is if that datafile is
the only file in a tablespace. For example, the backup is a tablespace
backup, but the tablespace only contains one file and is read-only or
offline-normal.

Control File Backups


A control file backup is a backup of a database's control file. If a
database is open, the user can create a valid backup by issuing the
following SQL statement: ALTER DATABASE BACKUP CONTROLFILE to 'location';
or use Recovery Manager (RMAN).

Archived Redo Log Backups


Archived redo logs are the key to successful media recovery. Depending on
the disk space available and the number of transactions executed on the
database, you want to keep as many days of archive logs on disk and you
want to back them up regularly to ensure a more complete recovery.

Configuration Files Backups


Configuration files may consist of spfile or init.ora, password file,
tnsnames.ora, and sqlnet.ora. Since these files do not change often, then
they require a less frequent backup schedule. If you lost a configuration
file it can be easily recreated manually. When restore time is a premium,
it will be faster to restore a backup of the configuration file then
manually creating a file with a specific format.

To Take Hot Backup Archive log mode must be Enabled.

One can Enable Archive log mode by following these Steps.

Enter the following SQL commands:


SQL> Shutdown
SQL> Startup mount
SQL> Alter database archivelog;
SQL> alter database open;

To check the ARCHIVELOG mode status


SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 7
Next log sequence to archive 9
Current log sequence 9

Then one can start using RMAN

To Connect to RMAN
[oracle@ue1usboxora501 ~] $ rman target /

Recovery Manager: Release 12.2.0.1.0 - Production on Tue Feb 26 02:55:21 2019

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

connected to target database: ORCL (DBID=1515531025)


To perform a full database backup use:
RMAN> BACKUP DATABASE;

To backup all archive logs use:


RMAN> BACKUP ARCHIVELOG ALL;

To backup the current controlfile explicitly use:


RMAN> BACKUP CURRENT CONTROLFILE;

The format clause allows the backup files to be directed to a specific location

For example:
BACKUP FORMAT '/u01/app/oracle/backup/%U' DATABASE;
Other format options are listed below.

Syntax
Element Description

%s Specifies the backup set number. This number is a counter in the control file that is incremented for each
backup set. The counter value starts at 1 and is unique for the lifetime of the control file. If you restore a
backup control file, then duplicate values can result. Also, CREATE CONTROLFILE initializes the counter back
to 1.

%t Specifies the backup set time stamp, which is a 4-byte value derived as the number of seconds elapsed
since a fixed reference time. You can use a combination of %s and %t to form a unique name for the backup
set.

%T Specifies the year, month, and day in the Gregorian calendar in this format: YYYYMMDD.

%u Specifies an 8-character name constituted by compressed representations of the backup set or image copy
number and the time the backup set or image copy was created.

%U Specifies a system-generated unique file name (default).

The meaning of %U is different for image copies and backup pieces. For a backup piece, %U specifies a
convenient shorthand for %u_%p_%c that guarantees uniqueness in generated backup file names. For an
image copy of a data file, %Umeans the following:

data-D-%d_id-%I_TS-%N_FNO-%f_%u

For an image copy of an archived redo log, %U means the following:

arch-D_%d-id-%I_S-%e_T-%h_A-%a_%u

For an image copy of a control file, %U means the following:

cf-D_%d-id-%I_%u

%Y Specifies the year in this format: YYYY.

%% Specifies the percent (%) character. For example, %%Y translates to the string %Y.

To backup up the SPFILE explicitly use:


RMAN> BACKUP SPFILE;
To backup a specific data file use BACKUP DATAFILE. For example
RMAN> BACKUP DATAFILE ' FRA/ORCL/DATAFILE/nrjtbs.dbf’;

One can do datafile backup by specifying file number also for that you need to

Check by:
SQL> SELECT file#, name FROM v$datafile;

After this

I wanted to take a backup of nrjtbs.dbf datafile so I just need to give file#(number)

To backup a tablespace use the BACKUP TABLESPACE command. For example:

Check using this query. (tablespaces present in


DB)
select TABLESPACE_NAME from dba_tablespaces;

RMAN> BACKUP TABLESPACE USERS;


To compress the backup use:
RMAN> BACKUP AS COMPRESSED BACKUPSET DATABASE;

A backup tag can optionally be specified with the BACKUP command.


BACKUP DATABASE TAG = 'Full_Backup';

Incremental backups can be:

 Differential - includes all changes since the last full or incremental backup
 Cumulative - includes all changes since the last full backup

Differential backups require less space; Cumulative backups are faster to restore

Differential backups are the default.

To run a Differential incremental backup use:

RMAN> BACKUP INCREMENTAL LEVEL 1 DATABASE;

To run a cumulative incremental backup use:

RMAN> BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;


In order to take a level 0 backup use

RMAN> BACKUP INCREMENTAL LEVEL 0 DATABASE;

To create an image copy of an entire database use:

RMAN> BACKUP AS COPY DATABASE;

CRONTAB - Crontab is a file which contains the schedule of cron entries to be run and at specified times. File
location varies by operating systems, See Crontab file location at the end of this document.
CRONTAB COMMANDS:

crontab -e : Edit crontab file, or create one if it doesn’t already exist.


crontab –l : crontab list of Cronjobs, display crontab file contents.
crontab -r : Remove your crontab file. (DON’T USE THIS UNTIL & UNLESS ABSOLUTLEY NECESSARY)

Crontab Entries:
For Reference im attaching Cron entries
CRONTAB
ENTRIES_TEXT FORMAT.txt
Please go through .txt file

How to Schedule ADRCI Entry.


I’m Attaching purge_adr_logs.ksh text file (You should save as.ksh)

purge_adr_logs.ksh

The Directory which I used is


/home/oracle/epsilon/scripts/monitor/purge_adr_logs.ksh this directory
should be same in Crontab also.
Crontab –e is used to edit or make entry of cornjob in crontab.
Inside the same directory log file also should be created, after creating permissions should be set for that PWD
(Present Working Directory)
##Schema Stats

10 02 * * * /home/oracle/epsilon/scripts/statistics/gather_schema_stats.ksh -s
d1gmcc -e gmcc_ora_dba@epsilon.com -F -f d1gmcc_schemas.dat >
/home/oracle/epsilon/scripts/statistics/log/gather_schema_stats_d1gmcc.out 2>&1

For this supporting file is d1gmcc_schemas.dat and this should be present in dat folder.

##DB HEALTH REPORT

10 2 * * * /home/oracle/epsilon/scripts/healthreports/health_check_d1gmcc.ksh >
/home/oracle/epsilon/scripts/healthreports/log/health_check_d1gmcc.log 2>&1

This entry is for health report on db from this we can know the SID name, Tablespace space, ASM Disk space,
full Backup history, Archive log Backup history, Top 5 SQL with highest I/O in last 24 Hrs etc.

Ex: snapshot of . ksh script

These are the changed to be made.

 mypath = ”where the .ksh & supporting files stored.”


 export ORACLE_SID= “Name of DB”.
 export SUBJECT= “subject to be displayed in mail ”
 export SCRIPT_HOME= ”where the .ksh & supporting files stored.”
 export ORACLE_HOME= “ path to DB home”
 export MAIL_FROM=”server name / hostname “
 export MAIL_TO='email address'

Along with .ksh script two more .sql files are also required.

overall_check.sql perf_check.sql

Note: - LOG should be created. so that we can check for errors or warning in execution.

You might also like