Sie sind auf Seite 1von 10

Basic RMAN Backup

Lets do a real simple backup using RMAN that writes it's output to a local file instead of the tape subsystem just to see how it works. In this case, we've got our database (SID: cuddle) up and running.
[oracle@vixen oracle]$ echo $ORACLE_SID cuddle [oracle@vixen oracle]$ rman nocatalog target / Recovery Manager: Release 10.1.0.2.0 - 64bit Production Copyright (c) 1995, 2004, Oracle. All rights reserved. connected to target database: CUDDLE (DBID=251015092) using target database controlfile instead of recovery catalog RMAN> backup database; Starting backup at 02-NOV-04 allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=162 devtype=DISK channel ORA_DISK_1: starting full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset input datafile fno=00001 name=/u02/oradata/cuddle/system01.dbf input datafile fno=00003 name=/u02/oradata/cuddle/sysaux01.dbf input datafile fno=00002 name=/u02/oradata/cuddle/undotbs01.dbf input datafile fno=00004 name=/u02/oradata/cuddle/users01.dbf channel ORA_DISK_1: starting piece 1 at 02-NOV-04 channel ORA_DISK_1: finished piece 1 at 02-NOV-04 piece handle=/u01/app/oracle/product/10.1.0/db_1/dbs/05g438u6_1_1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:45 channel ORA_DISK_1: starting full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset including current controlfile in backupset including current SPFILE in backupset channel ORA_DISK_1: starting piece 1 at 02-NOV-04 channel ORA_DISK_1: finished piece 1 at 02-NOV-04 piece handle=/u01/app/oracle/product/10.1.0/db_1/dbs/06g4391f_1_1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03 Finished backup at 02-NOV-04 RMAN> quit Recovery Manager complete. [oracle@vixen oracle]$

This is the most basic backup you can do with RMAN. We didn't tell RMAN how or where to backup the database, just simply to do it. The rman command is passed 2 arguments: the first "nocatalog" tells RMAN that we aren't using a recovery catalog database and the second "target /" is similar to a SQL*Plus connect statement,

with information that RMAN requires to connect to the target database. The target is the database we wish to backup. Notice that RMAN returns some interesting information prior to giving us a prompt. It confirms that RMAN is connected to the target and lists that target. The DBID seen after the target database SID can be very important for later recoveries and it is recommend that you write it down somewhere for future use. RMAN then confirms that because we aren't using a recovery catalog to store backup metadata that it will instead store the data in the target databases control files. The RMAN command backup database; sends RMAN on its merry way backing up the database. Notice that we didn't tell it where or how to backup the data. By default the backup peices will be placed in the $ORACLE_HOME/dbs directory. This can get very messy since your system PFILES are in there too, and therefore we recommend that you don't use this location for your normal backups. Two backup peices were created. The first contains the datafiles holding the tablespaces including the undo tablespace. The second backup peice contains the current SPFILE and curent controlfile. Lets stop and think carefully for just a moment. Now, we've opted to use ARCHIVELOG mode which means we can do hot backups. However, we didn't want the hassle and administrative overhead of maintaining a recovery catalog. So here is the rub: recall that you need a PFILE/SPFILE to start an instance and you need the controlfile to point to all the files to be mounted. If the database were completely destroyed we would certainly need both the SPFILE and the Controlfile to access the backup peices made by RMAN.... but they are inside the backup we just made! Nice little loop of confusion huh? We'll talk about this later, but for now just keep it in mind.

Basic Recovery
To see how RMAN can be useful for recovery, lets take a database and damage it. Lets simulate a tablespace being deleted because of a bad script or stupid DBA and then try to recover the database.
[oracle@vixen oracle]$ mv /u02/oradata/cuddle/users01.dbf /u02/oradata/cuddle/users01.dbf.oops

Okey, there is our disaster. Lets connect to RMAN and look for suitable backups to recover.
[oracle@vixen oracle]$ rman nocatalog target / Recovery Manager: Release 10.1.0.2.0 - 64bit Production

Copyright (c) 1995, 2004, Oracle.

All rights reserved.

