|
FAQ Part 1 | FAQ Part 2 | FAQ Part 3 | FAQ Part 4 | FAQ Part 5 | FAQ Part 6
Modification history
24-SEP-92 Original version, by Kevin Loney.
This article cannot be published. Part 1. Backup Strategy Q: What backup strategy should I use to best protect myself against media and node failures? How should I structure my backup procedures to minimize the vulnerabilities they cause? And how can I have them check for both physical and logical errors? A: I will assume throughout this discussion that the reader has at least a passing knowledge of the backup options available in Oracle. The recovery options and procedures are well documented, both in the DBA Guide and in the online RECOVERY.DOC file in the RDBMS directory. The procedures described here will allow the user to best exploit the tools available to him/her.
NOTE: Rama Velpuri, the Backup/Recovery guru at Oracle, has written
an entire book on this subject (Oracle Backup and Recovery Handbook,
Osborne/McGraw-Hill). It's from my publisher, but my honest appraisal:
it's one of the best-written computer books I've ever read.
If you're really into the subject, then get Rama's book; this article
only scratches the surface. The Backup and Recovery chapter of the
ORACLE DBA Handbook is not as intensive as Rama's book, but
is certainly more thorough than this article.
There are three valid ways of backing up an Oracle (V6-7) database. They are:
1. The Cold Backup. Shut down the database and perform a cold backup by going disk by disk and backing up all files in the [oracle] directories. When complete, restart the database. You may need to put an automated check into your backup program to use cold backups effectively, as several situations can cause the database shutdown to fail. For example, deadlocked users can prevent a SHUTDOWN IMMEDIATE from working. Also, "memory leaks" can keep the database is a suspended mode - in which the only solution is to SHUTDOWN ABORT. So add a script to your shutdown commands that does an independent check to see if the database actually went down. Some DBAs prefer choose to use the following command sequence: That way, they can be sure the database goes down via the SHUTDOWN ABORT command, and then shut it down cleanly via the SHUTDOWN IMMEDIATE command. The alternative is to use just a SHUTDOWN IMMEDIATE, followed by a separate command that checks to make sure the shutdown worked. 2. The Export. A full system export picks up information that user exports do not; this includes third-party indexes and grants. Why perform an export at all? Well, regular backups check that the database files are physically acceptable; export checks that they are logically readable. [Aside: This does not imply that they are logically importable; corrupt records may be exported into the dump file, preventing import. See my paper, #111, "Editing Corrupted Export Files (When Import Fails)" in the proceedings from the 1992 IOUW. Also, see Sam Youngman's article on the Export file structure, as presented at OOW 1996.] For example, export will detect data structure errors in tables (these are particularly prevalent in tables containing LONG datatypes). Export is of limited use for full-system backups; in order to recreate from an export file, you'd have to re-create the database from scratch first. However, it is worthwhile to periodically validate every record in the database via export. The dump file can then be used to retrieve particular tables/users if needed. Immediately following the export, run scripts to map the tablespaces to owners, and owners to tablespaces. This will allow you to see who owns what where. In the event of a tablespace loss, you would then be able to quickly determine what users/systems will be affected. Here are two scripts I use: group by substr(owner,1,20), substr(tablespace_name,1,32) union select substr(owner,1,20) owner, substr(tablespace_name,1,32) tablespace_name, count(*)||' indexes' objects from sys.dba_indexes group by substr(owner,1,20), substr(tablespace_name,1,32)
spool user_locs.lst
rem ts_users.sql
select
spool ts_users.lst These will create the tablespace/user mapping files. NOTE: Export/Import improved between V6 and V7. The biggest headache with them in V7 is that Import brings back the tables in alphabetical order, and if you have constraints on the table, you need to bring the tables back in hierarchical key order - so you need to disable the constraints prior to Import. Also, having the indexes on the tables during Import makes the Import process take orders or magnitude longer than it should. As of 7.3, you can use Direct Exports to cut the time required by your exports in half; but if you use this option, you can't Import the generated dump file into an earlier release of the database (7.2, eg). You can also map objects to datafiles, via the following script. 3. The Hot Backup. The ARCHIVELOG function that came in OracleV6 opened up a whole new set of possible backup options, but also caused a lot of heartache until they got it working right. Good parts about Archivelog:
Bad parts about Archivelog:
Implementing Archivelog: To start using Archivelog, simply alter your startup command file: and startup the database. From then on, the database will be in Archivelog mode until you turn it off (alter database noarchivelog). Note that a failed transaction is still a transaction; Archivelog keeps track of rollback segment extents, so rolled back inserts or deletes affect it just like completed transactions. Turn it off (shutdown, restart with noarchivelog mode) before doing big loads from SQL*Loader. Another option for controlling the amount of archived redo log entries generated is to use the UNRECOVERABLE keyword, available as of 7.2. UNRECOVERABLE can be used with the CREATE INDEX and CREATE TABLE AS SELECT commands; if it is used, then the transaction will not generate redo entries. When you start archiving, archived logs will be written every time the redo operation is about to overwrite a previously written logfile. It will write it to the directory indicated by the log_archive_dest parameter in your init.ora file. They will all be the same size (in V6; V7 can have variably sized archive logs) as your redo logs. They will increase in number until they run out of space on their destination device. At that point the database will freeze until you clear more space for them in the log_archive_dest location. SO, have a second location ready to receive them. Backup strategy for Archivelogs: 1. Do each tablespace one at a time. That is, rather than setting them all offline, then backing them up, then setting them back online, do them each separately. You don't want to risk having a system crash while the entire database is in begin backup state; recovery is a mess. Minimize your window of vulnerability by having only one tablespace in backup state at any one time. If you are using RAID devices or mirrored disks, in which the loss of a single disk does not cause the loss of a file, then you can simplify your backup procedures by taking all of the tablespaces offline at once, and backing them up as a set. 2. Before you backup the control file, force an archive log switch. This will update the header information in the control file. 3. Don't do it during user activity. When in backup state, a tablespace's activity is still written to the archive logs. However, it's written block-by-block rather than byte-by-byte. So changing one record in a tablespace that's being backed up will result in that record's entire block being written to the archive area. NOTE: This is correct only for those platforms where the physical sector size is less than the Oracle logical block size. On systems where the physical disk transfer size is equal to the Oracle block size, then we do not incur the penalty of having to log the entire block. This is true for MVS, VM, and perhaps other systems. Sample Archive log command file for VMS: NOTE: See Rama's book for a more complete script; the code is available at the Web site.
Note: The "alter system switch logfile" command is all but undocumented,
(see pg 3-15 of the DBA guide. It refers you to a nonexistent
cross-reference). It will NOT show up in the alert log. Don't
be alarmed by that; it does actually work.
NEW NOTE: Some people modify the script above to automatically
pull the file names from DBA_DATA_FILES, so they don't have
to hardcode the file names. I would only do that if the datafiles were
all mirrored, so that a media failure wouldn't take down my database.
Integrating the three methods. Use hot backups for all of your transaction-critical data. As a backup to the hot backups, perform cold backups periodically. As a backup to the physical file backups, use Exports. If you have a large amount of static data, you may wish to export only certain small tables, while relying on loading programs to re-create the static data when needed. As your database grows larger, the time required to perform Imports will remove Export as a viable backup option for all but the smallest of your tables. If at all possible in your O/S, it is also a good idea to shadow the disks on which your realtime and archived redo logs reside.
FAQ Part 1 | FAQ Part 2 | FAQ Part 3 | FAQ Part 4 | FAQ Part 5 | FAQ Part 6
|