You are on page 1of 27

TUESDAY, 4 DECEMBER 2012 RMAN

Implementation of Rman (Recovery Manager) To get the full benefits of Rman we should recovery catalog. Recovery Catalog The recovery catalog is an optional repository of information about your target databases that RMAN uses and maintains. Physical location of the catalog We should place the catalog database on a different server than the target datab ase. If we fail to do this, we jeopardize backup and recovery options, because w e make it possible to lose both the catalog and the target database. The catalog database should be created with the latest version of Oracle in your production environment. This helps to minimize compatibility issues and complex ity when you start to back up your target databases. Creating a catalog The examples in this section provide details for creating a catalog database and registering a target database within the catalog. These examples assume that yo ur catalog database is on a different host than your target database. Catalog database: Oracle 9.2.0.4 (AIRTEL) on sonu Target database: Oracle 10.1.0.2 (AIRTEL1) on sonu1 To create a recovery catalog follow these steps 1. Create a specific tablespace to hold the catalog objects. 2. Create a catalog schema. 3. Issue appropriate grants 4. Create the schema objects. Oracle@sonu:~> sqlplus system/manager@AIRTEL CREATE TABLESPACE rman_cat DATAFILE SIZE 50M; Now that we have a tablespace to store our schema objects, we can create the sch ema CREATE USER rmancat IDENTIFIED BY rmancat DEFAULT TABLESPACE rman_cat /U01/oracle/db/GEK1/CAT/rman_cat_01.dbf

TEMPORARY TABLESPACE temp QUOTA UNLIMITED ON rman_cat; Before we create the catalog objects, we need to grant special privileges to new schema. These privileges, granted through the RECOVRY_CATALOG_OWNER role, let t he schema manage its catalog objects. GRANT RECOVERY_CATALOG_OWNER TO rmancat; GRANT CREATE TYPE TO rmancat; We can now create the catalog objects within our new schema. In order to perform this step, invoke RMAN, connect to newly created catalog schema, and issue the create catalog command. If we don't specify a tablespace with the create catalog command, the catalog objects are created in the default tablespace assigned to the catalog owner. Oracle@sonu:~> rman catalog rmancat/rmancat@AIRTEL Recovery Manager: Release 10.1.0.2.0 - Production Copyright (c) 1995,2004, Oracle. All rights reserved. connected to recovery catalog database recovery catalog is not installed RMAN> create catalog; Recovery catalog created RMAN> exit; At this point, we now have an operational RMAN catalog Registering a target database After creating a catalog, the next logical step is to register a target database . We won t be able to backup the target with the catalog unless the target databas e is registered. Invoke RMAN, connect to both the target and the catalog and issue the register d atabase command. Oracle@sonu:~> rman target / catalog rmancat@rmancat@AIRTEL RMAN> Register Database; RMAN> Exit; Configuring the RMAN Environment Configure command We can configure persistent settings in the Rman environment. The configuration setting is done once, and used by Rman to perform all subsequent operations. To display the pre configured settings type the command SHOW ALL RMAN> SHOW ALL There are various parameters that can be used to configure RMAN operations to su it our needs.

Some of the things that we can configure are 1. Required number of backups for each datafile. 2. Number of server processes that will do backup/restore operations in parallel . 3. Directory where on disk backups will be stored. Etc., We can return any CONFIGURE command to it s default setting by running the command with the CLEAR option. $ rman target / catalog rmancat/rmancat@AIRTEL RMAN> CONFIGURE DEFAULT DEVICE TYPE TO DISK; RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY 3; RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 2; RMAN> CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/u01/oracle/db/AKI1/bck/ora_df%t_s%s_s%p'; RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON; RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/oracle/db/AKI1/bck/ora_cf%F'; RMAN> CONFIGURE BACKUP OPTIMIZATION ON; RMAN> SHOW ALL; Working with RMAN There are few things we need to have in place before instructing RMAN to connect to the target. 1. Appropriate target environment variables must be established. 2. We must have access to an O/S account or a schema that has SYSDBA privilege. Before you connect to your target database, you must ensure that the standard Un ix environment variables are established. These variables include: ORACLE_SID, O RACLE_HOME, PATH, NLS_LANG, and NLS_DATE_FORMAT. They govern the name of the ins tance, the path to the RMAN executable; and the behavior of backup, restore, and reporting commands. When using RMAN, NLS_LANG should be set to the character set that your database was created with. If you do not set NLS_LANG, you may encounter problems when is suing BACKUP, RESTORE, and RECOVER commands. Once you have the appropriate an O/S account or a database ccess to the SYSDBA privilege g RMAN. There are two methods environment variables set, you then need access to schema that has SYSDBA privileges. You must have a before you can connect to the target database usin of administering the SYSDBA privilege:

