oracle rman demo

Upload: coolair1584956

Post on 09-Apr-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 Oracle RMAN Demo

    1/24

    Oracle RMAN DemoVersion 10.2

    Mount the NetApp

    192.0.0.1 bigdog.psoug.org --> RMAN Database

    192.168.2.200 --> PROD Database

    $ cd /etc

    $ vi hosts on PROD box

    -- append the following

    192.0.0.1 bigdog.psoug.org bigdog

    -- save change

    $ ping bigdog.psoug.org

    $ ping bigdog

    Modify TNSNAMES.ORA

    -- as oracle on PROD box$ ping bigdog.psoug.org

    cd $ORACLE_HOME/network/admin

    vi tnsnames.ora

    -- add the following:

    RMAN =

    (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.0.0.1)(PORT = 1521))

    (CONNECT_DATA =

    (SERVER = DEDICATED)

    (SERVICE_NAME = RMAN)

    )

    )

    -- save change

    $ lsnrctl start

    $ lsnrctl status

    $ tnsping RMAN

    Put the PROD Database into Archive Log Mode

    -- as oracle

    $ sqlplus /nolog

    SQL> conn / as sysdba

    SQL> startup nomount;col name format a30

    col value format a30

    SELECT name, value

    FROM v$parameter

    WHERE name LIKE '%arch%';

    SQL> CREATE pfile FROM spfile;

    -- alter the SPFILE as required.

    Open a Terminal window

    $ cd $ORACLE_HOME/dbs

    $ ls -la

    $ vi initorcl.ora-- append archive log destination

    1

  • 8/7/2019 Oracle RMAN Demo

    2/24

    log_archive_dest = '/u01'

    -- save changes

    SQL> shutdown immediate;

    SQL> CREATE spfile FROM pfile;

    SQL> startup mount exclusive;

    SQL> alter database archivelog;SQL> alter database open;

    SQL> alter system switch logfile;

    In Terminal Window

    cd /u01

    ls -la

    Create Repository Tablespace and Schema

    SQL> conn sys@RMAN AS SYSDBA

    password: xxxxxx##

    SQL> SELECT file_name

    FROM dba_data_files;

    SQL> SELECT name, value

    FROM v$parameter

    WHERE name like '%block%';

    SQL> CREATE TABLESPACE RMAN DATAFILE

    '/app/oracle/product/OracleHomes/oradata/emrep/RMAN_DATA.dbf'

    SIZE 50M

    AUTOEXTEND OFFBLOCKSIZE 8192

    FORCE LOGGING

    DEFAULT NOCOMPRESS

    EXTENT MANAGEMENT LOCAL UNIFORM SIZE 64K

    SEGMENT SPACE MANAGEMENT AUTO

    FLASHBACK ON ONLINE;

    SQL> CREATE USER RMAN

    IDENTIFIED BY RMAN

    DEFAULT TABLESPACE RMAN

    TEMPORARY TABLESPACE tempQUOTA UNLIMITED ON RMAN;

    SQL> GRANT create session TO RMAN;

    SQL> GRANT resource TO RMAN;

    SQL> GRANT recovery_catalog_owner TO RMAN;

    SQL> GRANT execute ON dbms_stats TO RMAN;

    SQL> CREATE OR REPLACE PUBLIC SYNONYM dbms_stats FOR sys.dbms_stats;

    SQL> RMAN@RMAN

    SQL> SELECT COUNT(*) FROM user_objects;

    Create RMAN Catalog

    2

  • 8/7/2019 Oracle RMAN Demo

    3/24

    $ rman target / catalog RMAN/RMAN@RMAN

    RMAN> create catalog tablespace RMAN;

    RMAN> register database;

    Explore the RMAN Catalog

    SQL> SELECT object_type, COUNT(*)

    FROM user_objects

    GROUP BY object_type;

    SQL> SELECT COUNT(*) FROM user_objects;

    Spread the backup across several disk drives. Allocate one DEVICE TYPE DISK channel for each disk driveand specify the format string so that the filenames are on different disks

    RUN

    {

    ALLOCATE CHANNEL disk1 DEVICE TYPE DISK FORMAT '/disk1/backups/

    %U';

    ALLOCATE CHANNEL disk2 DEVICE TYPE DISK FORMAT '/disk2/backups/

    %U';# AS COPY is default when backing up to disk

    BACKUP DATABASE PLUS ARCHIVELOG;

    }

    When creating multiple copies of a backup, you can specify the SET BACKUP COPIES command. The followingexample generates a single backup of the database to disk, and then creates two identical backups of datafile 1to two different file systems

    RUN

    {

    ALLOCATE CHANNEL c1 DEVICE TYPE DISK MAXPIECESIZE 5M;

    # AS COPY is the default, so RMAN creates image copies

    BACKUP DATABASE PLUS ARCHIVELOG;SET BACKUP COPIES = 2;

    BACKUP DATAFILE 1 FORMAT '/disk1/backups/%U', '/disk2/backups/%U';

    }

    When creating a duplicate database, allocate a channel by using the AUXILIARY option

    RUN

    {

    ALLOCATE AUXILIARY CHANNEL c1 DEVICE TYPE sbt;

    ALLOCATE AUXILIARY CHANNEL c2 DEVICE TYPE sbt;

    DUPLICATE TARGET DATABASE TO ndbnewh

    LOGFILE

    '?/oradata/aux1/redo01.log' SIZE 200K,'?/oradata/aux1/redo02.log' SIZE 200K

    '?/oradata/aux1/redo03.log' SIZE 200K

    SKIP READONLY

    NOFILENAMECHECK;

    }

    Startup

    $ rman

    $ rman TARGET / CATALOG rman/rman@rman

    RMAN> STARTUP MOUNT

    $ rman TARGET SYS/oracle@trgt NOCATALOG

    $ rman TARGET / CATALOG rman/rman@rman AUXILIARY SYS/oracle@auxdb

    RMAN Create Catalog Demo

    3

  • 8/7/2019 Oracle RMAN Demo

    4/24

    $ rman

    RMAN> connect rcvcat rman/rman

    RMAN> connect target sys/coi@infradb

    RMAN> create catalog;

    RMAN> register database;

    database registered in recovery catalog

    starting full resync of recovery catalogfull resync complete

    RMAN Backup Demo

    $ rman

    RMAN> connect rcvcat rman/rman

    RMAN> connect target sys/coi@infradb

    RMAN> run {

    2> allocate channel c1 type disk;

    3> backup database format '/nfs/curly/rman/o1/%u';

    4> release channel c1;

    5> }

    database registered in recovery catalogstarting full resync of recovery catalog

    full resync complete

    RMAN Demo 1

    Target Database Not Running in Archive Log Mode

    CONFIGURATIONThere are various parameters that can be used to configure RMAN operations to suit your needs. Some of thethings that you can configure are:- the required number of backups of each datafile- the number of server processes that will do backup/restore operations

    in parallel- the directory where on-disk backups will be stored

    This case study assumes that you want:- 5 backups of each datafile- backups to be stored on disk in the /backup directory- 2 server processes to do backup/restore operations in parallel- no backups for tablespace tbl_exclude, because it is easy to recreate

    It should be noted that configuration settings are stored persistently, and will be used by RMAN for allsubsequent backup, restore, recovery, and maintenance operations.

    Configure backups to be written to disk.

    CONFIGURE DEFAULT DEVICE TYPE TO DISK;

    Configure RMAN to keep at least 5 backups of each datafile. If you

    have certain backups which must be retained longer than this

    retention policy, you can use the KEEP option with the BACKUP command

    when creating those backups.

    CONFIGURE RETENTION POLICY TO REDUNDANCY 5;

    Configure RMAN to use two disk channels for backup, restore,

    recovery, and maintenance operations.

    CONFIGURE DEVICE TYPE DISK PARALLELISM 2;

    4

  • 8/7/2019 Oracle RMAN Demo

    5/24

    Configure RMAN to write disk backups to the /backup directory. The

    format specifier %t is replaced with a 4-byte timestamp, %s with the

    backup set number, and %p with the backup piece number.

    CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/backup/ora_df%t_s%s_s%p';

    Configure RMAN to back up the control file after each backup.

    CONFIGURE CONTROLFILE AUTOBACKUP ON;

    Configure RMAN to write controlfile autobackups to the /backup

    directory.

    CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/backup/ora_cf

    %F';

    Excludes tbs_exclude from full database backups. NOEXCLUDE can be

    specified with the BACKUP command to override this configuration.

    CONFIGURE EXCLUDE FOR TABLESPACE tbl_exclude;

    NOTES:

    If you want backups to go to tape, refer to the configuration section

    in case2.rcv on how to configure tape backups. However in case of

    disaster recover if RMAN is not connected to recovery catalog, you

    will have to manually allocate all channels where backups were taken.

    - Use the SHOW ALL command to see your current configuration

    settings.

    - Save the database id displayed in the RMAN output if you are

    taking

    RMAN backups in nocatalog mode or database name is ambiguous in

    recovery catalog. The database id is required during disaster

    recovery (See Section 5). You will see the database id in RMAN

    output

    on connecting to target database like :

    connected to target database: INVENTORY (DBID=1670954628)

    BACKUP

    Since you are operating the database in no-archivelog mode, only the

    following kinds of backups are allowed:

    - whole database backups when the database is cleanly closed and

    the

    instance is mounted

    - tablespace backups of tablespaces that are offline clean or read

    only

    The following scenario assumes that you want to take one full

    database backup every week, and one incremental database backup every

    day. The backup cycle starts on Friday. A full backup is taken on

    Friday, and an incremental backup is taken every other day. Theretention policy of REDUNDANCY 5 applies only to full (not

    5

  • 8/7/2019 Oracle RMAN Demo

    6/24

    incremental) backups, so the combination of that policy and this

    backup schedule ensures that you can restore to any incremental

    backup time for the last 5 weeks.

    Start script for backup cycleThe following commands are run each Friday to start the backup cycle.

    The steps are:- Re-start the database to perform crash recovery, in case the

    database is

    not currently open, and was not shut down consistently. The

    database is

    started in DBA mode so that normal users cannot connect.

    - Shut down with the IMMEDIATE option to close the database

    consistently.

    - Startup and mount the database.

    - Backup database with incremental level 0.

    - Open database for normal operation.

    STARTUP FORCE DBA;

    SHUTDOWN IMMEDIATE;

    STARTUP MOUNT;

    BACKUP INCREMENTAL LEVEL 0 DATABASE FILESPERSET 4;

    ALTER DATABASE OPEN;

    If the above backup fails for any reaon, you can use the NOT BACKED

    UP SINCE

    option on the BACKUP command (9i restartable backup feature) to

    continue from the point of failure. The small value of FILESPERSET is

    good for restartable backups. However you should note that smaller

    FILESPERSET produces more backup sets.

    To re-start from the point of failure, run following commands:

    BACKUP INCREMENTAL LEVEL 0 DATABASE FILESPERSET 4

    NOT BACKED UP SINCE TIME 'SYSDATE-1';

    ALTER DATABASE OPEN;

    Script for other days of the backup cycle

    The following commands can be run from Saturday through Thursday to

    take

    cumulative incremental backups. They are same as in section 2.1,

    exceptthat LEVEL 1 is specified on BACKUP command.

    The steps are the same as in section 2.1, except that the options

    LEVEL 1 CUMULATIVE indicate that only the blocks that have changed

    since the last level 0 backup will be backed up. If the CUMULATIVE

    option was not specified, then only the blocks that have changed

    since the last level 1 backup will be backed up. The advantage of a

    cumulative backup is that only one incremental backup ever needs to

    be applied during recovery.

    STARTUP FORCE DBA;SHUTDOWN IMMEDIATE;

    STARTUP MOUNT;

    6

  • 8/7/2019 Oracle RMAN Demo

    7/24

    BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE FILESPERSET 4;

    ALTER DATABASE OPEN;

    Taking backups of readonly tablespacesThe database does not have to be closed to back up a readonly

    tablespace. The following command can be used to backup a readonly

    tablespace.

    BACKUP TABLESPACE read_only_tablespace_name;

    RESTORE VALIDATION

    The following commands can be run any time to check if RMAN is

    capable of restoring database/tablespace using existing backups.

    # check if database can be restoredRESTORE DATABASE VALIDATE;

    # check if tablespace is restorableRESTORE TABLESPACE read_only_tablespace_name VALIDATE;

    MAINTENANCE COMMANDS

    Basic steps for maintenance are:

    Verify all backups on backup media are intactCROSSCHECK BACKUP OF DATABASE;

    - Display a list of files that need to be backed up based on the

    retention policy. For this case study, files that don't have at

    least

    5 backups will be reported.REPORT NEED BACKUP;

    Delete un-necessary backups. This command deletes backups based on

    the

    retention policy. For this case study, all backups older than the 5

    most

    recent backups of each datafile will be deleted.DELETE OBSOLETE;

    get complete list of existing backupsLIST BACKUP SUMMARY;

    RESTORE AND RECOVERY

    In case of any user error or media failure you would have to do

    complete

    database recovery. However using the SET UNTIL command, it is

    possible to recover to different points in time when incrementals

    were taken. Because redo logs are not archived, only full and

    incremental backups are available for restore and recovery.

    It is assumed that you have all the configuration files like the

    serverparameter file (spfile - equivalent of init.ora in 9i), tnsnames.ora,

    and listener.ora in the appropriate places, and that you can startup

    7

  • 8/7/2019 Oracle RMAN Demo

    8/24

    the Oracle instance in nomount mode and connect from RMAN to the

    target instance.

    The steps are:

    - If not using a recovery catalog, or if the database name is

    ambiguous in, the recovery catalog you need to start RMAN without

    TARGET option and set the dbid before restoring the controlfilefrom

    autobackup.

    - Startup database in nomount mode (you should have restored

    initialization files for database, and listener files (only if

    connecting over SQLNET)).

    - restore controlfile.

    - restore all database files. Use CHECK READONLY, to make sure all

    read-only files are correct. If not RMAN will restore them.

    - apply all incrementals.

    - open database with resetlogs mode to re-create online logs.

    SET DBID ;

    CONNECT TARGET ;

    STARTUP NOMOUNT;

    RUN

    {# uncomment the SET UNTIL command to restore database to the

    # incremental backup taken three days ago.

    # SET UNTIL TIME 'SYSDATE-3';

    SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO

    '/backup/ora_cf%F';

    RESTORE CONTROLFILE FROM AUTOBACKUP;

    ALTER DATABASE MOUNT;

    RESTORE DATABASE CHECK READONLY;

    RECOVER DATABASE NOREDO;

    ALTER DATABASE OPEN RESETLOGS;

    }

    RMAN Demo 2

    Target Database Running in Archive Log Mode

    This case study can be used as basis for developing your own

    backup, maintenance, restore, and recovery scripts for a single

    instance database running in archivelog mode.

    The examples provided in this case study will use a disk area(/backup directory) to hold the most recent one week of backups, in

    order to expedite backup/restore operations. The size of this area

    may vary depending on database size, redo generated, etc. If you want

    all backups to go to tape, remove DEVICE TYPE DISK option from the

    BACKUP commands given in this case study.

    Only the incremental backups are stored on disk for one week. The

    level 0 backup goes immediately to tape. This means that RMAN will

    always have to read tape for recovery.

    NOTESYou should not run all of the commands in this file in a single RMAN

    session. Rather, the various sections in this file should be

    8

  • 8/7/2019 Oracle RMAN Demo

    9/24

    separated into individual RMAN scripts which can be run to configure,

    backup, restore, and recover the database.

    Organization:

    This case study is divided into the following sections:

    # 1. Configuring RMAN parameters# 2. Backup

    # - start script for backup cycle

    # (full database backup and archivelog backups)

    # - script for other days of backup cycle

    # (cumulative incremental level 1 backups and archivelog backups)

    # 3. Restore validation

    # - verify that the database/tablespace is restorable

    # 4. Maintenance commands

    # 5. Restore and Recovery

    # - Datafile recovery

    # - Tablespace recovery# - Controlfile recovery

    # - Block recovery

    # - Disaster recovery

    # - Database Point-in-time recovery

    #

    # How to run the file containing RMAN commands:

    #

    Here is an example of how to run the file that contains RMAN

    commands:

    rman target internal/pwd@prod1 catalog rman/rman@rcat cmdfile

    command.rcv

    CONFIGURATION

    There are various parameters that can be used to configure RMAN

    operations to suit your needs. Some of the things that you can

    configure are:

    - the recovery window, to keep backups so that it is possible to

    recover

    the database to any point in time during last X days.

    - the number of server processes that can do backups/restore

    operations inparallel

    - default device type for backups

    - the directory where on-disk backups will be stored

    This case study assumes that you

    - have 1 tape drive

    - want parallelization for disk to two and for tape to one

    - want to be able to recover your database to any point in time

    during the last

    30 days

    - want all full database backups to go only to tape- want to keep incrementals on disk for seven days

    - want to leave archivelogs on disk for seven days

    9

  • 8/7/2019 Oracle RMAN Demo

    10/24

    - want one copy of each archivelog backup saved on tape

    - want to back up archivelogs once per day

    - want to exclude tablespace tbl_exclude from database backups and

    restores

    because it is easier to re-create it than to restore and recover

    it.

    It should be noted that configuration setting is done just once, and

    these settings are used by RMAN to perform all subsequent backup,

    restore, recovery, and maintenance operations.

    Configure backups to be written to tape, via a 3rd-party media

    management product.CONFIGURE DEFAULT DEVICE TYPE TO SBT;

    If the media manager requires an RMAN PARMS string, configure it

    here. The media manager documentation will specify whether this

    configuration is needed.CONFIGURE CHANNEL DEVICE TYPE SBT PARMS '';

    Configure the number of server processes (channels) that write

    backups to DISK. You can delete these three lines if you want to only

    back up to tape.CONFIGURE DEVICE TYPE DISK PARALLELISM 2;

    CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/backup/ora_df%t_s%s_s%p';

    CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/backup/%F';

    Set the retention policy to a recovery window of 30 days. This

    ensures that RMAN retains all backups needed to recover the database

    to any point in time in the last 30 days. You can use the DELETEOBSOLETE command to delete backups that are no longer required by the

    retention policy. To exclude a backup from consideration by the

    policy, you can use KEEP option with the BACKUP command.CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 DAYS;

    Enable the autobackup feature to backup the controlfile after each

    database or archivelog backup.CONFIGURE CONTROLFILE AUTOBACKUP ON;

    Enable the backup optimization feature introduced in 9i to make sure

    that RMAN won't backup an archivelog or datafile if there already

    exists a backup of that file. The FORCE option can be used tooverride optimization on a specific BACKUP command.CONFIGURE BACKUP OPTIMIZATION ON;

    # Exclude tbs_exclude from full database backups. NOEXCLUDE can be

    specified

    # with backup command to override this configuration.

    CONFIGURE EXCLUDE FOR TABLESPACE tbl_exclude;

    # IMPORTANT: Save the database id displayed in the RMAN output if you

    are

    # operating RMAN backups in nocatalog mode, since it is requiredduring

    # disaster recovery. You will see the database id in output from RMAN

    10

  • 8/7/2019 Oracle RMAN Demo

    11/24

  • 8/7/2019 Oracle RMAN Demo

    12/24

    take

    # cumulative incremental backups.

    # The steps are:

    # - delete incrementals on disk that were taken before 7 days.

    # - take differential incremental backup of complete database.

    # - copy incrementals to tape.

    # - backup all archiveogs that are not backed up.# - deletes any copies of archivelog on disk older than 7 days.

    DELETE BACKUP COMPLETED BEFORE 'SYSDATE-7' DEVICE TYPE DISK;

    BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DEVICE TYPE DISK DATABASE FILESPERSET 4;

    BACKUP BACKUPSET ALL; # copies backups from disk to tape

    BACKUP ARCHIVELOG ALL;

    DELETE ARCHIVELOG UNTIL TIME 'SYSDATE-7';

    CONCEPT NOTE ON CUMULATIVE INCREMENTAL BACKUPS: Cumulative

    incremental level 1 backups will backup the blocks that changed since

    the last level 0 backup. Incremental backups are similar in function

    to archived logs and RMAN uses them in favor of archived logs duringrecovery. If the CUMULATIVE option was not specified, then only the

    blocks that have changed since the last level 1 backup will be backed

    up. The advantage of a cumulative backup is that only one incremental

    backup ever needs to be applied during recovery.

    As in section 2.1, you can use the NOT BACKED UP SINCE option with

    the BACKUP command (9i re-startable backup feature) to continue from

    the point of failure.

    Use the following commands to re-start backups after a failure:DELETE BACKUP COMPLETED BEFORE 'SYSDATE-7' DEVICE TYPE DISK;

    BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DEVICE TYPE DISK DATABASE FILESPERSET 4

    NOT BACKED UP SINCE TIME 'SYSDATE -1 ';

    BACKUP BACKUPSET ALL; # copies backups from disk to tape

    BACKUP ARCHIVELOG ALL;

    DELETE ARCHIVELOG UNTIL TIME 'SYSDATE-7';

    RESTORE VALIDATIONThe following commands can be run any time to check if RMAN is

    capable of restoring the database/tablespace using existing backups.

    check if database can be restoredRESTORE DATABASE VALIDATE;

    check if tablespace tst_tbs can be restoredRESTORE TABLESPACE tst_tbs VALIDATE;

    check if controlfile can be restoredRESTORE CONTROLFILE VALIDATE;

    check if archivelogs for the past two weeks can be restoredRESTORE ARCHIVELOG FROM TIME 'SYSDATE-14' VALIDATE;

    MAINTENANCE COMMANDSThe following commands can be run any time for maintenance of

    backups.

    Verify that all backups which RMAN thinks are stored by the third-

    12

  • 8/7/2019 Oracle RMAN Demo

    13/24

  • 8/7/2019 Oracle RMAN Demo

    14/24

  • 8/7/2019 Oracle RMAN Demo

    15/24

    Start RMAN without the TARGET option, and use the following commands

    to restore and recover the database:

    SET DBID ; # use database id from RMAN output as

    # explained in Section 2.1,

    # not required if using recovery catalogCONNECT TARGET ;

    STARTUP NOMOUNT;

    RUN

    {

    # You need to allocate channels if not using recovery catalog. Media

    # manager parameter string must be same as in Section 1.

    ALLOCATE CHANNEL FOO TYPE SBT PARMS '';

    ALLOCATE CHANNEL FOO2 TYPE DISK;

    RESTORE CONTROLFILE FROM AUTOBACKUP;

    ALTER DATABASE MOUNT;

    RECOVER DATABASE;

    ALTER DATABASE OPEN RESETLOGS;

    # You must take a new whole database backup after resetlogs (as

    # in Section 2.1), since backups of previous incarnation are not

    easily

    # usable.

    }

    # Section 5.4 - Block recovery# Block recovery can be used to recover a corrupted block(s). It is

    not

    # intended to recover complete datafile.

    # Usually, the corruption is reported in alert logs, trace files or

    # results of SQL commands

    #

    # For example, as a result of SQL command

    # SQL> select * from emp;

    #

    #NAME

    #ORA-01578: ORACLE data block corrupted (file # 7, block # 233)

    #ORA-01578: ORACLE data block corrupted (file # 7, block # 235)

    #ORA-01578: ORACLE data block corrupted (file # 4, block # 101)

    #ORA-01110: data file 7: '/oracle/dbs/tbs_07.f'

    #ORA-01110: data file 4: '/oracle/dbs/tbs_04.f'

    # Use the following BLOCKRECOVER command to recover the corrupted

    blocks

    # listed above:

    BLOCKRECOVER DATAFILE 7 BLOCK 233, 235 DATAFILE 4 BLOCK 101;

    # The BLOCKRECOVER command can also be used to repair all corrupted

    blocks

    15

  • 8/7/2019 Oracle RMAN Demo

    16/24

    # listed in V$BACKUP_CORRUPTION and V$COPY_CORRUPTION. These views

    are

    # populated whenever an RMAN process peforms a complete scan of a

    file for the

    # purpose of backing it up, such as with the BACKUP or COPY command.

    Use the

    # following command to repair all blocks listed in theV$xxx_CORRUPTION views:

    # command:

    BLOCKRECOVER CORRUPTION LIST;

    Section 5.5 - Disaster recovery# A disaster recovery scenario assumes that you have lost everything.

    To

    # perform recovery in this case, you would have to restore

    initialization

    # parameters manually. Then use RMAN to restore and recover the

    database as# described in this section.

    #

    # The commands below assume that all initialization parameter files

    are in

    # place and the complete directory structure for datafiles is

    recreated.

    #

    # Ensure you set your NLS_LANG environment variable.

    # e.g. in unix (csh):

    # > setenv NLS_LANG american_america.we8dec

    #

    # Start RMAN without the TARGET option, and use the followingcommands to

    # restore and recover the database:

    SET DBID ; # use database id from RMAN output as

    # explained in Section 2.1,

    # not required if using recovery catalog

    CONNECT TARGET ;

    STARTUP NOMOUNT;

    RUN

    {

    # You need to allocate channels if not using recovery catalog. Media# manager parameter string must be same as in Section 1.

    ALLOCATE CHANNEL FOO TYPE SBT PARMS '';

    ALLOCATE CHANNEL FOO2 TYPE DISK;

    # Optionally you can use SET NEWNAME and SWITCH commands as described

    in

    # Section 5.2 to restore datafiles to a new location.

    RESTORE CONTROLFILE FROM AUTOBACKUP;

    ALTER DATABASE MOUNT;

    RESTORE DATABASE;RECOVER DATABASE;

    ALTER DATABASE OPEN RESETLOGS;

    16

  • 8/7/2019 Oracle RMAN Demo

    17/24

    # You must take a new whole database backup after resetlogs (as

    # in Section 2.1), since backups of previous incarnation are not

    easily

    # usable.

    }

    Section 5.6 - Database Point-in-time recovery# This scenario assumes that all initialization files and the current

    # controlfile are in place and you want to recover to a point in time

    # '2001-04-09:14:30:00'.

    #

    # Ensure you set your NLS_LANG environment variable.

    # e.g. in unix (csh):

    # > setenv NLS_LANG american_america.we8dec

    STARTUP MOUNT FORCE;RUN

    {

    SET UNTIL TIME "TO_DATE('2001-04-09:14:30:00','yyyy-dd-

    mm:hh24:mi:ss')";

    RESTORE DATABASE;

    RECOVER DATABASE;

    ALTER DATABASE OPEN RESETLOGS;

    # You must take a new whole database backup after resetlogs (as

    # in Section 2.1), since backups of previous incarnation are not

    easily

    # usable.}

    RMAN Demo 3

    # DESCRIPTION# This case study outlines the basic steps to perform tablespace# point-in-time recovery (TSPITR) using Recovery Manager.## The examples in this case study assume that all backups are stored on# disk. However if you have backups on tape and channels are configured as# described in case2.rcv, Section 1, the same procedures will work.

    ## This case study assumes that# - You want to recover tablespaces TBS1 and TBS2 to the point in time# '2000-APR-01:07:05:30'.# - TSPITR is performed on the same machine as the target database.# - ORACLE_HOME is /oracle.# - ORACLE_SID for the target database is PROD.# - target database files and online logs are in $ORACLE_HOME/dbs/.# - ORACLE_SID for the auxiliary instance is AUX.# - all temporary files (except password file) for the auxiliary# instance are created in $ORACLE_HOME/auxiliary.## NOTES

    # You should not run all of the commands in this file in a single RMAN# session. Rather, the various sections in this file should be studied# thoroughly before performing TSPITR.

    17

  • 8/7/2019 Oracle RMAN Demo

    18/24

    ## MODIFIED (MM/DD/YY)# banand 04/17/01 - re-write case for tablespace point-in-time recovery# banand 04/17/01 - Creation## Organization:#

    # This case study is organized into the following sections:# 1. TSPITR usage and restrictions# 2. Resolving referential dependencies# 3. Preparing for TSPITR - setup auxiliary instance# 4. Performing TSPITR# 5. Preparing the target database to use recovered files# 6. Cleaning up the auxiliary instance and temporary files#

    Section 1 - TSPITR usage and restrictions

    Section 1.1 - When to do TSPITRTSPITR can be performed:

    - to recover from an erroneous drop or truncate table operation- to recover a table that has become logically corrupted- to recover from a batch job or DML that has affected only a subset of thedatabase

    Section 1.2 - Restrictions of TSPITRIt should be noted that TSPITR:- cannot recover a dropped tablespace- cannot recover a tablespace that was dropped and recreated with same name- will not recover optimizer statistics; statistics must be recalculatedafter TSPITR- cannot recover a tablespace containing any of the following object types:- replicated master tables

    - tables with varray columns- tables with nested tables- tables with external bfiles- snapshot logs- snapshot tables- IOTs- objects owned by SYS (including rollback segments)

    After TSPITR you should take a new backup of the recovered tablespace(s),since it is not possible to recover using the pre-TSPITR backups.

    Section 1.3 - RMAN specific restrictions for TSPITRRMAN specific TSPITR restrictions are :

    - cannot recover partitioned tables unless all partitions are contained in the recovery set- cannot recover tablespaces containing rollback segments

    Section 2. Resolving referential dependencies The main issue to consider when deciding whether or not toproceed withTSPITR is the possibility of application-level inconsistencies between tables in recovered and unrecoveredtablespaces due to implicit rather than explicit referential dependencies. You should understand thesedependencies and have means to resolve any possible inconsistencies before proceeding.

    Oracle provides the TS_PITR_CHECK view to assert that no referential integrity constraints will be broken afterTSPITR. If this view returns rows when queried then the reason should be investigated and resolved. Only whenTS_PITR_VIEW returns no rows TSPITR will be able to proceed (since this view is checked by imp/exp utilitiescalled by RMAN during

    TSPITR). All actions taken at this stage should be noted in order that these relationship can be rebuilt afterTSPITR is complete.

    18

  • 8/7/2019 Oracle RMAN Demo

    19/24

    You should check view TS_PITR_OBJECTS_TO_BE_DROPPED to see which objects will be lost after TSPITR.If you want certain object listed by this view, then TSPITR should not be performed.

    Run the following queries to prepare for performing TSPITR on TBS1 and TBS2 to time '2000-APR-01:07:05:30':

    SELECT OWNER, NAME, TABLESPACE_NAME

    FROM SYS.TS_PITR_OBJECTS_TO_BE_DROPPEDWHERE TABLESPACE_NAME IN ('TBS1', 'TBS2')

    AND CREATION_TIME > TO_DATE('2000-APR-01:07:05:30', 'YYYY-MON-DD:HH24:MI:SS')

    ORDER BY TABLESPACE_NAME, CREATION_TIME;

    SELECT * FROM SYS.TS_PITR_CHECK

    WHERE (TS1_NAME IN ('TBS1', 'TBS2') AND

    TS2_NAME NOT IN ('TBS1', 'TBS2')) OR

    (TS1_NAME NOT IN ('TBS1', 'TBS2') AND

    TS2_NAME IN ('TBS1', 'TBS2'));

    Preparing for TSPITR

    This section shows how to set up the auxiliary instance which will be used by RMAN to perform TSPITR on thedesired tablespaces. RMAN will connect to this database using the AUXILIARY connect option.

    Section 3.1 - Setting up the auxiliary instance

    Section 3.1.1 - Preparing to connect to the auxiliary instance The following steps should be followed to connectto the auxiliary instance:

    - create a password file for the auxiliary instance using the orapwd utility:

    orapwd file=/oracle/dbs/orapwAUX password=auxpwd entries=100

    Add listener.ora and tnsnames.ora entries so that RMAN can connect to the auxiliary database.

    Section 3.1.2 - Preparing the parameter file for the auxiliary instance You can use the production instanceparameter file as the basis for the auxiliary instance. However certain parameters like db_block_buffers,shared_pool_size, large_pool_size, enqueue_resources, etc which allocate shared memory can probably bereduced, because the auxiliary instance does not have the same memory requirements as the productioninstance.

    The following parameters must be set for the auxiliary instance: db_name must be the same as in the productioninstance

    db_name=PROD

    control_files must be different than the production instance

    control_files=/oracle/auxiliary/ctl.f

    lock_name_space must be different than the production instance

    lock_name_space=_PROD

    db_file_name_convert and log_file_name_convert are used only in the parameter file of the auxiliary instance.They establish the rules that are used to convert the datafile and log file names from the production to theauxiliary database.

    Note that starting in Oracle9i, more than one pair of substitutions can be specified in both of these parameters,which allows more flexibility in converting file names. Use the RMAN SET NEWNAME command to convert anyfile names that cannot be converted with the xxx_file_name_convert parameters.

    db_file_name_convert=('/dbs/', '/auxiliary/')

    log_file_name_convert=('/dbs/', '/auxiliary/')

    # log_archive_dest_n and log_archive_format can be the same as the target instance

    19

  • 8/7/2019 Oracle RMAN Demo

    20/24

    log_archive_dest_1='LOCATION=/oracle/log'

    log_archive_format=r_%t_%s.arc

    It is important to note that ALL controlfiles, online logs, and datafiles must have different names at the auxiliaryinstance than they have at the production instance, otherwise RMAN may restore files to those locations, andoverwrite the production files. Use the control_files, db_file_name_convert, and log_file_name_convertparameters to make surethat the files at the auxiliary instance all have different names.

    Section 3.1.3 - Starting the auxiliary instanceYou should start the auxiliary instance in nomount mode before performing TSPITR. You can connect usingSQLPLUS and start the auxiliary using the following commands:

    CONNECT sys/syspwd@auxiliary_db_connect_string as sysdba;

    STARTUP PFILE=/oracle/auxiliary/initAUX.ora NOMOUNT;

    Performing TSPITR using RMAN

    The auxiliary database must be in nomount state and the target instance must be mounted or open state toperform TSPITR. The steps in RMAN TSPITRare:- connect to auxiliary instance- connect to target database- connect to recovery catalog (optional)- recover tablespace TBS1 and TBS2

    CONNECT AUXILIARY

    CONNECT TARGET

    CONNECT CATALOG

    RUN

    {# optionally, use SET NEWNAME here for file name translation

    # SET NEWNAME FOR DATAFILE 1 TO '/oracle/auxiliary/file1.f'

    # SET NEWNAME FOR DATAFILE 2 TO '/oracle/auxiliary/file2.f'

    RECOVER TABLESPACE TBS1, TBS2 UNTIL TIME

    "TO_DATE('2000-APR-01:07:05:30', 'YYYY-MON-DD:HH24:MI:SS')";

    }

    All the recovered tablespaces will be OFFLINE in target database on successful execution of RECOVERcommand. If the RECOVER command fails, then after resolving the error you can re-execute the commands.

    If export fails due to lack of temporary space, you can create a temporary tablespace. Search for tspitr_7 in/oracle/rdbms/admin/recover.bsq and see comments to create temporary tablespace.

    If import fails because of import tables not existing, you can run CATEXP.SQL on target database to createimport schema.

    Preparing the target database to use the recovered tablespaces

    After the RECOVER command in Section 4 runs successfully, you should backup the recovered tablespaces,because after they are brought online, they can no longer be recovered using backups taken prior to theTSPITR.

    CONNECT TARGET sys/syspwd@target_db_connect_string;

    BACKUP TABLESPACE TBS1, TBS2;SQL 'ALTER TABLESPACE TBS1, TBS2 ONLINE';

    20

  • 8/7/2019 Oracle RMAN Demo

    21/24

    Cleanup auxiliary instance

    The auxiliary instance is not usable after successful completion of TSPITR. This instance must be cleaned usingfollowing steps:- Connect to the auxiliary instance as explained in Section 3.1.3- mount the database using 'ALTER DATABASE MOUNT CLONE DATABASE'- Delete the temporary files restored by RMAN when performing TSPITR.

    You can use following queries to list them:

    SELECT d.name FROM v$datafile d, v$tablespace t

    WHERE d.ts#=t.ts# AND status in ('SYSTEM', 'ONLINE')

    AND t.name not in ('TBS1', 'TBS2');

    SELECT member FROM v$logfile;

    SELECT name FROM v$controlfile;

    - Shutdown the auxiliary instance and delete the above files. All these files in this case should be in the/oracle/auxiliary directory.

    - You can also delete initAUX.ora and orapwAUX

    RMAN Demo 4

    # The following script creates a duplicate database that you can use

    # for testing purposes. This scenario assumes:

    # - You wish to duplicate the target database to a new database

    # named newdb.

    # - The target database is mounted or open.

    # - The auxiliary instance is started in NOMOUNT state.

    # - The INIT.ORA file of the duplicate database must contain:# - DB_NAME = newdb

    # - CONTROL_FILES = ... (see script)

    # - The INIT.ORA file of the duplicate database can also contain:

    # - DB_FILE_NAME_CONVERT = ... (see script)

    # - LOG_FILE_NAME_CONVERT = ... (see script)

    # - Any other parameters required by the auxiliary database.

    #

    # The following script creates a duplicate database using the most

    recent

    # backup. After the DUPLICATE command has finished succesfully,

    # you can register the duplicate database (if using a recoverycatalog)

    # and perform backups as with any other database.

    #

    # Make sure to set your NLS_LANG and NLS_DATE_FORMAT environment

    variables.

    # You can set these values to whatever you wish. The UNIX example

    # below keeps the date format to the standard date format used

    # for recovery:

    #

    # %> setenv NLS_LANG AMERICAN

    # %> setenv NLS_DATE_FORMAT 'YYYY-MM-DD:hh24:mi:ss'

    #

    #

    21

  • 8/7/2019 Oracle RMAN Demo

    22/24

    # Connect to RMAN and run the script by executing the following at

    # the O/S command line

    # (a single-line command is shown here on multiple lines for the

    # sake of clarity):

    # rman

    # TARGET

    #

  • 8/7/2019 Oracle RMAN Demo

    23/24

    # with the command: SET AUXNAME FOR DATAFILE ... TO NULL;

    #

    # (3) When the duplicate database is in a different host from the

    # target database, the same disk structure is present at the new

    # host, and you want to keep the same datafile names, then use

    # the NOFILENAMECHECK clause

    # SET NEWNAME FOR DATAFILE 1 TO '?/dbs/newdb_datafile1.dbf';

    # SET NEWNAME FOR DATAFILE 2 TO '?/dbs/newdb_datafile2.dbf';

    # ...

    # SET NEWNAME FOR DATAFILE 10 TO '?/dbs/newdb_datafile10.dbf';

    # ...

    # You must allocate at least one auxiliary channel needs before

    issuing

    # the DUPLICATE command. The channel type (DISK or SBT) must match

    # the media where the backups of the target database are stored. If

    you

    # allocate TYPE DISK, then the more channels that are allocated, the

    # faster the duplicate process will be. For other types the number of

    # channels should be limited to the actual number of devices

    available

    # for the operation:

    ALLOCATE AUXILIARY CHANNEL ch1 TYPE DISK;

    # ALLOCATE AUXILIARY CHANNEL ch2 TYPE SBT;

    # newdb is the name of the auxiliary database as specified in the

    # INIT.ORA parameter DB_NAME:

    DUPLICATE TARGET DATABASE TO newdb;

    # The LOGFILE clause is needed if the online logs cannot be

    # automatically generated from the target datafile names after

    # applying the LOG_FILE_NAME_CONVERT parameter of the

    # auxiliary database.

    # for example, for two groups each with two members of 512K bytes:

    # LOGFILE

    # GROUP 1 ('?/dbs/new_g1_l1.dbf',

    # '?/dbs/new_g1_l2.dbf') SIZE 512K,# GROUP 2 ('?/dbs/new_g2_l1.dbf',

    # '?/dbs/new_g2_l2.dbf') SIZE 512K

    # If restoring to a host with the same structure as the target host,

    use the

    # NOFILENAMECHECK clause:

    # NOFILENAMECHECK

    # Note that read-only datafiles are duplicated by default. If this is

    not# desired, use the SKIP READONLY clause:

    23

  • 8/7/2019 Oracle RMAN Demo

    24/24

    # SKIP READONLY

    ;

    # release the auxiliary channel

    RELEASE CHANNEL ch1;# RELEASE CHANNEL ch2;

    }

    RMAN Demo (Flashback Recovery Area)

    SELECT SUM(bytes) from v$datafile;

    SELECT SUM(blocks * block_size) BYTES

    FROM v$archived_log

    WHERE completion_time > SYSDATE-1;

    SELECT SUM(blocks * block_size) BYTES

    FROM v$archived_log

    WHERE status = 'A';

    ALTER SYSTEM SET db_recovery_file_dest_size = 2237460480 SCOPE=BOTH;

    ALTER SYSTEM SET db_recovery_file_dest = '/app/oracle/...'

    SCOPE=BOTH;

    RMAN Demo

    RMAN> backup incremental level 0 tag 'BU1_LEV0' database;

    RMAN> backup incremental level 1 for recover of copy tag 'BU1_LEV0'

    database;

    RMAN> recover copy of database with tag 'BU1_LEV0';

    RMAN Demo

    From Complete Failure

    RMAN> backup incremental level 0 tag 'BU1_LEV0' database;

    RMAN> backup incremental level 1 for recover of copy tag 'BU1_LEV0'

    database;

    RMAN> recover copy of database with tag 'BU1_LEV0';