home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a524 / 28.ddi / doc / recovery.doc < prev    next >
Encoding:
Text File  |  1991-03-04  |  13.4 KB  |  263 lines

  1. ...
  2. ... $Header: recovery.doc,v 6002701.1 89/06/15 23:00:54 rcs Exp $ recovery.doc Copyr (c) 1989 Oracle
  3. ...
  4.  
  5. Manual Recovery
  6. ---------------
  7.  
  8.  
  9. This note describes the external view of manual recovery and how it relates
  10. to other forms of recovery.  There is no background given - a complete
  11. understanding of V6 is assumed.
  12.  
  13. There are two forms of recovery in V6:
  14.  
  15.         Crash Recovery - Normal recovery of a database after a crash
  16.                          using online logs.  This happens atomatically
  17.                          when bringing up a crashed database.
  18.  
  19.         Media Recovery - Recovery of a database using one or more backup
  20.                          copies of database files; may require the use of
  21.                          archived logs.  This form of recovery is envoked
  22.                          by issuing
  23.  
  24.                                  RECOVER DATABASE
  25.  
  26.                          from SQLDBA.  Media recovery is done on a database
  27.                          that is mounted but NOT open.  It is done to all
  28.                          online tablespaces (offline tablespaces can be
  29.                          recovered using "RECOVER TABLESPACE" on an open
  30.                          database).
  31.  
  32. There are two options to media recovery that allow the DBA to stop recovery
  33. before the end of the most current log.  They may be used together or
  34. seperately:
  35.  
  36.         RECOVER DATABASE [MANUAL] [UNTIL <time>]
  37.  
  38.         <time> is of the form DD-MON-YY:HH:MM:SS (no quotes!)
  39.  
  40. There are several side effects from doing either type of incomplete
  41. recovery:
  42.  
  43.                         1) All past logs become invalid after
  44.                            recovery is complete.
  45.  
  46.                         2) Recovery cannot stop in the middle of the
  47.                            backup of any file. All redo generated between
  48.                            typing the BEGIN BACKUP and END BACKUP commands
  49.                            must be applied.
  50.  
  51.                         3) Any offline files WILL BE LOST.
  52.  
  53.                         4) All files must be restored from backups taken
  54.                            before the point where recovery is terminated.
  55.  
  56.                         5) If the control file is a backup, the control file
  57.                            schema can not have changed since the backup was
  58.                            taken. No data files or log files may be dropped
  59.                            or added since the control file backup was taken.
  60.                            Note that the MANUAL option is required if the 
  61.                            control file is a backup.
  62.  
  63.  
  64.         Recover Until - Like media recovery, except that the recovery process
  65.                         is stopped at a particular time.  This form of
  66.                         recovery is envoked by issuing:
  67.  
  68.                                 RECOVER DATABASE UNTIL <time>
  69.  
  70.  
  71.         Recover Manual - This option will cause the system to prompt for
  72.                          every log. (For logs that were never archived give 
  73.                          the name of the online log file.) It is used
  74.                          so the DBA can stop recovery at the end of a
  75.                          particular logfile and/or to restore the control
  76.                          file from a backup. (This form of recovery allows
  77.                          recovery beyond the "end" of the current
  78.                          control file):
  79.  
  80.                                 RECOVER DATABASE MANUAL
  81.  
  82. After performing incomplete recovery, ALL log files become invalid, so the
  83. DBA must open the database using:
  84.  
  85.         ALTER DATABASE OPEN RESETLOGS
  86.  
  87. The keywords RESETLOGS must be used after either manual or time based
  88. recovery has been envoked. This clears all the online logs to zero, and
  89. modifies all the online data files to indicate no recovery is needed.
  90. After resetting the logs none of the existing log files or data file
  91. backups can be used. A new backup must be taken before any data is protected
  92. from media failures.
  93.  
  94. A NORESETLOGS option also exists but should be used with caution. It informs 
  95. the system that even though the DBA used an incomplete recovery option,
  96. recovery did in fact go to the end of the log, so the logs are valid. It also
  97. implies that the control file was not a backup.
  98.  
  99.  
  100. The following additional SQLDBA commands exist:
  101.  
  102.         ALTER DATABASE DATAFILE <file spec> [ONLINE | OFFLINE]
  103.  
  104. This command can be used to take an idividual file on or offline - it is
  105. only valid on a mounted but unopened database. It is useful for forcing
  106. data files online for an offline tablespace before manual recovery. It is
  107. also useful for taking a file offline so that the database can be opened
  108. when the file is on a broken disk drive.
  109.  
  110.         ALTER DATABASE BACKUP CONTROLFILE TO <backup file name>
  111.  
  112. This command allows the hot backup of a control file - this is the ONLY
  113. way to backup a control file on an opened database!
  114.  
  115.  
  116.  
  117. How to use a control file backup
  118. --------------------------------
  119.  
  120. It is possible to use manual recovery to make a backup control file current.
  121. The backup must be more recent than the last add or drop of a log or data
  122. file. Thus it is prudent to always take a new control file backup after any
  123. of those operations. Although not strictly required, it is advisable to
  124. backup the control file after any log or data file renames. Since it is not
  125. possible to discover the names of data files when the database is closed, it
  126. is also advisable to keep a list of them in case they need to be named in an
  127. ALTER DATABASE command. It is best to only take control file backups when all
  128. data files are online. The following assumes that all online log files are
  129. intact and all necesssary archived logs are available. If not, see below for
  130. incomplete recovery.
  131.  
  132. 1) Make a backup: Make a copy of all the about to be recovered data files and
  133.    online logs. This procedure will make the current files unuseable. Should
  134.    something go wrong, these backups will allow retrying this procedure.
  135.  
  136. 2) Restore backups: The database must be shutdown. Restore the backup control
  137.    file to all files listed as control files in the init.ora file. Restore
  138.    any necessary data file backups. It is alright to restore to a different
  139.    file name if the correct file is inaccessable (see 4).
  140.  
  141. 3) Mount the database: Do a STARTUP MOUNT to get the instance started and the
  142.    backup control file opened.
  143.    
  144. 4) Insure all data files are correctly named: Use the ALTER DATABASE RENAME
  145.    FILE command to correct any file names. This will be needed if a backup
  146.    was restored to a different file or if a rename was done since the control
  147.    file backup was taken. Note that rename does not change the name of the
  148.    file used by the operating system. It changes the name that the database
  149.    uses when it attempts to open the file. It is best to give the fully
  150.    expanded name, in the proper case, for the old file name. This is the name
  151.    as it appears in SELECT * FROM V$DBFILE. The problem is that the name can
  152.    not be translated to the fully expanded version if the file does not exist.
  153.    
  154. 5) Insure all data files are online: If any data files are offline, either due
  155.    to an i/o error or DBA command, they will never be recoverable after this
  156.    procedure. The offline status is in the control file so the status at the
  157.    time of the control file backup is what counts. Use the ALTER DATABASE
  158.    DATAFILE <file spec> ONLINE command to bring files online. If in doubt put
  159.    a file online, there is no harm in doing it twice. It may be desirable to
  160.    have a file offline to avoid recovering it, but once the database is opened
  161.    it will be necessary to drop the tablespace containing the file. This will
  162.    lose all data in that tablespace as well as any data in the file.
  163.    
  164. 6) Do manual recovery: Use the RECOVER DATABASE MANUAL command to do manual
  165.    recovery. If you restored any data files from backups it may request logs
  166.    that were archived. Eventually you will be prompted for a log that is not
  167.    archived, enter the name of an online log file. If you get the wrong one
  168.    you will get an error indicating the sequence number of the file you named.
  169.    Keep trying online logs till you get it right. After that log is processed
  170.    you will be prompted for the next sequence number. Keep naming the online
  171.    logs until it requests a sequence number higher than any of the logs.
  172.    Recovery is now complete to the present, so enter CANCEL for the log name.
  173.  
  174. 7) Open the database: Use ALTER DATABASE OPEN RESETLOGS to open the database.
  175.    This will destroy the contents of the online logs and the start rba's of
  176.    the online data files. The software will accept the NORESETLOGS option but
  177.    this may result in a corrupted database.
  178.  
  179. 8) Make new backups: All data files must be backed up before media recovery can
  180.    work. Resetting the logs marked the database to prevent the use of any logs
  181.    from before the reset. Thus any data file backups from before the reset can
  182.    not be recovered. The old logs and data file backups are only useful for
  183.    repeating this procedure.
  184.  
  185.  
  186. How to do incomplete recovery
  187. -----------------------------
  188.  
  189. Situations can arise where it is desirable to recover to some point in the
  190. past. For example, an important table may be accidentally dropped, or a log
  191. file needed for recovery may be lost. The database can be restored to a
  192. particular point in time or to the end of a particular redo log. If necessary,
  193. a backup control file may also be used. See above for restrictions on the use
  194. of backup control files.
  195.  
  196. 1) Make a backup: Make a copy of all the online logs. This procedure will make
  197.    the current logs unuseable. Should something go wrong, these backups will
  198.    allow retrying this procedure. Note that the current data files can not be
  199.    used in this procedure, but it might be prudent to take a copy of them
  200.    anyway.
  201.  
  202. 2) Restore backups: The database must be shutdown. All data files must be
  203.    restored from image backups taken before the point where recovery will be
  204.    stopped. This is necessary to insure that all the files in the database
  205.    are recovered to the same point in time. Unfortunately there is no check to 
  206.    enforce this restriction. Failure to do this will result in a corrupt
  207.    database. However the corruption may not be noticed until a long time after
  208.    the recovery is completed and the database is in use. It is alright to
  209.    restore a data file to a different file name if the correct file is
  210.    inaccessable (see 4).
  211.  
  212. 3) Mount the database: Do a STARTUP MOUNT to get the instance started and the
  213.    control file opened.
  214.    
  215. 4) Insure all data files are correctly named: Use the ALTER DATABASE RENAME
  216.    FILE command to correct any file names. This will be needed if a backup
  217.    was restored to a different file or if a backup control file is used and a
  218.    rename was done since the backup was taken. Note that rename does not
  219.    change the name of the file used by the operating system. It changes the
  220.    name that the database uses when it attempts to open the file. It is best
  221.    to give the fully expanded name, in the proper case, for the old file name.
  222.    This is the name as it appears in SELECT * FROM V$DBFILE. The problem is
  223.    that the name can not be translated to the fully expanded version if the
  224.    file does not exist.
  225.  
  226.    
  227. 5) Insure all data files are online: If any data files are offline, either due
  228.    to an i/o error or DBA command, they will never be recoverable after this
  229.    procedure. The offline status is in the control file so the status at the
  230.    time of the control file is what counts. Use the ALTER DATABASE DATAFILE
  231.    <file spec> ONLINE command to bring files online. If in doubt put a file
  232.    online, there is no harm in doing it twice. It may be desirable to have
  233.    a file offline to avoid recovering it, but once the database is opened
  234.    it will be necessary to drop the tablespace containing the file. This will
  235.    lose all data in that tablespace as well as any data in the file.
  236.    
  237. 6) Do incomplete recovery: To recover to the end of a particular log use the
  238.    RECOVER DATABASE MANUAL command. To recover to a point in time use the
  239.    RECOVER DATABASE UNTIL DD-MON-YY:HH:MM:SS command. If the control file is
  240.    a backup then add the MANUAL option as well. You will be prompted by 
  241.    sequence number for the names of log files. If necessary give the name of
  242.    one of the online logs. If you get the wrong one you will get an error
  243.    indicating the sequence number of the file you named. Keep trying online
  244.    logs till you get it right. You may enter CANCEL at any time to end
  245.    recovery. After cancelling you may enter the recover command again to
  246.    resume where you left off, or you can just end recovery there. If the UNTIL
  247.    option was given recovery will end when that time is found in the logs.
  248.    Otherwise cancelling is the only way to end recovery.
  249.  
  250. 7) Open the database: Use ALTER DATABASE OPEN RESETLOGS to open the database.
  251.    This will destroy the contents of the online logs and the start rba's of
  252.    the online data files. The software will accept the NORESETLOGS option but
  253.    this may result in a corrupted database. The only valid use of the no reset
  254.    option is if you did not use a control file backup, changed your mind about
  255.    incomplete recovery, cancelled incomplete recovery, and did a normal
  256.    RECOVER DATABASE command to complete recovery.
  257.  
  258. 8) Make new backups: All data files must be backed up before media recovery can
  259.    work. Resetting the logs marked the database to prevent the use of any logs
  260.    from before the reset. Thus any data file backups from before the reset can
  261.    not be recovered. The old logs and data file backups are only useful for
  262.    repeating this procedure.
  263.