1. Locally via O/S authentication 2. Remotely via password file For local connections, RMAN automatically connects you to the target database wi th SYSDBA privileges. Setting up a password file is the other method by which we can administer the SY SDBA privilege. There are two good reasons to use RMAN with a password file. 1. Oracle has deprecated the use of CONNECT INTERNAL and Server Manager. 2. We may want to administer RMAN remotely through a network connection. For example, if you're in an environment where you want to back up all of your t arget databases from one place and not has to log on to each host and back up th e database, you must do it via a network connection. To remotely administer RMAN through a network connection, you need to do the following: Create a password file Enable remote logins for password file users Create a password file for Target To create the password file, as the Oracle software owner or as a member of the dba group. $ cd $oracle_home/dbs $ orapwd file=sidname password=password entries=n There are three user-provide variables in this example 1. sidname : The SID of the target instance 2. password : The password to be used when we connect a user SYS with SYSDBA pri vilege. 3. n : The maximum number of schemas allowed in the password files. Example $ cd $ORACLE_HOME/dbs $ orapwd file=orapwAKI1 password=goofi entries=30 After we create a password file, we need to enable remote logins. To do this, se t the instance s REMOTE_LOGIN_PASSWORDFILE initialization parameter to EXCLUSIVE. Setting this parameter to exclusive signifies that only one database can use the password file and that users other than sys and internal can reside in it. We c an now use a network connection to connect to your target database as SYSDBA. Test the connection, try to connect from a PC to the remote database as SYS with SYSDBA privileges: $ sqlplus "sys/Airtel1@sonu1 as sysdba" Note that we have to create a password file only for the target database and not for the catalog. This is because when you connect to the target, you need to con nect as an account that has the SYSDBA privilege. When you connect remotely to a target database, the SYSDBA privilege is enabled through the password file. Thi s is unlike a connection to the catalog, for which SYSDBA is not required, becau

se you log in as the owner of the catalog schema. When the SYSDBA privilege is granted to a specified user, the user can be querie d in the V$PWFILE_USERS view. SQL> GRANT SYSDBA TO rmancat; SQL> select * from v$pwfile_users where username='RMANADMIN'; Invoking the RMAN Executable In order to use Rman we have to invoke the executable. Once we have invoked the executable, we get an RMAN prompt, from which we can execute RMAN commands. The executable of RMAN is located with all of the other oracle executables, in t he BIN directory of oracle installation. From O/S command prompt issue the command RMAN $ rman Connecting to target with no catalog O/S Authentication $ rman target / nocatalog We can use O/S authentication only from an O/S account on the database server Password file authentication client-pc> rman target sys/Airtel1@sonu1 nocatalog Hiding the password Connect to the database after RMAN has been invoked prevents any password inform ation from showing up in a process list. SQLPLUS> $ rman nocatalog RMAN> connect target sys/pwd@SID Connecting to both Target and Catalog If we are using catalog, we will typically connect to the target and the catalog at the same time. This is because when we are performing backup and recovery op erations both the target and the catalog need to be aware of your activities. O/S authentication $ rman target / catalog rmancat/rmancat@sonu1 This connects us to the target and catalog database at the same time. Alternativ ely we can invoke RMAN first and then issue connect commands for the target and catalog separately. $ rman RMAN> connect catalog rmancat/rmancat@sonu1 RMAN> connect target / Password Authentication client-pc> rman target sys/Airtel@sonu1 catalog rmancat/rmancat@sonu1 BACKUPS RMAN can backup data files, control files, archived redo files, and backup piece

s. RMAN doesn t backup the online redo logs. RMAN, as part of its default backup behavior, touches each datafile block, perfo rms verification checks, and then logs any detected corruption. You can monitor potential corruption by querying the V$BACKUP_CORRUPTION and V$COPY_CORRUPTION v iews. For a database to be backed up it must be in mount or open mode. The database ne eds to at least be in mount mode, because RMAN needs to access the target databa se control file before performing a backup. Full Database Offline Backup For offline backups, the database needs to be shutdown and restarted in mount mo de. The database doesn t have to be in archievelog mode. Here's a shell script for an Oracle9/10 database that shuts down the database, m ounts it, backs it up, and opens it: #!/bin/bash rman target / catalog rmancat/rmancat@sonu1 <<eof shutdown immediate; startup mount; backup database format '/u01/oracle/db/AKI1/bck/ora_df%t_s%s_s%p'; alter database open; EOF exit $ ./rman_offline.bash The following files are created: $ cd /u01/oracle/db/sonu1/bck> $ ls -l -rw-r----- 1 oracle dba 7012352 ora_cfc-1994497080-20040927-08 -rw-r----- 1 oracle dba 349777920 ora_df537975652_s39_s1 -rw-r----- 1 oracle dba 138788864 ora_df537975652_s40_s1 Full Database Online Backup #!/bin/bash rman target / catalog rmancat/rmancat@GEK1 <<eof backup database format '/u01/oracle/db/sonu1/bck/ora_df%t_s%s_s%p'; EOF exit

Unlike traditional online (hot) backups, RMAN does not put tablespaces in backup mode. No extra redo is generated. For high-transaction databases, this can lead to significant resource savings. Again, note that with Oracle8i, the syntax is a bit different with respect to th e run{} command: #!/bin/bash rman target / catalog rmancat/rmancat@sonu1 <<eof run { allocate channel d1 type disk; backup database format '/u01/oracle/db/sonu1/bck/ora_df%t_s%s_s%p'; } EOF exit

