10.07.2015 Views

Oracle Database Backup.pdf

Oracle Database Backup.pdf

Oracle Database Backup.pdf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

v05, i07: <strong>Oracle</strong> <strong>Database</strong> <strong>Backup</strong> http://www.samag.com/print/1 of 6 26.09.2003 10:54<strong>Oracle</strong> <strong>Database</strong> <strong>Backup</strong>Curtis PrestonSee Sidebar 1See Sidebar 2Trying to back up today's databases is like trying to catch a charging rhino with a butterfly net. Real worlddatabases have become screaming behemoths that are very difficult to capture (back up), and standardUNIX utilities are like butterfly nets. If you try to use these utilities for the job, not only will you notcapture the data -- you'll break your arm! This article is my attempt to build a better rhino trap. It usesmany advanced shell scripting features, so you may find it useful even if you do not have <strong>Oracle</strong>.Hot or Cold <strong>Backup</strong>s?One of the first decisions a database administrator must make is whether to perform "cold" or "hot"backups. A cold backup involves:1. Shutting down the instance 2. Backing up its filesystems or raw devices 3. Starting up the instanceHere are the steps to perform a hot backup. (Note that a hot backup requires much more knowledge of<strong>Oracle</strong>'s internal structure, so a basic definition of helpful terms is given in the sidebar "Definitions.")First, you must determine the name of each tablespace in the instance and the files that are within it. Then,for each tablespace, you:1. Put that tablespace in backup mode; 2. <strong>Backup</strong> that tablespace's files or raw partitions (using cp, tar, dd,etc.); 3. Take that tablespace out of backup mode.Once all tablespaces are done:1. Switch redolog files; and 2. <strong>Backup</strong> the control file.It is much easier to perform cold backups, so why do hot backups at all? Simply stated, they increase yourbackup window, or the time in which you are allowed to perform backups. Because cold backups requirea shutdown of the database, your users will probably allow only a very small backup window. Hotbackups allow you to back up without shutting down, remaining virtually invisible to the user, andthereby significantly enlarging your window. I have even performed hot backups of production dataduring primetime hours. Try that with a cold backup!Be CarefulIf you are going to use hot backups, though, you must follow certain precautions. Failure to do so couldmean you would only be able to restore up to your last cold backup -- if you made one.During a cold backup, all data files have been synchronized. A restore simply requires copying all filesinto place and restarting the database. However, during a hot backup, each file is backed up at a differenttime; thus each has a different time stamp. You must have some method of syncing all of those files to the


v05, i07: <strong>Oracle</strong> <strong>Database</strong> <strong>Backup</strong> http://www.samag.com/print/2 of 6 26.09.2003 10:54same point during a restore. That is what <strong>Oracle</strong>'s Redo Logs, (also known as archiving, or Archive Logs)are for. Archiving continually records all database changes in what is called the On-line Redo log. Oncethat log is full, it is copied to an Archived Redo log. (For more information, see the sidebar "Should I UseArchiving?")When restoring from a hot backup, you first replace the damaged database files with their respectivebackup copies. (You only need to replace the damaged files.) You then "play" the redo logs, effectively"redoing" all the transactions that affected those files. All files are then synchronized, and the databasecan be brought on line.With all the logs in place, this restore can be done with one command. However, if just one redolog islost, your restore could range from extremely difficult to impossible. If you do not have the set of redologs that span the time of your backup, you will not recover at all.This is why you must treat your redo logs as if they were gold. Some of the methods of protecting themare:Mirroring the filesystem on which they are storedStoring them on an NFS filesystem mounted from another server (can result in a performance loss)Performing hourly incremental backups (to tape or disk) of that filesystemIt is not uncommon, or unwise, to use all of the methods listed above to protect your redo logs.A Bird's Eye ViewTo automate <strong>Oracle</strong> backups, you must know the location of tablespaces, raw partitions, data files, controlfiles, redolog files, and whether archiving is running. To make things more difficult, each installation willhave different answers to these questions. Oraback.sh (Listing 1) addresses all of the problems above byobtaining most of its information from <strong>Oracle</strong>. The script will do the following for each instance:Use sqldba to obtain configuration informationPerform a cold or hot backup (as described above), based on the day of the weekMake a backup copy of essential redologsOraback.sh supports these features:<strong>Backup</strong>s to disk or tape<strong>Backup</strong>s of raw partitionsMultitasking, which can reduce backup time by up to 75%Mail-based error notificationThe script assumes that all instances want hot backups, which require redologs. Oraback.sh will warn youof any instances that do not have logs. It will continue to warn you until you correct the problem orcustomize your setup for that instance. Customization is done with oraback.conf (Listing 2).Looking in the <strong>Backup</strong> WindowNow that I've explained the overall purpose of oraback.sh, here is a description of each step within thescript. Oraback.sh begins by checking oraback.conf to see whether: the user running the backup is <strong>Oracle</strong>,or a user listed in field 7. It then looks to see whether the word "skip" is in field 2. If so, it skips the


