Pages

Thursday, July 14, 2011

RMAN By Example


 @
·         You can create a script and run it, you can use @ Running a Command File from the Command Line: Example This example creates a command file and then runs it from the operating system command line:
o    echo "BACKUP DATABASE;" > backup_db.rman
o    rman TARGET / @backup_db.rman

·         Running a Command File Within RMAN: Example This example runs a command file from the RMAN prompt and from within a RUN command:
o    @backup_db.rman
o    RUN { @backup_db.rman }

@@

·         Calling a Command File within another Command File: Example Assume that you create command files called backup_logs.rman and backup_db.rman as in the following example. Then, you execute bkup_db.rman from the command line, which specifies that RMAN should look for the bkup_logs.rman script in the Oracle home directory:
o    echo "BACKUP ARCHIVELOG ALL;" > $ORACLE_HOME/bkup_logs.rman
o    echo "BACKUP DATABASE;" > $ORACLE_HOME/bkup_db.rman
o    echo "@@bkup_logs.rman" >> $ORACLE_HOME/bkup_db.rman
o    rman TARGET / @$ORACLE_HOME/bkup_db.rman

Allocate:
·         Allocating a Single Channel for a Backup: Example This command allocates a tape channel for a whole database and archived redo log backup:
o    RUN
o    {
o      ALLOCATE CHANNEL c1 DEVICE TYPE sbt;
o      BACKUP DATABASE PLUS ARCHIVELOG;
o    }

·         Spreading a Backup Across Multiple Disks: Example When backing up to disk, you can spread the backup across several disk drives. Allocate one DEVICETYPE DISKchannelforeachdiskdriveandspecifytheformatstringsothatthefilenames are on different disks:
o    RUN
o    {
o      ALLOCATE CHANNEL disk1 DEVICE TYPE DISK FORMAT '/disk1/backups/%U';
o      ALLOCATE CHANNEL disk2 DEVICE TYPE DISK FORMAT '/disk2/backups/%U';
o      BACKUP DATABASE PLUS ARCHIVELOG; # AS COPY is default when backing up to #disk
o    }

·         Creating Multiple Copies of a Backup: Example When creating multiple copies of a backup, you can specify the SET BACKUP COPIES command. The following example generates a single backup of the database to disk, and then creates two identical backups of datafile1 to two different file systems:
o    RUN
o    {
o      ALLOCATE CHANNEL c1 DEVICE TYPE DISK MAXPIECESIZE 5M;
o      BACKUP DATABASE PLUS ARCHIVELOG; # AS COPY is the default, so RMAN                         #creates image copies
o      SET BACKUP COPIES = 2;
o      BACKUP DATAFILE 1 FORMAT '/disk1/backups/%U', '/disk2/backups/%U';
o    }

·         Allocating an Auxiliary Channel for Database Duplication: Example When creating a duplicate database, allocate a channel by using the AUXILIARY option:
o    RUN
o    {
o      ALLOCATE AUXILIARY CHANNEL c1 DEVICE TYPE sbt;
o      ALLOCATE AUXILIARY CHANNEL c2 DEVICE TYPE sbt;
o      DUPLICATE TARGET DATABASE TO ndbnewh
o        LOGFILE
o          ' /oradata/aux1/redo01.log' SIZE 200K,
o          ' /oradata/aux1/redo02.log' SIZE 200K
o          ' /oradata/aux1/redo03.log' SIZE 200K
o      SKIP READONLY
o      NOFILENAMECHECK;
o    }

·         Configuring an Automatic Channel: Example This example configures a persistent disk channel:
o    CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT = ' /oradata/bkup_%U';

·         Configuring a Channel for a Backup: Example This example manually allocates an sbt channel and then runs a whole database backup:
o    RUN
o    {
o    ALLOCATE CHANNEL c1 DEVICE TYPE sbt MAXPIECESIZE 800M;
o      BACKUP DATABASE;
o    }

·         Allocating a Channel for a Backup: Example this example configures a default media management library, then makes a database backup by using this library. Then, the example backs up the database again using a different library, then finally makes a third backup using the default library:
o    CONFIGURE DEFAULT DEVICE TYPE TO sbt;
o    CONFIGURE CHANNEL DEVICE TYPE sbt PARMS="SBT_LIBRARY=/mediavendor/lib/mm_lib1.so";
o    BACKUP DATABASE;
o    RUN
o    {
o      ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS="SBT_LIBRARY=/mediavendor/lib/mm_lib2.so";
o      BACKUP DATABASE;
o    }
o    BACKUP ARCHIVELOG ALL;