Backing up a Tablespace The ability to specify only a subset of tablespaces in a backup operation can ad d flexibility to your backup strategy. For Oracle9i, the syntax can be fairly si mple: RMAN> backup tablespace system format '/u01/oracle/db/sonu1/bck/ora_df%t_s%s_s%p '; Once again, note that with Oracle8i, the syntax is a bit different with respect to the run{} command: run { allocate channel d1 type disk; backup tablespace system, users include current controlfile format '/u01/oracle/db/sonu1/bck/ora_df%t_s%s_s%p'; } A nice feature of Oracle9i is its ability to configure the control file to be ba cked up automatically whenever you issue a backup command. You can do this by us ing the configure command as follows: Reset to Defaults RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK CLEAR; Set CONTROLFILE AUTOBACKUP on:

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON; RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u01/oracle/db/sonu1/bck/ora_cf%F.con'; Now backup a tablespace and watch the logging output for the saved controlfile RMAN> backup tablespace users format '/u01/oracle/db/sonu1/bck/rman_%s_%t_%d.bck '; With Oracle9i, the syntax for backing up archived redo log files is fairly simpl e: RMAN> backup archivelog all; Another Oracle9i technique is to use the backup command's plus archivelog clause to include the archive redo log files as part of a backup. This creates at leas t two backup pieces, one for the datafiles, and one for the archived redo log fi les: RMAN> backup database plus archivelog; Incremental Backups One of the most impressive features of RMAN is its ability to perform incrementa l backups. RMAN has the ability to detect which blocks in a datafile has changed since the last backup and will copy only those modified blocks When RMAN copies only the modified blocks during a backup, this is called compre ssion. Skipping unmodified blocks gives RMAN a big advantage over file-based backups in that the resources required to do a backup or restore can be considerably less. Additionally, this means that the backup time and tape/disk space required corr elates to the number of changes made to the database, and not necessarily to the size of the database. For very large databases, this alone can necessitate the use of RMAN. Much of the nomenclature around incremental backups contains the term level. The basic idea behind RMAN level-based backups is to back up only blocks that have been modified since the previous backup. Incremental backups can be applied to t he database, tablespaces, or datafiles. Oracle refers to this usage of levels as a multilevel incremental backup. These levels can range from level 0 to a maxim um of level 4. There are two flavors of incremental backups -- differential and cumulative. A d ifferential incremental backup tells RMAN to back up blocks that have changed si nce level n or lower. For example, if you take a level 1 differential backup, yo u will back up blocks that have changed since the previous level 1 backup. Diffe rential backups are the default incremental backup mode. If you take an incremental backup higher than level 0, and no prior level 0 exist s, RMAN automatically creates a level 0 backup. A cumulative incremental backup instructs RMAN to back up blocks that have chang ed since level n-1 or lower. For example, if you take a level 1 cumulative backu p, RMAN will back up blocks that have changed since the most recent level 0 back up. A full backup backs up the exact same blocks as a level 0. The difference between

a full backup and a level backup is that a full backup is not known to any subs equent incremental backups. Therefore, they cannot be used as a basis when apply ing incremental backups during a recovery operation. A full backup is the defaul t backup type if no incremental level is specified. Why all the choices? A differential backup takes less space and time to perform but requires more time to restore. It follows that a cumulative backup takes mor e space and time to perform but less time to restore. So it becomes a tradeoff i ssue; do you want to minimize your backup time or minimize your restore time? We prefer to minimize our restore time, and therefore, we use cumulative backups. For small databases, we recommend daily RMAN level 0 backups. RMAN> backup incremental level 0 database; Here's an Oracle9i cumulative backup example in which you tell RMAN to back up a ll blocks that have been modified since the most recent level 3 or lower backup. RMAN> backup incremental level 4 cumulative database; Validating backups One nice feature of RMAN is the ability to report on the status of backups. The simplest way to view backup information is via the list backup command. View Backup Information RMAN> list backup; Is Backup restorable ? RMAN also has a way to verify whether the backup files are restorable. You accom plish this by issuing the restore database validate command. This command doesn' t actually restore any datafiles, it just validates that the contents of the bac kup sets can be restored if necessary. The following example works with both Ora cle8i and Oracle9i: RMAN> run { allocate channel d1 type disk; restore database validate; } Validate Backup You can run a test RMAN backup that does not generate any output. The test check s datafiles for physical and logical corruption and that all database files exis t and is in the correct locations. For example: RMAN> backup validate database archivelog all; In general there are three steps involved in restoring files: 1. Ensure that the target database is started in the appropriate mode for the re storation operation. For lost control files, this will be nomount mode. If the e ntire database needs to be restored, this will be mount mode. If datafiles that don't belong to the SYSTEM tablespace are damaged, you have the option of keepin g the database open and taking only the tablespace(s)/datafile(s) that needs to be restored offline. 2. Start RMAN and connect to the target and recovery catalog if one is being use

d. 3. Run the appropriate RMAN RESTORE command to bring back required files. The re quested files and the appropriate archived redo log files will be restored. Restoring and Recovering All Datafiles Our first step is to make sure that the target database is shutdown SQL> connect sys/... as SYSDBA; SQL> shutdown abort; ORACLE instance shut down. Next, you need to start up your target database in mount mode. RMAN cannot resto re datafiles unless the database is at least in mount mode, because RMAN needs t o be able to access the control file to determine which backup sets are necessar y to recover the database. If the control file isn't available, you have to reco ver it first. Issue the STARTUP MOUNT command shown in the following example to mount the database: SQL> startup mount; Oracle instance started. Since backup set files are created in an RMAN-specific format, you must use RMAN to restore the datafiles. To use RMAN, connect to the target database: $ rman target / catalog rmancat/rmancat@sonu1 The remainder of this example shows how to restore all of the datafiles of the t arget database. RMAN will go to its last good backup set and restore the datafil es to the state they were in when that backup set was created. When restoring database files with Oracle9i, RMAN reads the datafile header and makes the determination as to whether the file needs to be restored. The recover y is done by allocating a channel for I/O and then issuing the RMAN restore data base command. With Oracle9i, you don't need to allocate a channel explicitly. Instead, you can use the default channel mode: RMAN> restore database; RMAN> recover database; RMAN> alter database open; For Oracle8i, the ALLOCATE, RESTORE, and RECOVER commands need to be enclosed by the run{} command: RMAN> run { allocate channel d1 type disk; restore database; recover database;

} alter database open; Or alternatively, once RMAN has restored the datafiles, you can use SQL*Plus to recover the database and open it for use: $ sqlplus /nolog SQL> connect sys/... as SYSDBA; SQL> recover database; SQL> alter database open; Restoring Specific Tablespaces/Datafiles In this scenario, it is assumed that your control files are still accessible. Yo u have a backup, done for example with backup database plus archivelog; Take the tablespace/datafile that needs recovery offline, restore the tablespace /datafile, recover the tablespace/datafile, and bring the tablespace/datafile on line. If you cannot take the tablespace/datafile offline, then shutdown abort th e database and restore in mount mode. First try to take the Tablespace offline; sqlplus "sys/managase as sysdba" SQL> alter tablespace tab offline; $ rman target / catalog rmancat/rmancat@sonu1 RMAN> restore tablespace tab; RMAN> recover tablespace tab; SQL> alter tablespace tab open; SQL> connect sys/... as SYSDBA; SQL> shutdown abort; SQL> startup mount; $ rman target / catalog rmancat/rmancat@sonu1 RMAN> restore tablespace tab; RMAN> recover tablespace tab; SQL> alter database open; Instead of a tablespace, you can restore and recover a specific datafile: RMAN> restore datafile '/u01/oracle/db/sonu1/tab/sonu1_tab.dbf' RMAN> recover datafile '/u01/oracle/db/sonu1/tab/sonu1_tab.dbf'