v05, i07: <strong>Oracle</strong> <strong>Database</strong> <strong>Backup</strong> http://www.samag.com/print/3 of 6 26.09.2003 10:54backup once, and removes the word from oraback.conf. The script then does one of the following,depending on which arguments, if any, it received:$ oraback.sh at -- If called with at as an argument (you would usually do this with cron), the script checksoraback.conf to see whether the day in field 3 (the cold backup day) is today. If so, it will set the variable$TIME to the time in field 4. If not, it will set it to the time in field 5. The script then schedules an at jobthat will run oraback.sh at the time specified by $TIME.$ oraback.sh [$SID1 $SID2...] -- If given one or more instance names (ORACLE_SID's, or SID's forshort) as arguments, the script will perform a backup of each of them. If given no arguments, it performs abackup of all SID's listed in <strong>Oracle</strong>'s oratab file. (The latter is what the at job will do.)Oraback.sh first checks the $HOST.master line in oraback.conf to find out if: (a) there is a tape device infield 6. If so, it labels the tape, making sure the no-rewind device is being used; and (b) there is a numberin field 8. If so, it will perform that many simultaneous copies of database files.Next, oraback.sh asks <strong>Oracle</strong> questions that will determine how (or if) the SID will be backed up. It asks:if the instance is on-line; if so, oraback.sh makes a set of configuration files needed laterif archiving is runningif the instance is excluded from hot backupsif this is a cold backup; if so, it shuts down the instanceHot <strong>Backup</strong>If the instance is online, logs are on, and the instance is not excluded from hot backups, the script will puteach tablespace into backup mode by using the sqldba command begin backup. The script then copies thattablespace's files to the backup device. When the copying is done, it takes the tablespace out of backupmode with the sqldba command end backup.These three steps are the core of the hot backup. While the tablespace is in backup mode, the files will notchange. Any changes made to the tablespace while it is in backup mode are sent to the redo logs, and areapplied once it is taken out of backup mode. This is all done automatically by <strong>Oracle</strong>.The script supports simultaneous copying of individual data files to dramatically increase the speed of thebackup. Depending on how many files there are per tablespace, there may be one or more tablespaces inbackup mode at once. This will be done in order to perform the number of concurrent file copies (usingdd) that are specified in field 8 of oraback.conf, if you are using this feature.Next, the script forces a checkpoint and archive log switch, which causes the online redo log to be sent toan archived redo log. It then backs up the control files to disk using both sqldba and a manual copy.Finally, the script makes copies of the essential redo logs and compresses them. (Essential logs are thosethat span the time of your backup.) If the backup device is a tape, it then backs up all files that were sentto disk to the tape device.Cold <strong>Backup</strong>If the instance is off-line, oraback.sh only needs to copy the datafiles to the backup device. The script thenbacks up the control files and redo logs the same way the hot backup does.Special CasesIf the instance is online, but archiving is off, it checks oraback.conf for a line that reads:


v05, i07: <strong>Oracle</strong> <strong>Database</strong> <strong>Backup</strong> http://www.samag.com/print/4 of 6 26.09.2003 10:54$HOST:$SID:NOARCHIVELOGIf that line is not found, oraback.sh complains and sends you mail. If the line is found, it looks for theword "offline" on that same line. If "offline" is there, oraback.sh will shut down the instance, perform acold backup, and then restart the instance. (This is one of the ways you can customize oraback.sh fordifferent instances.)If the instance is online, oraback.sh also looks for a line in oraback.conf that reads$HOST:$SID:::nohotbackupIf that word is found, the script will skip this instance when performing a hot backup.In summary, oraback.sh can back up from one to all of the instances in oratab. To back up all instances,run it with no arguments. To back up one or more, run it with those SID's as arguments. To schedule abackup for the time in oraback.conf, run it with the at argument.Installing Oraback.shCheck the following values in the site-specific section at the top of the script. They must be changed to fityour site.a. BINDIR must be set to where you install oraback.sh.b. ORATAB must be set to the name and location of <strong>Oracle</strong>'s oratab file. (It must be located in a directorythat <strong>Oracle</strong> can write to.)c. ORACONF must be set to the name and location of your oraback.conf file.You should also review and confirm all other preference variables in the site-specific section, includingORADIR, TMP, LOG, and PATH.You must also verify that:a. You know which instances are using archivingb. There is a valid archive_dest in each instances's config.ora (not the default /?/dbs/arch)c. <strong>Oracle</strong> can create directories in the filesystem that you are using for backupsCustomizing Your <strong>Backup</strong>sOraback.conf is the main configuration file for oraback.sh. If you want to use the at argument, you musthave the following line in that file:$HOST.master::Sun:1200:1730:::5 :/dmp::Mail -s Error_oracle:These and other fields are described below:$HOST=Hostname generated by uname -nField 2: If you want all backups skipped on this host tonight, put "skip" hereField 3: The day you want to do cold backups. This can be a day of the week (Fri) or month (03), or blankif you do not want cold backups.Field 4: The time to do cold backups


v05, i07: <strong>Oracle</strong> <strong>Database</strong> <strong>Backup</strong> http://www.samag.com/print/5 of 6 26.09.2003 10:54Field 5: The time to do hot backupsField 6: No-rewind tape device, if you want to backup to tape. (Blank for disk-only backup)Field 7: A "|" separated list of userid's permitted to run sqldba, such as "oracle|dba" (Blank allows only<strong>Oracle</strong>)Field 8: The number of simultaneous copies you want to run. (Blank=1)Field 9: Must be set to a filesystem that has enough room for a compressed copy of all database files. (Ifyou are backing up to tape, you still need some space on disk.)Field 10: A "Y" means to compress the files before they are written to tape or diskField 11: Set this to a complete mail command. (e.g., /usr/ucb/Mail -s <strong>Backup</strong>_Error oracle,dba@herworkstation.com)There are four predefined functions, unused by default, which are listed in the site-specific section oforaback.sh. They are listed below, with their respective usage times:Preback: Runs before entire backup startsPreshut: Runs before shutdown of each instancePoststart:Runs after startup of each instancePostback: Runs after entire backup finishesIf you wanted to restart orasrv, for instance, after an instance is restarted (with a script called rc.orasrv.sh,)you would change the Poststart function to read:Poststart(){rc.orasrv.sh}Customizing <strong>Backup</strong>s of an InstanceIf you have an instance that will not run archiving or hot backups, you need a line in oraback.conf thatstarts with:$HOST:$SID::::Put "NOARCHIVELOG" in field 3 if the instance does not use archivingPut "offline" in field 4 if the instance does not use archiving, and you want a cold backup done every timePut "nohotbackups" in field 5 to skip hot backups for this instanceTesting the <strong>Backup</strong>For testing, select a small instance and run the following command as <strong>Oracle</strong>:$ /usr/local/bin/oraback.sh Be aware that if the word "offline," is in oraback.conf, or if the day that you specified for cold backups istoday, the instance will be shut down!If this test functions properly, you can put an entry in <strong>Oracle</strong>'s cron. Call this command:


v05, i07: <strong>Oracle</strong> <strong>Database</strong> <strong>Backup</strong> http://www.samag.com/print/6 of 6 26.09.2003 10:54/usr/local/bin/oraback.sh atat around 1200. It will check the oraback.conf and schedule an at job that will perform the backup.Testing the RestoreNever accept that a new backup strategy works until you have fully tested it under all circumstances!Make sure you test all of the following until you are comfortable:Complete restore from a cold backupComplete restore from a hot backupPartial restore from a hot backup, restoring only a few of your data files.Simulate the loss of a redo log, following the instructions in the <strong>Oracle</strong> manual for this scenario. This oneis extremely painstaking!Restore from an older backup, using the redo logs to roll forward to todayOnce your restore test is successful, you will have caught and tamed the rhino! This script represents morethan three years of work, and its development is a continual process. I hope you find it useful.About the AuthorCurtis Preston is a consultant for Pencom Systems Administration, and has been doing Unix SystemsAdministration for 3 years. He specializes in automating backups of heterogeneous networks. He may bereached at (312) 781-1111 or curtis@pencom.com.Copyright © 2001 Sys Admin, Sys Admin's Privacy Policy. Comments about theWeb site:webmaster@sysadminmag.com


Sys Admin Magazinehttp://www.samag.com/documents/s=1215/sam9607a/9607a_s1.htm2 of 3 26.09.2003 10:55Sys AdminSearch Sys AdminMainCurrentArchivesSource CodeResourcesQ&APerl AdvisorSolaris TM CornerLinux RookeryNew ProductsTool ShowcaseHOME | CODE | CONTACT US | CUSTOMER SERVICE | SUBSCRIBEADVERTISE | WRITE FOR US | ABOUT US | CD-ROMSys Admin Magazine > Sys Admin MagazineArchives > 1996 > 9607Print-Friendly VersionSidebar: DefinitionsData Files -- The physical files that hold the data orindexes. These may be files in a filesystem (e.g.,~/data.dbf) or raw partitions (e.g.,/dev/rdsk/c1t0d0s0).Tablespace -- A collection of data files (e.g.,tablespace TBS1 contains files ~/data1.dbf and~/data2.dbf).NewsletterSubscribe to theSys Admin emailnewsletteremail addressSubmitMagazineSubscribeBack IssuesBuy This IssueAdvertiseWrite For UsNewslettersContact UsCustomer ServiceAbout UsCD-ROMThe Perl JournalCurrentArchivesDownloadsOne LinersPerl ResourcesInstance -- Each occurrence, or "instance," of<strong>Oracle</strong>. This is sometimes referred to as thedatabase, but it can actually contain severaldatabases. There may be one or many instances oneach UNIX server, and all will be listed in <strong>Oracle</strong>'soratab file.Oratab -- <strong>Oracle</strong>'s global configuration file, listingeach instance name, its working directory, andwhether it is to be restarted after a reboot.Redo Log File -- This is a transaction log that keepstrack of all changes to each tablespace. It is used toredo those changes during a restore, thus the name.(Each instance has its own set of logs.)Control File Each instance has a control file thatkeeps track of all the tablespaces, data files, redo logfiles, and their current state.MarketPlaceAT&T-Cisco PortalExamines IP VPNServices.The IP VPN Portal fromAT&T and CiscoSystems featuresnumerous resourcesand tools, including aWebcast on how toincrease productivity,


