B R Scenarios

Embed Size (px)

Citation preview

  • 7/30/2019 B R Scenarios

    1/16

    BACKUP AND RECOVERY

    Media Failure and Recovery:Database in NOARCHIVELOG ModeFailure: loss of disk, data file, or corruptionRecovery: Restore all Oracle files:

    - Data files- Control files- Redo log files- Password file (optional)- Parameter file (optional)

    Advantage

    Easy to perform with low risk of error Recovery time is the time it takes to restore all files.

    Disadvantage

    Data is lost and must be reapplied manually The entire database is restored to the point of the last whole closedbackup

    Recovery> shutdown

    Restore all files using operating system> startup

    Restoring to a Different Location> startup mount> alter database rename file /clover/oradata/user_01.dbf to

    /clover/oradata/user_01.dbf;> alter database open;

    Media Failure and Recovery:ARCHIVELOG ModeFailure : loss of disk,data file,or corruptionRecovery

    - Data files for restore must be offline.- Restore only lost or damaged data files- Do not restore the control files, redo log files, password files, or parameter files- Recover the data files.

    Advantages

    Only need to restore lost files Recovers all data to the time of failure

    Recovery time is the time it takes to restore lost files and apply allarchived log files

    Disadvantages Must have all archived log files since the backup from which you arerestoring

    Complete recovery

  • 7/30/2019 B R Scenarios

    2/16

    Closed database recovery for- System data files- Rollback segment data files- Whole database

    Opened database recovery, with database initially opened : for fileloss

    Opened database recovery with database initially closed : for

    hardware failure Data file recovery with no data file backup

    Incomplete recovery

    Time based Cancel based

    Using control file Change based

    Closed database backupNo archive log mode

    Data files, Control files, Redolog files, Parameter file, Password file

    > SHUTDOWN IMMEDIATEcp /backup> STARTUP OPEN;

    Open database backupArchive log modeData files, Control files, Parameter file, Password fileArch process must be enabled

    > alter tablespace TEST begin backup;cp /clover/data/test.dbf /clover/backup/test.dbf

    > alter tablespace TEST end backup;

    Creating a binary image;> alter database backup controlfile to controll.bk

    Creating a text trace file:

    alter database backup controlfile to trace;

    Case Study for Backup and recovery

    To check database mode> archive log list

    To bring database in archive log mode> startup mount> alter database archivelog;

    To start ARCN processlog_archive_start=truelog_archive-max_process=2(max 10)> ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=3;> ALTER SYSTEM ARCHIVE LOG START | STOP

  • 7/30/2019 B R Scenarios

    3/16

    To define archive formatlog_archive_format=TS%S.ARC

    Data Dictionary FormatV$ARCHIVED_LOG V$ARCHIVE_DESTV$LOG_HISTORY V$ARCHIVE_PROCESSES

    To define archive destination : Up to 4 destination can be defined

    log_archive_dest=/clover/archivelog_archive_duplex_dest=/clover/archive

    ORlog_archive_dest_1=LOCATION=/clover/arch

    Mandatory Reopen=500(Default 300)Optional

    log_archive_min_succeed_dest=2log_archive_dest_state_3=DEFER / ENABLE

    > ALTER SYSTEM SET log_archive_dest_state_3=ENABLE;

    log_archive_dest_state_2=SERVICE=standby

    To defining archive destination in open database> ALTER SYSTEM ARCHIVE LOG START TO /clover/arch;

    Selectively Archiving> ALTER SYSTEM ARCHIVE LOG SEQUENCE 052;

    Backups

    I. Closed database backup

    Note : To keep backup, create one subfolder in your main folder Every day beforeshutdown delete all your backups.

    Database may in no archive/archive log modeTake backup of all files Data files, Control files, Redolog files,Parameter file, Password file (optional )

    > SHUTDOWN IMMEDIATE;Copy all files to backup location using operating system.cp /clover/backup/> STARTUP OPEN;

    II Open database backup

    Database must be in archive log madeARCN process must be enabledTake backup of Data files, Control filesPassword file and Parameter file is optional

    > alter tablespace test begin backup;Copy datafile of test tablespace to backup location using operating system.cp /oracle/db01/data/test.dbf /oracle/backup/test.dbf

  • 7/30/2019 B R Scenarios

    4/16

    > alter tablespace test end backup;

    Note : Perform open database backup for all tablespaces

    Creating a binary image of control file> alter database backup controlfile to controll.bkp; path should be specified

    Creating a text trace file> alter database backup controlfile to trace; path should be specified

    Recovery

    Recovery in No Archive log mode :

    Advantage : Easy to perform with minimum riskRecovery time is time taken for restore the files from backup

    Disadvantage : Data lost must be reapplied manuallyDatabase is recovered to time of last backup.

    Possible media failure : Loss of disk, datafile or corruption of datafile.

    Requirement : Last valid closed database backup.

    Recovery : Restore all datafiles, control files, redolog files.Recover the database.

    Note : if log sequence no is not changed after taking the backup no need restore all file.

    Recovery in Archive log mode : ( Complete Recovery )

    Advantage : Restore damaged datafileRecover all data to the time of failureRecovery time is time taken to restore datafile and apllying the archive

    logs.

    Disadvantage : Require all archive logs since the backup from which are restored

    Possible media failure : Loss of disk , datafile or corruption of datafile.

    Requirement : Last valid backup after seting database in archive log mode.All archive logs and online redologs which are not yet archived

    Recovery : Startup the database in mount/open stageRestore damaged datafile from backup using operating system recoverRecover the datafile.

    Recovery syntaxRecovering in mount stage> Recover database

  • 7/30/2019 B R Scenarios

    5/16

    > Recover datafile ;> Alter database recover database;

    Manual recovery

    If archive log destination is not defined in the parameter fileOracle server has to be informed about the location of the file archive logs.

    > Alter system archive log start to ;To recover also you have to define the archive log location

    > recover from < location > database;

    Automatic recovery

    Before recover set auto recovery on.> set auto recovery on;> recover datafile ;

    Enter auto when prompted for a redolog file.> Auto

    Or> recover automatic datafile

    Check V$recover_file - which file need recoveryV$recovery_log - archive log need for recovery

    Incomplete Recovery

    In incomplete recovery database will be recovered before the time of failure.

    Possible Failures : A failed complete recovery operation, Important table in the Database

    is dropped, A control file is lost, Loss of redolog files

    Rquirement : Valid online or offline backup of all the database files.Need all archived logs ,Back up of control file.

    Recovery : Shutdown and backup the database.Restore all data files.Do not restore the control file, redo logs, password files, orParameter files.Mount the database and recover the data file before time of failure.Perform a closed database backup.

    Recovery Guidelines :Follow all steps: Most errors occur during this type of recovery.Whole-database backup before and after recovery assist future recovery.Always verify that the recovery is successful.Back up the control file regularly.Back up and remove archived logs.Database are brought forward in time, not bake in time.

    Backup & Recovery Scenarios

  • 7/30/2019 B R Scenarios

    6/16

    1. How you will identify that the database was clean shutdown last time?

    2. Recover a lost datafile in Noarchive Mode - data is present in Redologi. Restore damaged datafile

    ii. Recover it

    3. Recover a lost datafile in Noarchive Mode - data is not present in redologfile(Incomplete Recovery)

    i. Restore cold backup

    4. Recover System Datafile in Archive Mode (Databae was Closed initially)i. Startup mountii. Restore damaged datafileiii. Recover datafileiv. Alter databse open;

    5. Recover Non-System Datafile in Archive Mode (Database was closed initially)Recover Non-system datafile to new location (Databae was closed initially)i. Startup mountii. alter tablespace .. offlineiii. alter databse openiv. restore datafile (to new location)

    alter databse rename datafile ... to ...v. recover tabclespacevi. alter tabclespace ... online

    6. Recover a datafile in Begin Backup mode (While taking backup of tablespace -

    Power goes off. how to recover it)i. Startupii. check v$Backup & V$recover_fileiii. recover datafileiv. alter database open

    7. Recover a datafile, no backup exists but controlfile contains the name ofdatafile.(Controlfile should be older than datafile otherwise you cannot recover thedatafile) (Scenario 5)

    8. Recover a Datafile belong to temporary tablespace.

    9. I am trying to take hot backup for all the table spaces to have a full backup ofdatabase with 9i...I took backup of all table spaces went ok....but for the temp itdoesnt work and i dont think theres any diffrent cammand for that i used thefollowing command and getting the ERROR massage:>Alter tablespace temp begin backup;ORA-03217: Invalid option for alter temporary tablespace(Don't back up TEMP, it cannot be recovered anyway. If you have to do arestore, just recreate the TEMP tablespace as part of the restore process)

  • 7/30/2019 B R Scenarios

    7/16

    There is no need to backup the temporary locally manged tablespaces because:1. Locally managed tempfiles are always set to NOLOGGINGmode. So thus will have no undo.2. Extents are managed by bitmap in each datafile to keep trackof free or used status of blocks in that datafile.3. The data dictionary does not manage the tablespace.4. Rollback information is not generated because there is no

    update on the data dictionary.5. Media recovery does not recognize tempfiles.

    10. Recovering from a lost datafile in a UNDO Tablespace - ID 1013221.6

    11. Recover databse after disk loss 230829.1

    12. How to Recover a Database Having Added a Datafile Since Last Backup [ID29430.1]

    13. Took a Cold Backup. Created a tablespace. How to recoveri. If controlfile exists

    ii. If controlfile is also lost

    14. Recover Inactive Redologfile (Scenario 7)Lost Active Redolog File in Archive Mode & in NoArchive ModeLost Current Redolog files in Archive & NOArchive ModeLost all redolog files (Scenario 9)Lost one of the Multiplexed Redolog Files

    15. Recover Controlfile - No Multiplex Exists (SCenario 14)

    16. Performing Incomplete Recovery [ID 114199.1]

    17. How to recover the database if Archive files are missing - ID 163434.1

    18. Recover a dropped table - ID 96197.1] (Scenario 8) - INCOMPLETE RECOVERY

    19. Recover Datafile after resetlogs (Scenario 10)

    20. Recover dropped tablespace (Scenario 11)

    21. Recovering READONLY tablespace backups made before a RESETLOGS Open -[ID 266991.1]

    22. Recover a tablespace, Control file does not contain the tablespace info.(Scenario 12)

    23. A table test was created at 10am and dropped at 10.30 am, another tabletest1was created at 10.45 was dropped at 11.45am.Recover the tables without losing any records in both the table. (Scenario 13)

    24. Recover new information that was not in the backup and was only stored in thearchivelog files. (Scenario 16)

  • 7/30/2019 B R Scenarios

    8/16

    25. How to recover a database having added a datafile since the last backup.(Scenario 17)

    26. If the database crashes during a hot backup. (Scenario 18)

    27. Re-creating controlfiles from a trace script where Read-Only Offlined tablespaces

    are present. (What will happen)

    28. Recover a datafile containing Index segments.

    29. Clonig using cold backup to same node / to another nodeHow to Manually Clone a Database to Another Node [ID 562556.1]

    30. Cloning using hot backup (Same as 31)

    31. Database is in Archive mode. You have a Cold backup (Consistent) & ArchiveFiles. You lost everything i.e. Redologs, Controlfile and Datafiles. Hoe to Recover.

    32. How To Make A Copy Of An Open Database For Duplication To A DifferentMachine [ID 224274.1]

    33. Doing Incomplete Recovery and Moving Redo Logs From Corrupted Disk [ID77643.1]

    34. One of the databases crashed. After some investigation it was found that onlydata files and initialization file intact. All other files i.e. control files and redo logfiles were lost. The control files and log files were not multiplexed (Firstmistake). With only data files, how would you recover a database with minimalloss?

    35. We even did not have consistent backup for the database (Second mistake).After doing some research, we finally decided to give a go to recover thedatabase with available data files and initialization file.

    Up the instance using pfilerecreate controlfile from tracealter database open resetlogs

    Extra:36. Database Startup Fails with ORA-01113, ORA-01110 [ID 146039.1]37. HOW TO RECOVER OFFLINE DROPPED DATAFILE IN ARCHIVELOG MODE [ID

    286355.1]

    38. ORA-600 [3668] "Media Recovery Required After CREATE CONTROLFILE" [ID93665.1]39. How to clone/duplicate a database with added datafile with no backup. [ID

    292947.1]40. Can I restore or duplicate my previous version database using a later version of

    Oracle? YCan I restore or duplicate between two different patchset levels? YCan I restore or duplicate between two different versions of the same operatingsystem? YIs it possible to restore or duplicate when the bit level (32 bit or 64 bit) of Oracle

  • 7/30/2019 B R Scenarios

    9/16

    does not match? OS SpecificCan I restore or duplicate my RMAN backup between two different platformssuch as Solaris to Linux? N

  • 7/30/2019 B R Scenarios

    10/16

  • 7/30/2019 B R Scenarios

    11/16

    (Old)

    Scenario 1

    Shutdown the database.> shutdowncopy all datafiles, control files, redolog files to backup folder using operating

    system.Delete one datafile using operating system.> startup ( Database will go to mount stage giving an error )

    RecoveryRestore damaged datafile from backup using operating system and recovercp /oracle/backup /oracle/db01/data

    > alter database open ;

    Scenerio 2

    Force the log switch to change the log seq no.> alter system switch logfile;> alter system switch logfile;> alter system switch logfile;Shutdown the database.> shutdownDelete one datafile using operating system.> startup ( Database will go to mount stage giving an error )

    RecoveryRestore all files.> alter database open ;

    Recovery in Archive log mode : ( Complete Recovery )Scenario 3 ( In mount stage )

    Force the log switch to change the log seq no.

    > alter system switch logfile ;> alter system switch logfile;

    > alter system switch logfile ;shutdown the database.

    > shutdown immediate ;Delete system datafile using operating system.

    > startup ( Database will go to mount stage giving an error )

    ORA-01157 : cannot identify/lock data file 1 see DBWR trace fileORA-01110 : data file 1 : /clover/system01.dbf'

    Restore system datafile from backup using oprating system and recover the

  • 7/30/2019 B R Scenarios

    12/16

    datafile> Recover datafile /clover/data/sys.dbf ;> Alter database open ;

    Scenario 4 ( Initially closed, open stage )Shutdown the database.

    > shutdown immediate ;Delete non system datafile using operating systm.

    > startup ( Database will go to mount stage giving an error )

    ORA-01157 : cannot Identify/lock data file 3 see DBWR trade fileORA-01110 : data file 3 : /clover/test.dbf

    Check V$ datafile header

    Take the lost datafile offline> Alter database datafile /clover/test.dbf offline;

    Restore the lost datafile from backup and recover the datafile.> Recover datafile /clover/test.dbf ;

    Bring the datafile online.> Alter database datafile /clover/test.dbf online;

    Note : if you want to restore the damaged datafile to different location oraclemust

    Be informed about new location by renaming recovery

    > Alter database rename file /clover/test.dbf to /new/test.dbf ;

    Backup Recovery

    Recovery in Archive log mode : ( Complete Recovery )

    Scenario 5 ( without backup )

    Shutdown the database.> shutdown immediate ;

    Delete non system datafile using operating system.> startup ( Database will go to mount stage giving an error )

    ORA-01157 : cannot identify/lock data file 3 see DBWR trace fileORA-01110 : data file 3 : /clover/test.dbf

  • 7/30/2019 B R Scenarios

    13/16

    Take the lost datafile oflinne> Alter database datafile /clover/test.dbf ofline;

    open the database> Alter database open;

    Take database offile immediate to avoid check point trying to write to datafile.> Alter tablespace test offline immediate;

    Since you do not have backup operate create the datafile> Alter database create datafile /clover/test.dbf as /clover/test.dbf;

    Recover the Database> Recover datafile /clover/test.dbf;> Alter tablespace test online ;

    Scenerio 6 Recovery of file in backup mode

    Startup online backup> Alter tablespace test begin backup ;

    switch off the system and restart .

    startup the database if it is already starting shut it down then startup. It willask for media recovery

    ORA-01113 : file 3 needs media recoveryORA-01110 : data file 3 : /clover/test.dbf

    Check V$Backup

    > Recover datafile '/clover/test.dbf;OR

    > Alter database datafile 3 end backup ;

    check V$Backup

    Since the datafile header was frozen the database files were not synchronized.

    Scenario 7

    Check V$Logfile for current logfile and delete one fo the redlog file which is notcurrent.Using operating system. Force the log switch

    > Alter system switch logfile;

    it will give an eror

    ORA- 00313 : open failed for members of log group of thread 1

    Scenario 8 :A table is dropped at 10 am at 11 am user comes to know that the table view ortable does not existCreate a table test.

    > Create table test ( n number );Insert values

    > Insert into test values (11111);

  • 7/30/2019 B R Scenarios

    14/16

    > Commit ;> Alter system switch logfile ;

    Note down the commit timing. Give some time gap and drop the table> Drop table test ;

    Shutdown the database> Shutdown

    Mount the databse

    > Startup mount ;Restore all datafile from backup (most recent ) using operating system. Andrecover the database until time (Specify time before droping the table )

    > Recover database until time 2001-11-12:09:30:00;> Alter database open resetlogs ;

    After incomplete recovery take new backup of database.

    Select * from nls_database_parameter;

    Cancel based recovery

    Scenario 9:Lost a redolog fileShutdown the database.Take back up of all logfiles, datafiles, controlfilesDelete one log file using operating system.Mount the database

    > startup mount ;Restore all datafile from backup using system.

    > recover database until cancel ;> Alter database open resetlogs ;

    Check for log file in v$ logfile

    Change based recovery

    Scenerio 10:No back up was taken after reset logs, need is to use cold backupBackup the data file and control file. ( cold backup )Perform incomplete recovery ( To bring database in new incarnation you can recover bytime based or cancel based )Create a table insert some records commit.Shutdown the database.

    > ShutdownRestore cold data file and control file ( from cold backup)Startup the database. ( You will get an error )

    > StartupCheck V$Log for change seq #)Recover until Change

    > recover database until change < change seq#>;> Alter database open resetlog :

    Check for table created.

  • 7/30/2019 B R Scenarios

    15/16

    Scenerio 11:Recovery using backup controlfileTablespace was created at 10am and backup was taken and dropped at 2pmCreate a tablespace and create one table insert records into the table.Take backup of all datafile and controlfile ( closed/open if you are taking open databasebackup first take backup of controlfile than datafile )

    Drop the tablespace.> Drop tablespace test including contents ;

    Shutdown the database take backup of existing controlfile first than restore controlfileand datafile.Startup the database it will give an error after taking the database in mount stage.Make sure that all datafiles are online before recovery by checking v$recover_file Performrecovery using backup controlfile

    > recover database until time 2001-11-11:13:10:00 using backup controlfile;> Alter database open resetlogs ;

    Check for the table.

    Scenario 12:

    Backup was taken of both controlfile and datafile at 10 am. At 11 am Tablespace wascreated and at 1pm tablespace was dropped. Recover the tablespace using cold backup.

    Scenario 13:A table test was created at 10am and dropped at 10.30 am, another table test1wascreated at 10.45 was dropped at 11.45am. Recover the tables without losing any recordsin both the table.

    Scenario 14:Recover the lost current control file, or the current control file is inconsistent with filesthat you need to recover

    Scenario 15:Recover lost online redo logs.

    Scenario 16:Recover new information that was not in the backup and was only stored in thearchivelog files.

    Scenario 17How to recover a database having added a datafile since the last backup.

    Scenario 18

    If the database crashes during a hot backup.

  • 7/30/2019 B R Scenarios

    16/16

    The RESETLOGS option is always required after incomplete media recovery or recoveryusing a backup control file. Resetting the redo log does the following:

    Archives the current online redo logs (if they are accessible) and then erases the contents

    of the online redo logs and resets the log sequence number to 1. For example, if thecurrent online redo logs are sequence 1000 and 1001 when you open RESETLOGS, thenthe database archives logs 1000 and 1001 and then resets the online logs to sequence 1and 2.

    Creates the online redo log files if they do not currently exist.

    Reinitializes the control file metadata about online redo logs and redo threads.

    Updates all current datafiles and online redo logs and all subsequent archived redo logswith a new RESETLOGS SCN and time stamp.

    Because the database will not apply an archived log to a datafile unless the RESETLOGSSCN and time stamps match, the RESETLOGS prevents you from corrupting datafiles witharchived logs that are not from direct parent incarnations of the current incarnation.