Restoring Control Files In this scenario, it is assumed that your control files are backed up. You have a backup, done for example with backup database plus archivelog; In an ideal world you'll never use RMAN to restore a control file. But if someth ing catastrophic happens, and you lose all control files, here are the steps for getting them back: SQL> connect sys/... as SYSDBA; SQL> shutdown abort; SQL> startup nomount; $ rman target / catalog rmancat/rmancat@sonu RMAN> restore controlfile; RMAN> alter database mount; RMAN> alter database open; If this fails with ... RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of alter db command at 09/28/2004 10:31:52 ORA-01589: must use RESETLOGS or NORESETLOGS option for database open ... then you must perform a recover database: SQL> shutdown abort; SQL> startup mount; $ rman target / catalog rmancat/rmancat@sonu RMAN> recover database; RMAN> alter database open resetlogs; Note, that all offline archivelogs are now useless, perform a full back as soon as possible. In this scenario, it is assumed that your control files are backed up. You have a backup, done for example with backup database plus archivelog; sqlplus "sys/manager as sysdba" SQL> shutdown abort; SQL> startup nomount; $ rman target / catalog rmancat/rmancat@sonu

RMAN> restore controlfile; RMAN> alter database mount; RMAN> restore database; RMAM> recover database; RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of recover command at 09/28/2004 11:03:23 RMAN-06054: media recovery requesting unknown log: thread 1 seq 1 lowscn 8448414 Since the online logs were lost, complete recovery is not possible. Open the dat abase with resetlogs to continue. RMAN> alter database open resetlogs; Note, that all offline archivelogs are now useless, perform a full back as soon as possible. Time-Based or Change-Based Incomplete Recovery Incomplete recovery uses a backup to produce a noncurrent version of the databas e. In other words, you do not apply all of the redo records generated after the most recent backup. You usually perform incomplete recovery of the whole database in the following s ituations: Media failure destroys some or all of the online redo logs. A user error causes data loss, for example, a user inadvertently drops a table. You cannot perform complete recovery because an archived redo log is missing. You lose your current control file and must use a backup control file to open th e database. To perform incomplete media recovery, you must restore all datafiles from backup s created prior to the time to which you want to recover and then open the datab ase with the RESETLOGS option when recovery completes. The RESETLOGS operation c reates a new incarnation of the database; in other words, a database with a new stream of log sequence numbers starting with log sequence 1. sqlplus "sys/manager as sysdba" SQL> shutdown abort; SQL> startup mount; $ rman target / catalog rmancat/rmancat@sonu

RMAN> restore database; SQL> recover database until time '2004-09-29:10:35:00'; media recovery complete. SQL> alter database open resetlogs; Maintenance Commands RMAN has a few maintenance commands, shown next. RMAN> report need backup; What files require a backup now RMAN> crosscheck backup; Determines whether a backup set and its related pieces still exist on media. If a backup piece exists in the location recorded in the c ontrol file of the target database or in the optional recovery catalog, its stat us is marked as AVAILABLE. If it is not at the specified location, it is marked as EXPIRED. RMAN> delete expired backup of database; RMAN> delete backup of database; For Oracle9i, this command deletes the physical files associated with backup sets and datafile copies, updates their status in the control file, and removes their information from the optional recovery catal og (if one is used). In Oracle8i and Oracle9i, backups are flagged as EXPIRED if they cannot be found at their recorded location. Deletion of EXPIRED backups removes their informati on from the control file and from the optional recovery catalog (if one is used) . RMAN> create catalog; RMAN> drop catalog; Create Recovery Catalog. Drops all objects associated with the recovery catalog schema. RMAN> report need backup days 2 database; RMAN> report need backup days 2 tablespace system; RMAN> report obsolete; RMAN> report unrecoverable; To report on those datafiles that, if restored, woul d require application of two days (or more) worth of archived redo log files: To generate the same report but only for SYSTEM tablespace datafiles: To list backups considered obsolete Reports on all unrecoverable datafiles Complete Recovery using RMAN Case : 1. Take a full database backup. Shutdown the database and delete one datafile da ta1.dbf 2. Startup the database you will get an error. 3. Recover the datafile C:\> rman target / RMAN> run{ Allocate channel c1 type disk

format 'c:\sql\backup%U.bak'; Backup database;} Configuring RMAN and taking backup RMAN> show all; RMAN> configure channel device type disk format 'c:\sql\backup\name%U.bak'; RMAN> configure controlfile autobackup on; RMAN> configure retention policy to recovery window of 7 days; RMAN> configure datafile backup copies for device type disk to 2; RMAN> backup datafile 'c:\sql\data\ora1.dbf; RMAN> backup copies 2 datafile 2 format 'c:\%U','d:\%U'; RMAN> configure backup optimization on; RMAN> backup database;(will take full backup) RMAN> backup database;(will not take any backup since optimization is on, so try without optimization) RMAN> report need redundancy 3; RMAN> list backup; RMAN> report need backup redundancy 7; Using recover tablespace command : Case: 1. Create a tablespace using OMF and create a table in the same tablespace 2. create tablespace good datafile size 1M; 3. create table one ( a number); 4. insert into one values (1111); 5. commit; Now, shutdown the database and delete the data file of the tablespace "good" usi ng OS command. Startup the database in nomount stage. You will find error. From another session, run the following and after the recovery check for the tab lespace and table RMAN> run{ sql "alter database datafile 3 offline"; sql "alter database open"; sql "alter tablespace good offline immediate"; restore tablespace good; recover tablespace good; sql "alter tablespace good online"; } Incomplete Recovery (RMAN) - Until Time Case: 1. Create a table in one of your tablespace. 2. Force log switch.

