DBAQuest.com
Backup and Recovery Using RMAN: Performing Database Backups Date Thursday, December 13 @ 18:54:49 Topic Backup and Recovery
| This is the second article in the series "Backup and Recovery using RMAN". Here, we will learn how to create RMAN scripts, store them in the recovery catalog and perform database backups. Click here to read the first article in this series, titled "Setting up the Recovery Catalog". Let us go through some basic concepts necessary to understand this article. The full gamut of options and commands is too large for the scope of this article. There are two types of RMAN backups - Backupsets and Image Copies.
- Backupsets are comprised of one or more backup pieces, which are physical files containing the used blocks from the target database. Backup is done at the block level and the unused blocks are not backed up by RMAN. Backup pieces can contain datafiles and archivelogs.
Backupsets can also be Full or Incremental. Incremental backups consist only of blocks that have been modified since another incremental backup of an equal or lower level. Full backups are the same as an Incremental Level 0 backup, only full backupsets cannot be used as the base backup for an Incremental backup strategy.
- Image Copies, on the other hand are more like full file copies of the datafiles that are being backed up.
Before backing up your database(s), create a backup strategy.
- If your database is running in NOARCHIVELOG mode, the database cannot be open during the backup.
- If running in ARCHIVELOG mode, the frequency of your backups may depend on how long it takes to restore/recover, how much space you have for your archivelogs and what kind of backup path (full or incremental) you adopt.
- RMAN needs a Media Management Layer (like Legato Storage Manager) to perform backups directy to tape.
For simplicity sake, we will cover performing full RMAN backups to disk. Now, let us create some backup scripts, store them in the catalog and then execute the scripts to perform our backup.
[prod-server:oracle] $ rman target sys/yoursyspwd rcvcat rman_admin/rman@rcat
Recovery Manager: Release 9.0.1.0.0 - Production
(c) Copyright 2001 Oracle Corporation. All rights reserved.
connected to target database: DEMO (DBID=3191250744) connected to recovery catalog database
RMAN> create script prod_full_backup { 2> allocate channel ch1 type disk; 3> backup full database include current controlfile 4> tag prod_full_backup 5> format '/u03/backup/%d_t%t_s%s_p%p'; 6> release channel ch1; 7> }
created script prod_full_backup
RMAN>
The "allocate channel" command creates a server process to perform the backup to the specified output device. We are doing a full backup of the database (remember only the used blocks will be backed up, so the backup may be smaller than the sum total of your database file sizes) along with the controlfile. We will give it a name "prod_full_backup" as specified in the tag.
The format specifies the full path (on the server with the target database, in out case, prod-server) and filename of the backup. Here, %d is the database name, %t is the timestamp, %s is the backup set number and %p is the backup piece number. Oh, I forgot to include the archivelogs in the backup script. You can either delete the script and recreate it or just replace it with a newer version of the script.
RMAN> delete script prod_full_backup;
deleted script: prod_full_backup
or
RMAN> replace script prod_full_backup { 2> allocate channel ch1 type disk; 3> backup full database include current controlfile 4> tag prod_full_backup 5> format '/u03/backup/prod_t%t_s%s_p%p'; 6> sql "alter system archive log current"; 7> backup archivelog from logseq=16 thread 1 delete input 8> format '/u03/backup/prodarch_t%t'; 9> release channel ch1; 10> }
replaced script prod_full_backup
RMAN>
Firstly, current redo logs cannot be backed up. So we issue a SQL statement to force the archival of the current redo log.
Next, archivelog backups cannot be tagged, hence no tag name. Finally, we are backing up all the archivelogs starting from the log sequence number 16, since we do not have the older archivelogs that were produced before we set up RMAN. We are also deleting the archivelogs after the backup is successfully completed. If the backups fail, the archivelogs will not be deleted, but use this with caution, since archivelogs are paramount for full database recovery.
We can now view the script from the RC_STORED_SCRIPT view in the recovery catalog database, RCAT. Use SQLPlus to connect as the RMAN user, which in our case is "rman_admin".
SQL> select * from rc_stored_script;
DB_KEY DB_NAME SCRIPT_NAME ---------- -------- ------------------------------ 1 PROD prod_full_backup
If you lost the file that you typed your script in, you can just retrieve it from the catatlog. Use the RC_STORED_SCRIPT_LINE view to get the text of your script.
SQL> select text from rc_stored_script_line where script_name='prod_full_backup';
TEXT ------------------------------------------------- { allocate channel ch1 type disk; backup full database include current controlfile tag prod_full_backup format '/u03/backup/prod_t%t_s%s_p%p'; sql "alter system archive log current"; backup archivelog from logseq=16 thread 1 delete input format '/u03/backup/prodarch_t%t'; release channel ch1; }
10 rows selected.
Excellent. Now we have the script ready and stored in the catalog. You can now do your backup manually or run it as a scheduled job (either from the Oracle Enterprise Manager or from the UNIX crontab). To run the script manually, use the "run" command from the RMAN prompt.
RMAN> run {execute script prod_full_backup;}
executing script: prod_full_backup
allocated channel: ch1 channel ch1: sid=9 devtype=DISK
Starting backup at 13-DEC-01 channel ch1: starting full datafile backupset channel ch1: specifying datafile(s) in backupset including current controlfile in backupset input datafile fno=00001 name=/u02/oradata/prod/system01.dbf input datafile fno=00002 name=/u02/oradata/prod/undotbs01.dbf input datafile fno=00004 name=/u02/oradata/prod/example01.dbf input datafile fno=00005 name=/u02/oradata/prod/indx01.dbf input datafile fno=00007 name=/u02/oradata/prod/users01.dbf input datafile fno=00003 name=/u02/oradata/prod/drsys01.dbf input datafile fno=00006 name=/u02/oradata/prod/tools01.dbf input datafile fno=00008 name=/u02/oradata/prod/oem_rep.dbf channel ch1: starting piece 1 at 13-DEC-01 channel ch1: finished piece 1 at 13-DEC-01 piece handle=/u03/backup/prod_t448394435_s2_p1 comment=NONE channel ch1: backup set complete, elapsed time: 00:03:06 Finished backup at 13-DEC-01
sql statement: alter system archive log current
Starting backup at 13-DEC-01 current log archived channel ch1: starting archive log backupset channel ch1: specifying archive log(s) in backup set input archive log thread=1 sequence=16 recid=3 stamp=448308565 input archive log thread=1 sequence=17 recid=4 stamp=448393893 input archive log thread=1 sequence=18 recid=5 stamp=448393895 input archive log thread=1 sequence=19 recid=6 stamp=448394623 input archive log thread=1 sequence=20 recid=7 stamp=448394625 channel ch1: starting piece 1 at 13-DEC-01 channel ch1: finished piece 1 at 13-DEC-01 piece handle=/u03/backup/prodarch_t448394628 comment=NONE channel ch1: backup set complete, elapsed time: 00:00:35 channel ch1: deleting archive log(s) archive log filename=/u01/app/oracle/oradata/prod/archive/prod1_16.arc recid=3 stamp=448308565 archive log filename=/u01/app/oracle/oradata/prod/archive/prod1_17.arc recid=4 stamp=448393893 archive log filename=/u01/app/oracle/oradata/prod/archive/prod1_18.arc recid=5 stamp=448393895 archive log filename=/u01/app/oracle/oradata/prod/archive/prod1_19.arc recid=6 stamp=448394623 archive log filename=/u01/app/oracle/oradata/prod/archive/prod1_20.arc recid=7 stamp=448394625 Finished backup at 13-DEC-01
released channel: ch1
RMAN>
Since we know our script works, we want to run it every Sunday night as a scheduled job. Let's run it as a cron job. Create a Korn shell script called "rman_backup.ksh". This shell script will run the RMAN script, prod_full_backup.rcv.
#!/bin/ksh # Shell script to run RMAN script prod_full_backup.rcv # Logging messages to prod_full_backup.log
# Set environment variables export ORACLE_SID=prod export ORACLE_HOME=/u01/app/oracle/product/9.0.1
# Connect to RMAN and run the backup script rman target sys/yoursyspwd rcvcat rman_admin/rman@rcat cmdfile /export/home/oracle/scripts/prod_full_backup.rcv msglog /export/home/oracle/log/full_backup.log exit
Change permissions on the shell script appropriately.
[prod-server:oracle] $ chmod 755 rman_backup.ksh Now, create the RMAN script file, prod_full_backup.rcv. This just runs the previously stored catalog script, prod_full_backup. Here are the contents of prod_full_backup.rcv
run {execute script prod_full_backup;} Finally, schedule the shell script using the crontab.
[prod-server:oracle] $ crontab -e 00 21 * * 0 $HOME/scripts/rman_backup.ksh We have scheduled our script to run every Sunday night at 9:00 PM.
You can also develop an incremental backup strategy where you do Incremental Level 0 (base level) backup to begin with, an incremental level 1 every 2 weeks, incremental level 2 every week and incremental level 3 every day. This means
- The level 1 incremental will back up all blocks that have changed in the last 2 weeks
- The level 2 incremental will back up all blocks that changed since the last week
- The level 3 incremental will back up all blocks that changed since yesterday
Check out our scripts section for more RMAN scripts and examples for incremental backups.
Now that you know how to do RMAN backups, you are ready to delve into database recovery using RMAN.
| This article comes from DBAQuest.com http://www.dbaquest.com
The URL for this story is: http://www.dbaquest.com/modules.php?op=modload&name=News&file=article&sid=8 |
|
|