Sys Admin Magazinehttp://www.samag.com/documents/s=1215/sam9607a/9607a_s2.htm2 of 4 26.09.2003 10:56Sys AdminSearch Sys AdminMainCurrentArchivesSource CodeResourcesQ&APerl AdvisorSolaris TM CornerLinux RookeryNew ProductsTool ShowcaseHOME | CODE | CONTACT US | CUSTOMER SERVICE | SUBSCRIBEADVERTISE | WRITE FOR US | ABOUT US | CD-ROMSys Admin Magazine > Sys Admin MagazineArchives > 1996 > 9607Print-Friendly VersionSidebar: Should I Use Archiving?In one word, yes! Having logs available during arecovery is a tremendous help. There are severalthings that you can do with logs that simply are notpossible without them:Restore up to the point of failure. Otherwise, youwill only be able to restore up to your last goodbackup. That means if a failure occurred at 4 p.m.,you would lose an entire day's work.NewsletterSubscribe to theSys Admin emailnewsletteremail addressSubmitMagazineSubscribeBack IssuesBuy This IssueAdvertiseWrite For UsNewslettersContact UsCustomer ServiceAbout UsCD-ROMThe Perl JournalCurrentArchivesDownloadsOne LinersPerl ResourcesRestore to the point just before the failure. If thefailure was caused by human error (delete table), youcan restore the database to the way it appeared justbefore the error.Restore the database using an old backup. If youhave logs, it does not matter if last night's backupfailed. You can use a backup that is days old, oreven weeks old, and restore up to the last redo log.Restore only the damaged disk or files. Withoutredo logs, if you have a 60 Gb database, and loseone 2 Gb disk, you must restore the entire 60 Gb.With redo logs, you only have to restore that disk.You can then use redo logs to sync the restored fileswith the undamaged files. This feature of archivingsaves hours in a typical restore.Hot backups are not possible if archiving is notenabled.There are two common arguments for not usingarchiving. The first is that it would decreaseperformance. The performance loss is relativelyminor, unless you have some parameters setincorrectly. It is important to know that redo logs arealways being created in every <strong>Oracle</strong> instance.Enabling archiving simply copies the closed redo logto another directory for recovery purposes. Beforeyou make any decision about archiving, you shouldbenchmark your instance with and without archiving.(A recent benchmark I performed showed a 2.5percent performance loss during continuous loads.)MarketPlaceAT&T-Cisco PortalExamines IP VPNServices.The IP VPN Portal fromAT&T and CiscoSystems featuresnumerous resourcesand tools, including aWebcast on how toincrease productivity,


Sys Admin Magazinehttp://www.samag.com/documents/s=1215/sam9607a/9607a_s2.htmThe second argument is that archiving issuperfluous. Some databases are read-only and areupdated only occasionally. Users might argue thatarchiving is not needed. They often tell you to backupthe database manually when it changes, after a loador import. This defeats one of the main purposes ofautomating: cron never forgets! If the database doesnot need archiving because there is little activity,then enabling it won't hurt. The CPU usage isnegligible, and archiving will allow you to do hotbackups and use all the features listed above.There is one type of database that I think would besignificantly hampered by archiving: the testdatabase. I still believe that logs should be onwhenever possible, but when a DBA is testing a newdatabase, he/she may be loading and unloadingtables all day long. This generates a huge amount ofarchived redo logs that have no value. It was for thistype of database that I added the ability to do anightly cold backup of an instance that does not havearchiving.lower costs and extendthe power of yournetwork.Your Network isVulnerable. Thequestion is where?Today, newvulnerabilities werediscovered and old onesare being exploited innew ways. Threat Focusautomatically identifies1,700+ knownvulnerabilities acrossyour network. 14-dayFree Trial.Wanna see your adhere?In summary, every production and developmentdatabase should use archiving, unless continuousimports make it unrealistic.TOP | HOME | CODE | CONTACT US | CUSTOMER SERVICE | SUBSCRIBE | ADVERTISE |WRITE FOR US | ABOUT US | CD-ROMMarketPlaceAT&T-Cisco Portal Examines IP VPN Services.The IP VPN Portal from AT&T and Cisco Systems features numerousresources and tools, including a Webcast on how to increase productivity,lower costs and extend the power of your network.Your Network is Vulnerable. The question is where?Today, new vulnerabilities were discovered and old ones are beingexploited in new ways. Threat Focus automatically identifies 1,700+known vulnerabilities across your network. 14-day Free Trial.GoToMyPC: Secure Enterprise Remote AccessAll the TCO advantages of a managed service with multi-level securityand control. Click here for more information and a complimentaryevaluation of GoToMyPC.Storage Solutions For Your <strong>Backup</strong> MediaNow you can protect and store all your valuable media with our mediastorage racks, fire safes, and cabinets. Solutions available for all popularmedia types and quantities. Ask us for current pricing for your backupmedia too.Sunbelt Software - Security ToolsSunbelt Software is a vertical B2B Internet company that supplies thesecurity tools necessary to support a Windows NT/2000 B2Binfrastructure. Contact us for rates and details.Wanna see your ad here?3 of 4 26.09.2003 10:56

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!