connected to target database: CUDDLE (DBID=251015092) using target database controlfile instead of recovery catalog RMAN> list backup; List of Backup Sets =================== ......... BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------5 Full 528M DISK 00:01:43 02-NOV-04 BP Key: 5 Status: AVAILABLE Compressed: NO Tag: TAG20041102T134437 Piece Name: /u01/app/oracle/product/10.1.0/db_1/dbs/05g438u6_1_1 List of Datafiles in backup set 5 File LV Type Ckp SCN Ckp Time Name ---- -- ---- ---------- --------- ---1 Full 1267667 02-NOV-04 /u02/oradata/cuddle/system01.dbf 2 Full 1267667 02-NOV-04 /u02/oradata/cuddle/undotbs01.dbf 3 Full 1267667 02-NOV-04 /u02/oradata/cuddle/sysaux01.dbf 4 Full 1267667 02-NOV-04 /u02/oradata/cuddle/users01.dbf BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------6 Full 2M DISK 00:00:03 02-NOV-04 BP Key: 6 Status: AVAILABLE Compressed: NO Tag: TAG20041102T134437 Piece Name: /u01/app/oracle/product/10.1.0/db_1/dbs/06g4391f_1_1 Controlfile Included: Ckp SCN: 1267704 Ckp time: 02-NOV-04 SPFILE Included: Modification time: 15-OCT-04 RMAN>

We can see that we have good and current backups of this database avalible. Lets now try to recover in the basic way.
MAN> restore datafile '/u02/oradata/cuddle/users01.dbf'; Starting restore at 02-NOV-04 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile backupset restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set restoring datafile 00004 to /u02/oradata/cuddle/users01.dbf channel ORA_DISK_1: restored backup piece 1 piece handle=/u01/app/oracle/product/10.1.0/db_1/dbs/05g438u6_1_1 tag=TAG20041102T134437 channel ORA_DISK_1: restore complete Finished restore at 02-NOV-04 RMAN> recover datafile '/u02/oradata/cuddle/users01.dbf'; Starting recover at 02-NOV-04 using channel ORA_DISK_1

starting media recovery media recovery complete Finished recover at 02-NOV-04 RMAN>

Here, because the controlfiles and spfile are in tact, we can simply tell RMAN to restore the missing datafile, specifying which datafile by it's fully qualified path (which you can also see in your "list backup;"). Once the datafile is restored, we can recover it to ensure it's consistant. Once your done, you'll either want to bring the datafile and tablespaces online using alter statements, or at the very least use SQL*Plus to verify that the tablespaces are online by looking at the Oracle data dictionary.
SQL> select TABLESPACE_NAME,STATUS from dba_tablespaces; TABLESPACE_NAME -----------------------------SYSTEM UNDOTBS1 SYSAUX TEMP USERS STATUS --------ONLINE ONLINE ONLINE ONLINE ONLINE

SQL> select FILE#,STATUS,ENABLED,NAME from v$datafile; FILE# STATUS ENABLED ---------- ------- ---------NAME --------------------------------1 SYSTEM READ WRITE /u02/oradata/cuddle/system01.dbf 2 ONLINE READ WRITE /u02/oradata/cuddle/undotbs01.dbf 3 ONLINE READ WRITE /u02/oradata/cuddle/sysaux01.dbf 4 OFFLINE READ WRITE /u02/oradata/cuddle/users01.dbf

In this above case the tablespace is online but we find the datafile is offline. Lets just fix that up by using an alter statement:
SQL> alter database datafile '/u02/oradata/cuddle/users01.dbf' online; Database altered. SQL> alter tablespace USERS online; Tablespace altered.

We didn't need to alter the tablespace because it was already online, but I did it any way to demonstrate. Once you've successfully altered the database to bring both the datafile and the tablespaces online you'll want to run the queries above again to double check.

hi, Friends i had seen many people are asking how to use RMAN and they just need Step to do backup and recovery by using RMAN Uitility...frankly saying ....Its...Spoon feeding ... But below are the requirement of many people which shows how to do Backup , restore and recovery of database by using RMAN Note :- There is much more in RMAN ...as Backup of RMAN is stored on another Server here in this example i showed how to store backup on same server on which our database reside. You can know how to store RMAN backup on another server if you go through the documentation . Exmanple BACKUP and RECOVERY with RMAN --->Create directory rman were we can store our backup D:/orahome1>md rman --------------------------------------------------------------------------------------------------------------------------------===>Connecting to the RMAN with nocatalog C:\Documents and Settings\sadmin>rman target / nocatalog Recovery Manager: Release 9.0.1.5.1 - Production (c) Copyright 2001 Oracle Corporation. All rights reserved. connected to target database: ASDB (DBID=2169591373) using target database controlfile instead of recovery catalog ===> Taking Backup

