RMAN Backups & Rpt.
Download
Report
Transcript RMAN Backups & Rpt.
CHAPTER 18
RMAN Backups and Reporting
Introduction to RMAN Backups and
Reporting
• The focus of this chapter is backups of:
• Datafiles
• Control files
• Archived redo log files
• Spfile
• Backup pieces
• RMAN does not backup the online redo logs (it would be
pointless to do so).
• This chapter also focuses on logging and reporting
backup operations.
Setting NLS_DATE_FORMAT
• From the OS, set the operating system variable
NLS_DATE_FORMAT to include a time (hours, minutes,
and seconds) component. For example:
$ export NLS_DATE_FORMAT='dd-mon-yyyy hh24:mi:ss‘
• This ensures that when RMAN displays a date, it always
includes the hours, minutes, and seconds as part of the
output.
• By default, RMAN only includes the date component (DDMON-YYYY) in the output.
• This default is oftentimes not granular enough for
troubleshooting issues.
Setting ECHO... Setting ECHO
• Within RMAN
RMAN> set echo on;
• This instructs RMAN to display the command that it's
running in the output, so you can see what RMAN
command is running along with any relevant error or
output messages associated with the command.
• This is especially important when you're running RMAN
commands within scripts, because you're not directly
typing in a command (and may not know what command
was issued within the shell script).
Showing Variables
RMAN> SHOW ALL;
• This displays all of the RMAN configurable variables.
• When troubleshooting, you may not be aware of
something that another DBA has configured.
• This gives you a snapshot of the settings as they were
when the RMAN session executed.
Backing up the Entire Database
• Set the location to where you want the RMAN backup files
to be written and with what format and then backup the
database:
RMAN> configure channel 1 device type disk format
'/ora01/O11R2/rman/rman1_%U.bk';
RMAN> backup incremental level=0 database plus
archivelog;
Full Backup versus Incremental Level=0
• Full and Level 0 backup the same blocks
• Difference is that a level 0 can be used with subsequent
level 1 backups.
Backup Sets versus Image Copies
• Backup set includes blocks that have been used within
•
•
•
•
the datafiles.
RMAN is the only utility that can read from a backup set.
Image copy is a block for block copy of a datafile.
Image copies can be accessed from the OS.
Usually backup sets are more efficient.
Backing up Tablespaces
• RMAN has the ability to backup datafiles associated with
specific tablespaces.
• You may want to test a backup on a specific tablespace or
have a requirement to backup sets of tablespaces.
RMAN> backup tablespace system, sysaux;
Backing up Datafiles
• RMAN provides the ability to backup specific datafiles.
• You may want to do this to test a backup feature without
having to backup the entire database or you may want to
backup subsets of datafiles at a time.
RMAN> backup datafile 1,3;
Backing up the Control File
• Always configure the autobackup of the control file
feature:
RMAN> configure controlfile autobackup on;
• This ensures that the control file is backed up whenever a
backup or copy command is issued.
• You can manually backup the control file via:
RMAN> backup current controlfile;
Backing up the Spfile
• Whenever you have autobackup of the control file
enabled, the spfile (if you’re using an spfile) will also be
automatically backed up.
• To manually backup the spfile:
RMAN> backup spfile;
Backing up Archive Redo Logs
• The safest way to backup archive redo log files is to back
them up at the same time you’re backing up your
database:
RMAN> backup incremental level=0 database plus
archivelog;
• You can manually back them up via:
RMAN> backup archivelog all;
Backing up Fast Recovery Area
• If you’re using a FRA, RMAN can back up its contents to
tape or disk:
RMAN> configure channel device type sbt_tape parms
'ENV=(OB_MEDIA_FAMILY=RMAN-DB11R2)';
RMAN> backup device type sbt_tape recovery area;
RMAN> backup recovery area to destination
'/ora01/O11R1/fra_back';
Excluding Tablespaces from Backups
• You can configure non-critical tablespaces to be not
backed up by default:
RMAN> configure exclude for tablespace users;
Backing up Datafiles Not Backed Up
• This is a handy feature when you’ve had some sort of
failure with a daily scheduled backup and you want to
ensure that everything has been backed up within the last
day (for example):
RMAN> backup database not backed up since
time='sysdate-1';
Skipping Read-Only Tablespaces
• You don’t necessarily need to backup read-only
tablespaces on a regular basis because the data in these
tablespaces does not change from backup to backup:
RMAN> backup database skip readonly;
Skipping Offline or Inaccessible Files
• Sometimes a datafile might become corrupt, and you
need to take it offline.
• RMAN will throw an error when it attempts to backup an
offline datafile.
• Instruct RMAN to skip offline:
RMAN> backup database skip offline;
Backing Up Large Files in Parallel
• RMAN has the ability to backup large files with parallel
processes.
• You need to specify a size for the sections and then
RMAN figures out how to divvy it up:
RMAN> configure device type disk parallelism 2;
RMAN> configure channel 1 device type disk format
'/ora01/O11R2/rman/r1%U.bk';
RMAN> configure channel 2 device type disk format
'/ora02/O11R2/rman/r2%U.bk';
RMAN> backup section size 2500M datafile 10;
Adding RMAN Backup Information to the
Repository
• Very handy feature for repopulating the control file with
RMAN backup information.
• You may have a scenario where you’ve had to re-create
your control file; this wipes out any RMAN information;
use the CATALOG command to repopulate the control file
with RMAN backup information:
RMAN> catalog start with '/ora01/O11R2/rman';
Taking Incremental Level Backups
• Nice feature for backing up large databases that don’t
change much from backup to backup.
• First take a level 0, then take subsequent incremental
backups:
RMAN> backup incremental level=0 database;
RMAN> backup incremental level=1 database;
Making Incrementally Updating Backups
• The basic idea behind an incrementally updating backup
is to create image copies of datafiles and then use
incremental backups to update the image copies.
• In this manner, you have image copies of your database
that are kept somewhat current by applying an
incremental backup to them.
• This can be an efficient way to combine image copy
backups with incremental backups.
RMAN> recover copy of database with tag 'incupdate';
RMAN> backup incremental level 1 for recover of copy with
tag 'incupdate' database;
Using Block Change Tracking
• Uses a binary OS file that records which blocks have
changed.
• Useful for large databases using an incremental backup
strategy.
1. If not already enabled, set the
DB_CREATE_FILE_DEST parameter to a location.
2. Enable block change tracking via the ALTER
DATABASE command.
Using VALIDATE to Check for Corruption
• Check for missing files or physical corruption in database
datafiles, archive redo log files, control files, spfile, and
backup set pieces.
• For example, this command will validate all datafiles and
the control files:
•
RMAN> validate database;
Using BACKUP...VALIDATE to Check for
Corruption
• Check to see if datafiles are available and if the datafiles
contain any corrupt blocks. For example:
•
RMAN> backup validate database;
Using RESTORE...VALIDATE to Check
for Corruption
• Use RESTORE...VALIDATE to verify backup files that
would be used to restore (are available).
• This command validates backup sets, datafile copies, and
archive redo log files:
RMAN> restore validate database;
Redirecting Output to a File
• Shell commands provide a way to capture output
• Redirect standard out and standard error to a log file:
$ rmanback.bsh 1>/home/oracle/bin/log/rmanback.log
2>&1
Capturing Output with tee
• When you start RMAN, you can send the output you see
on your screen to an operating system text file using the
tee command:
•
$ rman | tee /tmp/rman.log
Using a Recovery Catalog
• Recovery catalog provides you with the most options
when faced with a recovery
• Recovery catalog allows you to retain a long history of
backups
• Having said that, many DBAs choose not to implement a
recovery catalog (Recovery Catalog, resides in another
database that needs to be setup, maintained, upgraded,
and so on)
Capturing Output with the script
Command
• The script command is useful because it instructs the
operating system to log any output that appears on the
terminal to a log file. To capture all output, run the script
command before connecting to RMAN:
•
$ script /tmp/rman.log
Script started, file is /tmp/rman.log
$ rman target /
RMAN> backup database;
RMAN> exit;
•
• To end a script session, type in Ctrl+D or type in exit.
Logging Output to a File
• An easy way to capture RMAN output is to use the
SPOOL LOG command to send the output to a file. This
example spools a log file from within RMAN:
•
RMAN> spool log to '/tmp/rmanout.log'
RMAN> set echo on;
RMAN> <run RMAN commands>
RMAN> spool log off;
Querying for Output in the Data Dictionary
• The V$RMAN_OUTPUT view contains messages recently
reported by RMAN:
•
select
sid
,recid
,output
from v$rman_output
order by recid;
•
Using LIST for Reporting
• LIST provides information about backups:
RMAN> list backup;
RMAN> list copy;
RMAN> list archivelog all;
Using REPORT for Reporting
• Report on the datafiles associated with a database:
RMAN> report schema;
• Report on datafiles that need to be backed up as defined
by your retention policy:
RMAN> report need backup;
Using SQL for Reporting
• Robust set of data dictionary views available for reporting
on RMAN backup activities:
• V$RMAN_BACKUP_JOB_DETAILS
• V$BACKUP
• V$BACKUP_ARCHIVELOG_DETAILS
• and so on...
Summary
• RMAN is a feature-rich utility for backup and recovery.
• You can implement features as required by your
environment.
• RMAN also contains many reporting capabilities which
assist with troubleshooting and maintaining a recoverable
database environment.