You want to backup your Oracle Database and wandering how ? Here is a simple way to backup database. But before we start we need to decide if we want to backup database in Online mode of backup in Offline Mode.
Online Backup : Advantage of online backup is that database keeps running and backup can be done in parallel. But since database is running in parallel we also need to backup the archive logs and apply them while restoring the backup. Also Database needs to be in archive log mode before starting the backup, steps to put database in archive log mode.
Offline Backup : In offline backup database needs to be shutdown before we start the backup. Also we don’t need to backup archive logs since the database is not running and no additionally media recovery step while restoring database.
Database Backup Steps Online Mode
1. Create RMAN sql file
run{
allocate channel ch1 device type disk format '<your backup location>/%U';
backup database plus archivelog;
backup as copy current controlfile format '<your backup location>/cntrl01.ctl';
release channel ch1;
}
Allocating more channels increases the parallelism in backup process. So we can allocate more channels like
allocate channel ch1 device type disk format ‘<your backup location>/%U’
allocate channel ch2 device type disk format ‘<your backup location>/%U’
.
.
backup commands
.
.
release channel ch1;
release channel ch2;
we can add a tag name to backup with
backup tag '<tagname>' database plus archivelog;
Also if we are backing up database in offline mode we can skip ‘plus archivelog’, and just say
backup tag ‘<tagname>’ database;
In case backup need to be compressed we can use ‘compressed backupset’ like following
backup tag 'mybkp' as compressed backupset database plus archivelog;
%U is specified to let rman decide the backup filenames. There are some more file name formats which can be specified. You can check oracle rman website for more on filenames. Also by specifying the location we are overriding the default backup location.
The next line is to backup the control file. It is good to copy control file specially if we are planning to restore database in a new environment. Same as database backup we add tag name to control file by following
backup tag '<control-file tag name>' as copy current controlfile format '<your backup location>/cntrl01.ctl';
So we have created following sql file /home/user1/MyBackup.sql
run{
allocate channel ch1 device type disk format '/u01/backup/mydb/%U';
backup tag database plus archivelog;
backup as copy current controlfile format '/u01/backup/mydb/cntrl01.ctl';
release channel ch1;
}
Now lets us run the sql file we have created.
1. Set env vars
$export ORACLE_HOME=/u01/app/oracle/11.2.0/dbhome_1
$export ORACLE_SID=mydb
2. Connect target using rman client
$ORACLE_HOME/bin/rman target
Recovery Manager: Release 11.2.0.2.0 - Production on Mon Jun 4 15:57:33 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: MYDB (DBID=XXXXX)
/
This command will open rman prompt and connect the database whose SID is set in the ORACLE_SID.
Since we not specified the username and password, the current user need to be part of dba group.
Alternatively we can use username and password
$ORACLE_HOME/rman target sys/welcome@mydb
3. Run Backup SQL file
RMAN>/home/user1/MyBackup.sql
OUTPUT
RMAN> run{
2> allocate channel ch1 device type disk format '/u01/backup/mydb/%U';
3> backup database plus archivelog;
4> backup as copy current controlfile format '/u01/backup/mydb/cntrl01.ctl';
5> release channel ch1;
6> }
using target database control file instead of recovery catalog
allocated channel: ch1
channel ch1: SID=48 device type=DISK
Starting backup at 04-JUN-12
current log archived
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
channel ch1: starting piece 1 at 04-JUN-12
channel ch1: finished piece 1 at 04-JUN-12
piece handle=/u01/backup/mydb/06ncmve9_1_1 tag=TAG20120604T155903 comment=NONE
channel ch1: backup set complete, elapsed time: 00:01:15
Finished backup at 04-JUN-12
Starting backup at 04-JUN-12
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
input datafile file number=00001 name=+DATADB/mydb/system01.dbf
input datafile file number=00002 name=+DATADB/mydb/sysaux01.dbf
input datafile file number=00003 name=+DATADB/mydb/undotbs01.dbf
input datafile file number=00004 name=+DATADB/mydb/users01.dbf
channel ch1: starting piece 1 at 04-JUN-12
channel ch1: finished piece 1 at 04-JUN-12
piece handle=/u01/backup/mydb/07ncmvgm_1_1 tag=TAG20120604T160022 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:35
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ch1: starting piece 1 at 04-JUN-12
channel ch1: finished piece 1 at 04-JUN-12
piece handle=/u01/backup/mydb/08ncmvhp_1_1 tag=TAG20120604T160022 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 04-JUN-12
Starting backup at 04-JUN-12
current log archived
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=29 RECID=28 STAMP=785088060
channel ch1: starting piece 1 at 04-JUN-12
channel ch1: finished piece 1 at 04-JUN-12
piece handle=/u01/backup/mydb/09ncmvhs_1_1 tag=TAG20120604T160100 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 04-JUN-12
Starting backup at 04-JUN-12
channel ch1: starting datafile copy
copying current control file
output file name=/u01/backup/mydb/cntrl01.ctl tag=TAG20120604T160101 RECID=2 STAMP=785088062
channel ch1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 04-JUN-12
released channel: ch1
RMAN> **end-of-file**
Running this command will store backup in /u01/backup/mydb..as we can see here
$ls -l /u01/backup/mydb/
total 2176972
-rw-r----- 1 dbuser dba 1013575680 Jun 4 16:00 06ncmve9_1_1
-rw-r----- 1 dbuser dba 1193861120 Jun 4 16:00 07ncmvgm_1_1
-rw-r----- 1 dbuser dba 9830400 Jun 4 16:00 08ncmvhp_1_1
-rw-r----- 1 dbuser dba 4096 Jun 4 16:01 09ncmvhs_1_1
-rw-r----- 1 dbuser dba 9748480 Jun 4 16:01 cntrl01.ctl