RMAN> backup database format 'D:/orahome1/rman/ora_df%t_s%s_s%p'; Starting backup at 19-AUG-05 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset including current controlfile in backupset input datafile fno=00001 name=D:\ORAHOME1\ORADATA\ASDB\SYSTEM01.DBF input datafile fno=00009 name=D:\ORAHOME1\ORADATA\ASDB\IAS_META01.DBF input datafile fno=00005 name=D:\ORAHOME1\ORADATA\ASDB\PORTAL.DBF input datafile fno=00002 name=D:\ORAHOME1\ORADATA\ASDB\UNDOTBS01.DBF input datafile fno=00016 name=D:\ORAHOME1\ORADATA\ASDB\IP_DT.DBF input datafile fno=00015 name=D:\ORAHOME1\ORADATA\ASDB\IP_RT.DBF input datafile fno=00012 name=D:\ORAHOME1\ORADATA\ASDB\DCM.DBF input datafile fno=00023 name=D:\ORAHOME1\ORADATA\ASDB\GCATS1_OID.DBF input datafile fno=00020 name=D:\ORAHOME1\ORADATA\ASDB\UDDISYS01.DBF input datafile fno=00007 name=D:\ORAHOME1\ORADATA\ASDB\PTLIDX.DBF input datafile fno=00017 name=D:\ORAHOME1\ORADATA\ASDB\IP_IDX.DBF input datafile fno=00018 name=D:\ORAHOME1\ORADATA\ASDB\IP_LOB.DBF input datafile fno=00013 name=D:\ORAHOME1\ORADATA\ASDB\OSS_SYS01.DBF input datafile fno=00003 name=D:\ORAHOME1\ORADATA\ASDB\DRSYS01.DBF input datafile fno=00024 name=D:\ORAHOME1\ORADATA\ASDB\GDEFAULT1_OID.DBF input datafile fno=00021 name=D:\ORAHOME1\ORADATA\ASDB\ATTRS1_OID.DBF input datafile fno=00025 name=D:\ORAHOME1\ORADATA\ASDB\SVRMG1_OID.DBF input datafile fno=00006 name=D:\ORAHOME1\ORADATA\ASDB\PTLDOC.DBF input datafile fno=00010 name=D:\ORAHOME1\ORADATA\ASDB\DISCOPLTM1.DBF input datafile fno=00011 name=D:\ORAHOME1\ORADATA\ASDB\DISCOPLTC1.DBF input datafile fno=00014 name=D:\ORAHOME1\ORADATA\ASDB\WCRSYS01.DBF input datafile fno=00019 name=D:\ORAHOME1\ORADATA\ASDB\OCA.DBF input datafile fno=00008 name=D:\ORAHOME1\ORADATA\ASDB\PTLLOG.DBF input datafile fno=00022 name=D:\ORAHOME1\ORADATA\ASDB\BATTRS1_OID.DBF channel ORA_DISK_1: starting piece 1 at 19-AUG-05 channel ORA_DISK_1: finished piece 1 at 19-AUG-05 piece handle=D:\ORAHOME1\RMAN\ORA_DF566751828_S3_S1 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:56 Finished backup at 19-AUG-05 RMAN> EXIT Recovery Manager complete. --------------------------------------------------------------------------------------------------------------------------------===>To Crash our database

Now shutdown your database from SQL prompt SQL> shutdown ----> And Rename your system01.dbf file so that there can be crash in your database --------------------------------------------------------------------------------------------------------------------------------===>Now Again try to startup the database but first connect to sqlpls by sysdba SQL*Plus: Release 9.0.1.4.0 - Production on Fri Aug 19 14:59:26 2005 (c) Copyright 2001 Oracle Corporation. All rights reserved. Enter user-name: SYS AS SYSDBA Enter password: Connected to an idle instance. SQL> STARTUP ORACLE instance started. Total System Global Area 151810128 bytes Fixed Size 282704 bytes Variable Size 100663296 bytes Database Buffers 50331648 bytes Redo Buffers 532480 bytes Database mounted. ORA-01157: cannot identify/lock data file 1 - see DBWR trace file ORA-01110: data file 1: 'D:\ORAHOME1\ORADATA\ASDB\SYSTEM01.DBF' ===>Now above you can see Error occoured because SYSTEM01.DBF is missing. -------------------------------------------------------------------------------------------------------------------------------Now Again connect to RMAN C:\Documents and Settings\sadmin>rman target / nocatalogRecovery Manager: Release 9.0.1.5.1 Production (c) Copyright 2001 Oracle Corporation. All rights reserved. connected to target database: ASDB (DBID=2169591373)