3. Take backup using RMAN 4. Drop table and note down the drop time. Steps: 1. create table new (n number) tablespace good; 2. insert into new values (1111); 3. commit; 4. alter system switch logfile; 5. alter system switch logfile; 6. alter system switch logfile; RMAN> backup database; RMAN> drop table new; RMAN> alter system switch logfile; RMAN> alter system switch logfile; RMAN> alter system switch logfile; Now, shutdown the database and startup the database in mount stage. Recover the database until time. Time should be just before the table was dropped. RMAN> sql "ALTER SESSION SET NLS_DATE_FORMAT = ''DD-MON-YYYY HH24:MI:SS''"; RMAN> run{ set until time '26-DEC-2005 16:02:00'; restore database; recover database; sql "alter database open resetlogs"; } Until Sequence: Take backukp of the whole database RMAN> backup database; (From another session create a table and force log switch) RMAN> create table one (a number); RMAN> alter system switch logfile; RMAN> alter system switch logfile; Shutdown the database, delete one archive log file and datafile(non system) Startup the database Steps: -----1. Startup

From RMAN session recover the database RMAN> run{ set until sequence 11 thread 1; restore database; recover database; sql "alter database open resetlogs"; } RMAN different ways of taking backup RMAN> run { allocate channel c1 type disk; backup format 'c:\sql\back%U.bak' database; } RMAN> run{ allocate channel c1 type disk format 'c:\sql\backup%U.bak backup datafile 'c:\sql\data\one.dbf';} RMAN> run{ allocate channel c1 type disk format 'c:\sql\backup%U.bak backup (datafile 'c:\sql\data\cat.dbf) (datafile 'c:\sql\data\one.dbf') } RMAN> run{ allocate channel c1 type disk format 'c:\sql\backup%U.bak backup (datafile 'c:\sql\data\cat.dbf', 'c:\sql\data\good.dbf'); }

RMAN> run{ allocate channel c1 type disk format 'c:\sql\backup%U.bak backup (datafile 'c:\sql\data\cat.dbf', 'c:\sql\data\good.dbf' include current controlfile); } RMAN> run{ allocate channel c1 type disk BACKUP incremental level=0 format 'c:\sql\backup%U.bak (datafile 'c:\sql\data\good.dbf' tag=good); }

RMAN> run{ allocate channel c1 type disk allocate channel c2 type disk BACKUP incremental level=0 format 'c:\sql\back%U.bak' (datafile 1 channel c1 tag=good) (datafile 2,3 channel c2 tag=2_good); } RMAN> run{ allocate channel c1 type disk; BACKUP incremental level=0 format 'c:\sql\backup%U.bak' (database filesperset=2 include current controlfile); }

RMAN> run{ allocate channel c1 type disk; BACKUP format 'c:\sql\backup%U.bak' (archivelog from logseq=200 until logseq=221 thread=1 delete input); } RMAN> run{ allocate channel c1 type disk; COPY datafile 'c:\sql\data\good.dbf' to 'd:\bak\good.dbf' datafile 'c:\sql\data\good1.dbf' to 'd:\bak\good1.dbf' datafile 'c:\sql\data\system.dbf' to 'd:\bak\system.dbf'; } RMAN> run{ allocate channel c1 type disk copy datafile 'c:\sql\data\good.dbf' to 'd:\bak\good.dbf' datafile 'c:\sql\data\good.dbf' to 'd:\bak\good.dbf' archivelog 'c:\sql\archive\arch1.bak' to 'd:\bak\200.bak'); } RMAN> run{ allocate channel c1 type disk; allocate channel c2 type disk; backup incremental level=0 format 'c:\sql\bak\%U.bak' database; }

Restore the data-file to a new location -------------------------------------Shutdown the database and delete one datafile and startup Using RMAN restore to different location and recover RMAN> run{ set newname for datafile 5 to 'c:\sql\ASK\data\new.dbf'; restore database; switch datafile all; recover database; alter database open; }</eof </eof </eof RMAN SCRIPTS -------------------------------------------------------------------------------ALLOCATE CHANNEL -------------------------------------------------------------------------------ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS='SBT_LIBRARY=/mediavendor/lib/libobk.so ENV=(NSR_SERVER=tape_srv,NSR_ GROUP=oracle_tapes)'; ALLOCATE CHANNEL ch3 DEVICE TYPE DISK FORMAT '/disk1/%d_backups/%U'; ALLOCATE CHANNEL ch3 DEVICE TYPE sbt; ALLOCATE AUXILIARY CHANNEL aux1 DEVICE TYPE DISK; ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK; --------------------------------------------------------------------------------------CONFIGURE -------------------------------------------------------------------------------------CONFIGURE CHANNEL DEVICE TYPE sbt PARMS='SBT_LIBRARY=/mediavendor/lib/libobk.so ENV=(NSR_SERVER=tape_svr,NSR_CLIENT=oracleclnt,NSR_GROUP=ora_tapes)' FORMAT "BACKUP_%U"; OTHERS CONFIGURE MAXSETSIZE TO 7500K; CONFIGURE MAXSETSIZE = 100M;