·         Opening the Database After a Backup: Example This example mounts the database, takes a whole database backup, then opens the database. At the RMAN prompt enter:
o    STARTUP MOUNT;
o    BACKUP DATABASE;
o    # now that the backup is complete, open the database.
o    ALTER DATABASE OPEN;
·         Mounting the Database After Restoring the Control File: Example To restore the control file to its default location when connected to a recovery catalog, enter the following:
o    STARTUP NOMOUNT;
o    RESTORE CONTROLFILE;
o    ALTER DATABASE MOUNT;
o    # you must run the RECOVER command after restoring a control file even if no datafiles
o    # require recovery
o    RECOVER DATABASE;
o    ALTER DATABASE OPEN RESETLOGS;
o    # if the database uses locally-managed temporary tablespaces, then you must add tempfiles
o    # to these tablespaces after restoring a backup control file
o    SQL " ALTER TABLESPACE temp ADD TEMPFILE '' /oradata/trgt/temp01.dbf'' REUSE";

·         Performing RESETLOGS After Incomplete Recovery: ExampleThisexampleuses a manually allocated channel to perform incomplete recovery and then resets the online redo logs:
o    RUN
o    {
o      ALLOCATE CHANNEL ch1 DEVICE TYPE sbt;
o    SET UNTIL SCN 1024;
o      RESTORE DATABASE;
o      RECOVER DATABASE;
o      ALTER DATABASE OPEN RESETLOGS;
o    }


Control File Auto backups
  • If CONFIGURE CONTROLFILE AUTOBACKUP is set to ON, then RMAN automatically backs up the control file after BACKUP commands.

Backup:
·         Backing Up a Database: Example This example assumes that CONFIGURE CONTROLFILE AUTOBACKUP is OFF. The command backs up all datafiles to tape, as well as the current control file, the server parameter file, and archived logs:
o    BACKUP DATABASE PLUS ARCHIVELOG;

·         Scripting Incremental Backups: Example This example shows a series of scripts that you can run to make regular incremental backups of the database:
o    # Run once a week to back up database to disk as level 0:
o    BACKUP INCREMENTAL LEVEL 0 DATABASE;
o    # Run every day to back up blocks that have changed since most recent level 0 or 1:
o    BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;
o    BACKUP INCREMENTAL LEVEL 1 DIFFERENTIAL TABLESPACE users;

·         Performing a Cumulative Incremental Backup: Example This example backs up All blocks changed in the database since the most recent level 0 backup:
o    BACKUP INCREMENTAL LEVEL 1 CUMULATIVE SKIP INACCESSIBLE DATABASE;

·         Backing Up Tablespaces and Datafiles to Disk: Example This command uses two backupSpec clauses to back up tablespaces and datafiles and lets RMAN perform automatic parallelization of the backup:
o    RUN
o    {
o      ALLOCATE CHANNEL dev1 DEVICE TYPE DISK FORMAT '/disk1/%U';
o      ALLOCATE CHANNEL dev2 DEVICE TYPE DISK FORMAT '/disk2/%U';
o      BACKUP
o        (TABLESPACE SYSTEM, tools, users, undotbs MAXSETSIZE 5M)
o        (DATAFILE 2,4,5);
o    }

·         Backing Up Tablespaces and Datafiles to Disk: Example This command uses two backupSpec clauses to back up tablespaces and datafiles and lets RMAN perform automatic parallelization of the backup:
o    RUN
o    {
o      ALLOCATE CHANNEL dev1 DEVICE TYPE DISK FORMAT '/disk1/%U';
o      ALLOCATE CHANNEL dev2 DEVICE TYPE DISK FORMAT '/disk2/%U';
o      BACKUP AS COPY
o        (TABLESPACE SYSTEM, tools, users, undotbs MAXSETSIZE 5M)
o        (DATAFILE 2,4,5);
o    }

·         Backing Up Datafile Copies: Example This example finds three Datafile copies with the tag LATESTCOPY, copies them to directory/copies and names the copies by means of substitution variables:
o    BACKUP AS COPY
o       FROM TAG 'LATESTCOPY'
o      COPY OF DATAFILE 4, 6, 14
o      FORMAT '/copies/Datafile%f_Database%d';

·         Backing Up Archived Logs and Deleting the Input: Example This example assumes that you have two archive destinations set:/arch1 and/arch2. The command backs up one log for each unique sequence number and then deletes all logs from both archiving directories.
o    BACKUP ARCHIVELOG LIKE '/arch%' DELETE ALL INPUT;

·         Specifying DEVICE TYPE on the BACKUP Command: Example This example configures DISK as the default device type, then backs up the server parameter file and all archived logs to tape:
o    # when disk is the default device and you do not specify a FORMAT parameter, then the
o    # default backup location is the flash recovery area (if configured) or
o    # a platform-specific default location (if not configured)
o    CONFIGURE DEFAULT DEVICE TYPE TO DISK;
o    BACKUP DEVICE TYPE sbt SPFILE ARCHIVELOG ALL;

·         Duplexing a Backup Set: Example This example duplexes a backup of datafile1 (which includes the current control file and server parameter file) to separate disks:
o    BACKUP DEVICE TYPE DISK
o      COPIES 2 DATAFILE 1
o      FORMAT '/disk1/df1_%U', '/disk2/df1_%U';

·         Creating a Control File for a Standby Database: Example This example creates a backup of the current control file that can be used to create a standby database:
o    BACKUP CURRENT CONTROLFILE FOR STANDBY;