using target database controlfile instead of recovery catalog RMAN>

RMAN> RESTORE DATABASE; Starting restore at 19-AUG-05 allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=8 devtype=DISK channel ORA_DISK_1: starting datafile backupset restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set restoring datafile 00001 to D:\ORAHOME1\ORADATA\ASDB\SYSTEM01.DBF restoring datafile 00002 to D:\ORAHOME1\ORADATA\ASDB\UNDOTBS01.DBF restoring datafile 00003 to D:\ORAHOME1\ORADATA\ASDB\DRSYS01.DBF restoring datafile 00005 to D:\ORAHOME1\ORADATA\ASDB\PORTAL.DBF restoring datafile 00006 to D:\ORAHOME1\ORADATA\ASDB\PTLDOC.DBF restoring datafile 00007 to D:\ORAHOME1\ORADATA\ASDB\PTLIDX.DBF restoring datafile 00008 to D:\ORAHOME1\ORADATA\ASDB\PTLLOG.DBF restoring datafile 00009 to D:\ORAHOME1\ORADATA\ASDB\IAS_META01.DBF restoring datafile 00010 to D:\ORAHOME1\ORADATA\ASDB\DISCOPLTM1.DBF restoring datafile 00011 to D:\ORAHOME1\ORADATA\ASDB\DISCOPLTC1.DBF restoring datafile 00012 to D:\ORAHOME1\ORADATA\ASDB\DCM.DBF restoring datafile 00013 to D:\ORAHOME1\ORADATA\ASDB\OSS_SYS01.DBF restoring datafile 00014 to D:\ORAHOME1\ORADATA\ASDB\WCRSYS01.DBF restoring datafile 00015 to D:\ORAHOME1\ORADATA\ASDB\IP_RT.DBF restoring datafile 00016 to D:\ORAHOME1\ORADATA\ASDB\IP_DT.DBF restoring datafile 00017 to D:\ORAHOME1\ORADATA\ASDB\IP_IDX.DBF restoring datafile 00018 to D:\ORAHOME1\ORADATA\ASDB\IP_LOB.DBF restoring datafile 00019 to D:\ORAHOME1\ORADATA\ASDB\OCA.DBF restoring datafile 00020 to D:\ORAHOME1\ORADATA\ASDB\UDDISYS01.DBF restoring datafile 00021 to D:\ORAHOME1\ORADATA\ASDB\ATTRS1_OID.DBF restoring datafile 00022 to D:\ORAHOME1\ORADATA\ASDB\BATTRS1_OID.DBF restoring datafile 00023 to D:\ORAHOME1\ORADATA\ASDB\GCATS1_OID.DBF restoring datafile 00024 to D:\ORAHOME1\ORADATA\ASDB\GDEFAULT1_OID.DBF restoring datafile 00025 to D:\ORAHOME1\ORADATA\ASDB\SVRMG1_OID.DBF channel ORA_DISK_1: restored backup piece 1 piece handle=D:\ORAHOME1\RMAN\ORA_DF566751828_S3_S1 tag=null params=NULL channel ORA_DISK_1: restore complete Finished restore at 19-AUG-05

RMAN> RECOVER DATABASE; Starting recover at 19-AUG-05 using channel ORA_DISK_1 starting media recovery media recovery complete Finished recover at 19-AUG-05 RMAN> --------------------------------------------------------------------------------------------------------------------------------==>Now at SQL prompt open the database as database is recovered so that user can connect to the database. SQL> ALTER DATABASE OPEN; Database altered. SQL> show parameter instance_name; NAME TYPE VALUE --------------------------------------- --------------- --------------instance_name string asdb --------------------------------------------------------------------------------------------------------------------------------Note:- Controlfile , Archive logs, redolog files, init.ora & Passwordfile do its backup manually as above senario is for Only datafile. From:Always your Friend Sunil

To Check The RMAN Progress:


SELECT sid, serial#, context, sofar, totalwork, round(sofar/totalwork*100,2) "% Complete" FROM v$session_longops where upper(opname) like '%RMAN%';

Das könnte Ihnen auch gefallen