CONFIGURE AUXNAME FOR DATAFILE 2 TO '/newdisk/datafiles/df2.df;' CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/oracle/oradata/trgt/snap_trgt.ctl'; CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 2; CLEAR CONFIGURE CONFIGURE CONFIGURE CONFIGURE CONFIGURE CONFIGURE DUPLEXING CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE sbt TO 2; CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 2; CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE sbt TO 2; DEVICE CONFIGURE CONFIGURE CONFIGURE CONFIGURE CONFIGURE DEVICE TYPE sbt PARALLELISM 1; DEVICE TYPE DISK PARALLELISM 3; DEFAULT DEVICE TYPE TO sbt; DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO COPY; DEVICE TYPE 'SBT_TAPE' PARALLELISM 2 BACKUP TYPE TO BACKUPSET; EXCLUDE FOR TABLESPACE cwmlite CLEAR; AUXNAME FOR DATAFILE 2 CLEAR; CHANNEL DEVICE TYPE sbt CLEAR; CHANNEL 3 DEVICE TYPE DISK CLEAR; DEVICE TYPE DISK CLEAR; DEFAULT DEVICE TYPE CLEAR;

CHANNEL DISK CONFIGURE CONFIGURE CONFIGURE CONFIGURE CONFIGURE CONFIGURE CONFIGURE CHANNEL CHANNEL CHANNEL CHANNEL CHANNEL CHANNEL CHANNEL DEVICE TYPE DISK MAXPIECESIZE = 2G; DEVICE TYPE sbt RATE 1M; DEVICE TYPE DISK FORMAT = /tmp/%U; DEVICE TYPE DISK FORMAT '/save1/%U', '/save2/%U'; DEVICE TYPE DISK MAXPIECESIZE = 2M; 3 DEVICE TYPE DISK MAXPIECESIZE = 900K; DEVICE TYPE sbt PARMS 'ENV=(NSR_DATA_VOLUME_POOL=first_pool)';

CONTROL-FILE CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE CONTROLFILE AUTOBACKUP OFF; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/u02/%F'; OPTIMIZATION CONFIGURE BACKUP OPTIMIZATION ON; CONFIGURE BACKUP OPTIMIZATION OFF; CONFIGURE BACKUP OPTIMIZATION CLEAR; -----------------------------------------------------------------BACKUP SCRIPTS ----------------------------------------------------------------DATABASE BACKUP BACKUP BACKUP BACKUP DATABASE; DATABASE FORMAT '/tmp/%U', '?/dbs/%U', '?/oradata/%U'; DEVICE TYPE sbt COPY OF DATABASE; DEVICE TYPE sbt COPY OF DATABASE DELETE INPUT;

BACKUP BACKUP BACKUP b_%U',

FORMAT = 'UW_%d/%t/%s/%p' ARCHIVELOG LIKE '%arc_dest%'; TAG 'weekly_full_db_bkup' DATABASE MAXSETSIZE 10M; AS COMPRESSED BACKUPSET DEVICE TYPE DISK COPIES 2 DATABASE FORMAT '/u01/d '/u02/db_%U';

CONTROL-FILE BACKUP DEVICE TYPE sbt CURRENT CONTROLFILE; BACKUP CURRENT CONTROLFILE TO DESTINATION '/u01/backups'; BACKUP AS COPY CURRENT CONTROLFILE; SPFILE BACKUP SPFILE TO DESTINATION '/u01/backups'; TABLESPACE BACKUP BACKUP BACKUP BACKUP TABLESPACE users; TABLESPACE users FORMAT = '/tmp/users_%u%p%c'; TABLESPACE tools MAXSETSIZE 5G; AS COPY TABLESPACE system, tools, users, undotbs;

DATAFILE BACKUP BACKUP BACKUP BACKUP BACKUP BACKUP BACKUP U'; DATAFILE 5,6,7; DATAFILE 5; DATAFILE 6; DATAFILE 7; DATAFILE 1 FORMAT '/u01/backups/%U', '/u02/backups/%U'; DATAFILE 6 TO '/u01/backups', '/u02/backups'; DEVICE TYPE DISK COPIES 3 DATAFILE 7 FORMAT '/tmp/%U','?/oradata/%U','?/%

ARCHIVELOG BACKUP BACKUP BACKUP BACKUP BACKUP PROXY BACKUP DEVICE TYPE sbt PROXY DATAFILE 3; BACKUP DEVICE TYPE sbt PROXY ONLY DATABASE; BACKUP DEVICE TYPE sbt PROXY ONLY ARCHIVELOG ALL; BACKUP-SET BACKUP BACKUP BACKUP BACKUP BACKUP backup DEVICE TYPE sbt COPIES 2 DEVICE DEVICE TYPE sbt DEVICE TYPE sbt DEVICE TYPE sbt backupset ; BACKUPSET ALL; TYPE sbt BACKUPSET ALL; BACKUPSET COMPLETED BEFORE 'SYSDATE-7' DELETE INPUT; BACKUPSET ALL; BACKUPSET ALL DELETE INPUT; DEVICE TYPE sbt ARCHIVELOG ALL; NOT BACKED UP SINCE TIME 'SYSDATE-14' DATABASE PLUS ARCHIVELOG; ARCHIVELOG ALL; ARCHIVELOG FROM SEQUENCE 288 UNTIL SEQUENCE 388 THREAD 1 DELETE INPUT; DEVICE TYPE sbt ARCHIVELOG ALL FROM TIME 'SYSDATE-10' DELETE ALL INPUT;

