Rman Backup Examples
Rman Backup Examples
Contents
1. RMAN Default Configuration Parameters
2. Offline Backup - (using configured defaults)
3. Offline Backup - (without using configured defaults)
4. Backup Archive Logs (All)
5. Online Backup - (using configured defaults)
6. Keeping Backups
7. Incremental Backups
8. Mirroring Backups
9. Copying Disk Backup to Tape
10. Backup Failures
RMAN> shutdown
RMAN> startup mount
RMAN> run {
2> allocate channel c1 device type disk format
'/orabackup/rman/TARGDB/backup_db_%d_S_%s_P_%p_T_%t';
3> allocate channel c2 device type disk format
'/orabackup/rman/TARGDB/backup_db_%d_S_%s_P_%p_T_%t';
4> setlimit channel c1 maxpiecesize 25m;
5> set maxcorrupt for datafile 1 to 0;
6> backup full
7> skip inaccessible
8> tag rman_backup_hot_full
9> filesperset 4
10> (database include current controlfile);
11> # backup current controlfile;
12> }
allocated channel: c1
channel c1: sid=13 devtype=DISK
allocated channel: c2
channel c2: sid=14 devtype=DISK
executing command: SET MAX CORRUPT
RMAN> exit;
% ls -l /orabackup/rman/TARGDB/*
-rw-r----- 1 oracle dba 26214400 Dec 22 20:50
backup_db_TARGDB_S_18_P_1_T_545604600
-rw-r----- 1 oracle dba 26214400 Dec 22 20:50
backup_db_TARGDB_S_18_P_2_T_545604600
-rw-r----- 1 oracle dba 26214400 Dec 22 20:51
backup_db_TARGDB_S_18_P_3_T_545604600
-rw-r----- 1 oracle dba 26214400 Dec 22 20:51
backup_db_TARGDB_S_18_P_4_T_545604600
-rw-r----- 1 oracle dba 26214400 Dec 22 20:51
backup_db_TARGDB_S_18_P_5_T_545604600
-rw-r----- 1 oracle dba 19333120 Dec 22 20:52
backup_db_TARGDB_S_18_P_6_T_545604600
-rw-r----- 1 oracle dba 343392256 Dec 22 20:52
backup_db_TARGDB_S_19_P_1_T_545604600
-rw-r----- 1 oracle dba 331636736 Dec 22 20:54
backup_db_TARGDB_S_20_P_1_T_545604731
-rw-r----- 1 oracle dba 7946240 Dec 22 20:54 c-2528050866-
20041222-04
Observations
Notice first, that like all offline backups, we need
to first shutdown and startup (mount) the
database. This can all be done within the RMAN
session.
Next, we have a run block, which will contain
one or more statements contained within the
braces and all will execute as one block. Oracle
will not run any of the commands within the
braces of the run block until all statements have
been entered. The run block is completed with
the closing brace, at which time Oracle will be
compiled and executed.
Then we see the allocate channel statements. In
this example, we have two channels allocated.
Each time a you create a channel, Oracle will
create one or more backup sets for that one
channel. In most cases, each channel will create
one backup set - but it is possible to have a
channel create more than one backup set. In
this example, I will show that my configuration
will be the exception to the rule and it will
create multiple backup sets for one channel.
You show also notice that with each channel, I
can define the format it will use for each backup
piece.
Now that I created two channels, RMAN will
automatically try to parallelize the backup
stream amoung those channels.
When using multiple channels, you can
configure and control the maximum piece size,
read rate, rate, and maximum open files for
each backup piece by using the channel name
you assigned to it. In my example, I have two
defined channels - c1 and c2.
o I put no limits on the second channel c2.
/u06/app/oradata/TARGDB/undotbs01.dbf
/u06/app/oradata/TARGDB/cwmlite01.dbf
/u06/app/oradata/TARGDB/odm01.dbf
/u06/app/oradata/TARGDB/indx01.dbf
o Backup Set 20
/u06/app/oradata/TARGDB/system01.dbf
/u06/app/oradata/TARGDB/tools01.dbf
/u06/app/oradata/TARGDB/users01.dbf
Observations
The above command created a backup set
containing all archived redo logs. I marked
several of the lines in the output in blue that are
important in observing the actions performed
by RMAN.
First, notice that RMAN performed a log as one
of it first actions. The output above shows that
this action was performed by the line reading
"current log archived".
Now let's look at the backup set that RMAN
created -
(backup_db_TARGDB_S_34_P_1_T_545694669). It only
contains one archived redo log - the archived
redo log that RMAN switched. In this example
there were no archived redo logs in the
destination directory. The only archived redo log
was the one that was created when RMAN
performed a log switch.
Finally, notice that this backup performed a
backup of the current control file (and SPFILE)
even though I didn't ask for it. RMAN created
the control file (and SPFILE) backup set because
I had set the default configuration parameter
"CONTROLFILE AUTOBACKUP" to ON. If I had set this
configuration parameter to OFF, then RMAN
would not have created the control file (and
SPFILE) backup set.
Observations
The key thing to mention here is that we needed
to drop the keyword "all" that appeared after
the "archivelog" token used in the example of
backing up archived redo logs.
Like in our previous example, notice that RMAN
performs a log switch since we included the "...
plus archivelog" clause.
After performing the log switch, RMAN first
creates a backup set of any archived redo logs
(including the on that was just created from the
log switch). This is backup set
"backup_db_TARGDB_S_38_P_1_T_545696328" in the
example above.
After created the backup set for all archived
redo logs, RMAN then creates a backup set for
the actual backup of all Oracle database files. In
the example above, this is done in backup set
"backup_db_TARGDB_S_39_P_1_T_545696330".
During the backup of the Oracle database files,
changes were being made to the data contained
in those files. This information is being made to
the online redo logs during that time. It is for
this reason that RMAN performs another log
switch and creates an archived redo log backup
set. This is backup set
"backup_db_TARGDB_S_40_P_1_T_545696585" in this
example.
Finally, just like in our last example, since the
RMAN configuration parameter "CONTROLFILE
AUTOBACKUP" was set to ON, RMAN creates a
backup set for the control file (and SPFILE).
Keeping Backups
You can mark backups that can override the default
retention policy.
The KEEP FOREVER option requires the use of a true
recovery catalog:
RMAN> backup tablespace users keep forever consistent;
RMAN> backup database keep until time '01-MAR-2005' logs;
Incremental Backups
This example performs an incremental (online) backup of
the Oracle database using RMAN.
In this example, it is assumed that you want to take one
full database backup once a week, and one incremental
database backup every day. The backup cycle starts on
Friday. A full backup is taken on Friday, and an
incremental backup is then taken every day.
Also in this example, it is assumed that I will be using
RMAN default configurations. One of the parameters I
set is "CONFIGURE RETENTION POLICY TO REDUNDANCY 3". The
retention policy of REDUNDANCY 3 applies only to full
(not incremental) backups, so the combination of that
policy and this backup schedule ensures that you can
restore to any incremental backup time for the last 3
weeks.
run {
# -----------------------------------------------------------
# The following RMAN commands are run each Friday to start
# the backup cycle.
# The steps are:
# - Backup database with incremental level 0.
# - Backup (and then delete) all archivelog files.
# -----------------------------------------------------------
backup
incremental level 0
filesperset 4
(database);
backup
archivelog all
delete input;
}
Now, let's look at what happens on those other days. The
following commands can be run from Saturday through
Thursday to take cumulative incremental backups. Notice
that LEVEL 1 is specified with the BACKUP command.
Also notice that the options LEVEL 1 CUMULATIVE indicate
that only the blocks that have changed since the last
level 0 backup will be backed up. If the CUMULATIVE option
was not specified, then only the blocks that have
changed since the last LEVEL 1 backup will be backed up.
The advantage of a cumulative backup is that only one
incremental backup ever needs to be applied during
recovery.
run {
backup
incremental level 1 cumulative
filesperset 4
(database);
}
Mirroring Backups
It is possible to multiplex up to 4 copies per set at
runtime:
run {
set backup copies 2;
backup full
format
'/orabackup1/rman/TARGDB/backup_db_%d_S_%s_P_%p_T_%t'
,
'/orabackup2/rman/TARGDB/backup_db_%d_S_%s_P_%p_T_%t'
(database);
}
You can also copy a disk backup to tape then remove files
to create room for the next disk backup:
backup device sbt backup set created before 'SYSDATE - 1' delete
input;
Backup Failures
If the above backup fails for any reaon, you can use the
NOT BACKED UP SINCE option on the BACKUP command (9i
restartable backup feature) to continue from the point of
failure. The small value of FILESPERSET is good for
restartable backups. However you should note that
smaller FILESPERSET produces more backup sets.
run {
# -----------------------------------------------------------
# To re-start from the point of failure, run following
# commands.
# -----------------------------------------------------------
backup
incremental level 0
filesperset 4
not backed up since time 'sysdate-1'
(database);
}