·         Checking for Corruption: Example This example backs up datafile3 and specifies that no more than two blocks with corruption should be tolerated:
o    RUN
o    {
o      SET MAXCORRUPT FOR DATAFILE 3 TO 2;
o      BACKUP CHECK LOGICAL
o        DATAFILE 3;
o    }

·         Creating a Long-Term Database Backup: Example This example creates a consistent backup of the database and server parameter file that is exempt from the retention policy. The command instructs RMAN to keep the backup for the next year, but not to keep the archived logs necessary to recover it:
o    SHUTDOWN IMMEDIATE;
o    STARTUP MOUNT;
o    BACKUP DATABASE
o      KEEP UNTIL TIME 'SYSDATE+365'
o      NOLOGS;
o    ALTER DATABASE OPEN;

·         Backing Up Files That Need Backups: Example This example backs up all datafiles that have not been backed up to tape in the last month, and then backs up all archived logs that do not have at least two backups on tape:
o    BACKUP DEVICE TYPE sbt DATABASE NOT BACKED UP SINCE TIME 'SYSDATE-31';

·         Using NODUPLICATES To Back Up Datafile Copies: Example This example creates several duplicate datafiles, and then backs up only the most recent of the duplicates:
o    RMAN> backup as copy Datafile 10 format 'foo' tag my_tag;
o    RMAN> backup as copy datafilecopy 'foo' format 'bar';
o    RMAN> backup as copy datafilecopy 'bar' format 'foobar';
o    RMAN>backup as backupset datafilecopy all noduplicates; # backs up only ’foobar’
o    RMAN>backup as backupset datafilecopy all; # backs up all files

·         Recovering a Group of Corrupt Blocks: Example This example recovers corrupt blocks in three datafiles:
o    BLOCKRECOVER DATAFILE 2 BLOCK 12, 13 DATAFILE 3 BLOCK 5, 98, 99 DATAFILE 4 BLOCK 19;

·         Limiting Block Media Recovery by Type of Restore: Example The following example recovers a series of blocks and restores only from Datafile copies:
o    RUN
o    {
o      BLOCKRECOVER DATAFILE 3 BLOCK 2,3,4,5 TABLESPACE sales DBA 4194405, 4194409, 4194412
o      FROM DATAFILECOPY;
o    }

·         Limiting Block Media Recovery by Time: Example The following example recovers two blocks in the SYSTEM tablespace. It restores only from backups that could be used to recover the database to a point two days ago:
o    BLOCKRECOVER TABLESPACE SYSTEM DBA 4194404, 4194405 RESTORE UNTIL TIME 'SYSDATE-2';

·         Repairing All Block Corruption in the Database: Example The following example runs a backup validation to populate V$DATABASE_BLOCK_CORRUPTION, then repairs any corrupt blocks recorded in the view:
o    BACKUP VALIDATE DATABASE;
o    BLOCKRECOVER CORRUPTION LIST;


Use CONFIGURE to set the following:
·         An ongoing retention policy that automatically determines which backups and copies are eligible for deletion because they are no longer needed
·         The device type (for example, DISK orsbt) for RMAN jobs  The default number of channels of each device type that RMAN should allocate
·         for automated backup and restore jobs
·         The settings for automatic channels for a specified device type
·         The maximum size of backup pieces and sets created on automatic channels
·         Backup optimization either ON or OFF
·         The exclusion policy for tablespaces in whole database backups
·         The filename of the snapshot control file
·         Filenames for files in an auxiliary database
·         The control file autobackup feature to ON or OFF
  • The default format for the control file autobackup output files.

·         Configuring Backup Optimization: ExampleThis example configures RMAN so that the BACKUP command does not backup files to a device type if the identical file has already been backed up to the device type:
o    CONFIGURE BACKUP OPTIMIZATION ON;

·         Configuring a Retention Policy: Example This example configures a retention policy with a recovery window of 2 weeks, and then resets the retention policy to its default value of REDUNDANCY=1:
o    CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS;
o    CONFIGURE RETENTION POLICY CLEAR;

·         Connecting Without a Recovery Catalog: Example This example starts RMAN and then connects to the target database with an Oracle Net service nameprod1:
o    % rman NOCATALOG
o    RMAN> CONNECT TARGET sys/change_on_install@prod1;
·         Connecting in the Default NOCATALOG Mode: Example This example starts RMAN and then connects to the target through Oracle Net. Because BACKUP is run and no CONNECTCATALOG has been run, RMAN defaults to NOCATALOG mode:
o    % rman
o    RMAN> CONNECT TARGET sys/change_on_install@prod1;
o    RMAN> BACKUP DATAFILE 7;
# You cannot run CONNECT CATALOG after this point because RMAN has defaulted to NOCATALOG
·         Connecting with a Recovery Catalog: Example This example starts RMAN and then connects to the target databaseprod1 by using operating system authentication and the recovery catalog databasercat by using a password file:
o    % rman
o    RMAN> CONNECT TARGET /
o    RMAN> CONNECT CATALOG rman/rman@rcat

No comments:

Post a Comment