BACKUP DEVICE TYPE DISK AS BACKUPSET DATABASE PLUS ARCHIVELOG;

BACKUP AS BACKUPSET DATAFILE 1; BACKUP AS BACKUPSET (DATAFILE 3, 4, 5, 6, 7) (DATAFILE 8, 9); BACKUP AS BACKUPSET DATAFILE 3, 4, 5, 6, 7, 8, 9; BACKUP AS BACKUPSET DEVICE TYPE DISK COPIES 3 INCREMENTAL LEVEL 0 DATABASE; BACKUP AS BACKUPSET DATAFILE 1,2,3,4 CHANNEL ch1 CONTROLFILECOPY '/tmp/control01.ctl' CHANNEL ch2 BACKUP AS BACKUPSET ARCHIVELOG FROM TIME 'SYSDATE-14' CHANNEL ch3; TAG BACKUP AS BACKUPSET TAG for_audit COPY OF TABLESPACE users FROM TAG monday_users TABLESPACE SYSTEM FROM TAG monday _system; BACKUP ARCHIVELOG ALL TAG first_copy; DELETE ARCHIVELOG ALL BACKED UP 2 TIMES TO DEVICE TYPE sbt; BACKUP DEVICE TYPE sbt DATAFILECOPY FROM TAG 'LATESTCOPY' FORMAT 'Datafile%f_Dat abase%d'; BACKUP TAG 'weekly_full_db_bkup' DATABASE MAXSETSIZE 10M; POLICY BASED BACKUP DATABASE KEEP UNTIL TIME "TO_DATE('31-DEC-2007' 'dd-mon-yyyy')" NOLOGS; BACKUP DATABASE NOT BACKED UP SINCE TIME 'SYSDATE-1'; BACKUP MAXSETSIZE 10G DATABASE PLUS ARCHIVELOG; BACKUP NOT BACKED UP SINCE TIME 'SYSDATE-1' MAXSETSIZE 10M DATABASE PLUS ARCHIVE LOG; BACKUP TABLESPACE users KEEP FOREVER NOLOGS; BACKUP MAXSETSIZE = 100M ARCHIVELOG ALL; BACKUP ARCHIVELOG FROM TIME 'SYSDATE-1' UNTIL TIME 'SYSDATE'; BACKUP BACKUP BACKUP BACKUP BACKUP DURATION DURATION DURATION DURATION DURATION 3:30 4:00 4:00 4:00 4:00 DATABASE; TABLESPACE users; PARTIAL TABLESPACE users FILESPERSET 1; PARTIAL MINIMIZE TIME DATABASE FILESPERSET 1; PARTIAL MINIMIZE LOAD DATABASE FILESPERSET 1;

BACKUP DATABASE FORCE; BACKUP ARCHIVELOG ALL FORCE; EXCLUDING CONFIGURE EXCLUDE FOR TABLESPACE cwmlite; CONFIGURE EXCLUDE FOR TABLESPACE example; BACKUP DATABASE NOEXCLUDE; BACKUP TABLESPACE cwmlite, example; CONFIGURE EXCLUDE FOR TABLESPACE cwmlite CLEAR;

CONFIGURE EXCLUDE FOR TABLESPACE example CLEAR; BACKUP DATABASE SKIP INACCESSIBLE SKIP READONLY SKIP OFFLINE; -------------------------------------------------------------------RESTORE -------------------------------------------------------------------RESTORE CONTROLFILE; RESTORE CONTROLFILE FROM AUTOBACKUP; RESTORE SPFILE FROM AUTOBACKUP; RESTORE DATAFILE '?/oradata/trgt/tools01.dbf'; -------------------------------------------------------------------------------RECOVERY -------------------------------------------------------------------------------RECOVER DATABASE NOREDO; RECOVER TABLESPACE users, tools UNTIL LOGSEQ 1300 THREAD 1 RECOVER RECOVER RECOVER RECOVER DATABASE TEST DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL TEST TABLESPACE users TEST DATABASE UNTIL CANCEL TEST

BLOCK RECOVERY BLOCKRECOVER DATAFILE 7 BLOCK 3 DATAFILE 2 BLOCK 235; BLOCKRECOVER BLOCKRECOVER BLOCKRECOVER BLOCKRECOVER BLOCKRECOVER BLOCKRECOVER ; DATAFILE DATAFILE DATAFILE DATAFILE DATAFILE DATAFILE 8 8 8 8 8 8 BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK 13 13 13 13 13 13 DATAFILE DATAFILE DATAFILE DATAFILE DATAFILE DATAFILE 2 2 2 2 2 2 BLOCK BLOCK BLOCK BLOCK BLOCK BLOCK 19 FROM BACKUPSET; 19 FROM DATAFILECOPY; 199 FROM TAG = mondayam; 19 RESTORE UNTIL 'SYSDATE-7'; 19 RESTORE UNTIL SCN 100; 19 RESTORE UNTIL SEQUENCE 7024

BLOCKRECOVER CORRUPTION LIST RESTORE UNTIL TIME 'SYSDATE-10'; ------------------------------------------------------------MANAGING -------------------------------------------------------------SHOWING SHOW SHOW SHOW SHOW SHOW SHOW SHOW CHANNEL FOR DEVICE TYPE sbt; DEFAULT DEVICE TYPE; CHANNEL; BACKUP OPTIMIZATION; DATAFILE BACKUP COPIES; EXCLUDE; AUXNAME;

SHOW show show show show show show show show

SNAPSHOT CONTROLFILE NAME; datafile backup copies; archivelog backup copies; controfile autobackup; device type; encryption algorithm; maxsetsize; retention policy; retention policy to redundancy;

CHECKING CROSSCHECK CROSSCHECK CROSSCHECK CROSSCHECK CROSSCHECK CROSSCHECK CROSSCHECK BACKUPPIECE BACKUPSET OF TABLESPACE UWDATA; COPY OF ARCHIVELOG ALL; CONTROLFILECOPY DATAFILECOPY ALL; FOREIGN ARCHIVELOG ALL; PROXY 941;

BACKUP CHECK LOGICAL DATABASE; BACKUP VALIDATE DATABASE ARCHIVELOG ALL; BACKUP VALIDATE CHECK LOGICAL DATABASE ARCHIVELOG ALL; LIST LIST LIST LIST LIST BACKUP; BACKUP SUMMARY; SCRIPT NAMES; GLOBAL SCRIPT NAMES; ALL SCRIPT NAMES;

Reduntancy CONFIGURE RETENTION POLICY TO REDUNDANCY 2; CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS; CONFIGURE RETENTION POLICY TO NONE; CHANGE CHANGE CHANGE CHANGE BACKUP TAG 'db_archive_1' UNAVAILABLE; BACKUPSET TAG year_end_2002 KEEP FOREVER NOLOGS; BACKUPSET TAG year_end_2002 NOKEEP; BACKUPSET 2 NOKEEP;

DELETION DELETE DELETE DELETE DELETE DELETE DELETE DELETE DELETE NOPROMPT BACKUP OF DATABASE COMPLETED BEFORE 'SYSDATE-7'; ARCHIVELOG ALL COMPLETED AFTER 'SYSDATE-7'; BACKUP DEVICE TYPE sbt; BACKUP DEVICE TYPE DISK; COPY; COPY TAG 'LATESTCOPY'; SCRIPT 'full_backup'; GLOBAL SCRIPT 'global_full_backup';

VALIDATE VALIDATE VALIDATE VALIDATE VALIDATE VALIDATE ARCHIVELOG ARCHIVELOG ARCHIVELOG ARCHIVELOG ARCHIVELOG ALL LIKE '' FROM SCN BETWEEN SCN AND SCN UNTIL SCN

VALIDATE ARCHIVELOG VALIDATE ARCHIVELOG VALIDATE ARCHIVELOG VALIDATE ARCHIVELOG TIME BETWEEN '' AND UNTIL TIME ''

FROM SEQUENCE [THREAD ] SEQUENCE [THREAD ] SEQUENCE BETWEEN AND UNTIL SEQUENCE [THREAD ] ''

VALIDATE CONTROLFILECOPY ALL VALIDATE CONTROLFILECOPY '' VALIDATE CONTROLFILECOPY LIKE '' VALIDATE VALIDATE VALIDATE VALIDATE COPY COPY COPY COPY OF OF OF OF DATABASE DATAFILE '' DATAFILE TABLESPACE '

VALIDATE VALIDATE VALIDATE VALIDATE VALIDATE VALIDATE VALIDATE VALIDATE VALIDATE

CURRENT CONTROLFILE DATABASE DATAFILE '' DATAFILE DB_RECOVERY_FILE_DEST RECOVERY AREA RECOVERY FILES SPFILE TABLESPACE

OTHERS SCRIPTS ENCRYTION CONFIGURE ENCRYPTION FOR DATABASE ON; CONFIGURE ENCRYPTION FOR TABLESPACE uwdata OFF; SET ENCRYPTION ON CONFIGURE ENCRYPTION FOR DATABASE OFF CONFIGURE ENCRYPTION ALGORITHM 'AES256'; CONFIGURE COMPRESSION ALGORITHM 'ZLIB'; CONFIGURE ENCRYPTION CLEAR; CATALOG BASED REGISTER DATABASE; RESYNC CATALOG; REPORT SCHEMA; CATALOG DATAFILECOPY '/disk1/old_datafiles/01_01_2003/users01.dbf'; CATALOG ARCHIVELOG '/disk1/arch_logs/archive1_731.dbf','/disk1/arch_logs/archive 1_732.dbf'; CATALOG START WITH '/disk1/backups/'; UNREGISTER DATABASE; OTHERS SET NEWNAME FOR DATAFILE '?/oradata/trgt/tools01.dbf' TO '/tmp/tools01.dbf'; SWITCH DATAFILE '/tmp/tools01.dbf' TO DATAFILECOPY '?/oradata/trgt/tools01.dbf'; RESTORE SPFILE TO PFILE '?/oradata/test/inittrgta.ora' FROM AUTOBACKUP; DUPLICATE TARGET DATABASE TO 'dupdb'; DUPLICATE TARGET DATABASE TO dupdb NOFILENAMECHECK UNTIL TIME 'SYSDATE-7';

INCREMENTAL BACKUP BACKUP BACKUP BACKUP INCREMENTAL INCREMENTAL INCREMENTAL INCREMENTAL LEVEL LEVEL LEVEL LEVEL 0 1 1 1 DATABASE; DIFFERENTIAL TABLESPACE users; CUMULATIVE DATABASE; CUMULATIVE SKIP INACCESSIBLE DATABASE;

You might also like