16.3. Physical Backups Without rmanMany Oracle environments prefer the supported nature of rman. They also enjoy the way that you can completely integrate your commercial backup software with rman. It's also the only way to get true incremental backups of your datafiles. In addition, you can also use rman to back up to disk without purchasing an agent for your commercial backup system. However, some DBAs prefer what Oracle calls user-managed backups. They put their database into backup mode prior to backing up and take it out of backup mode after backup. Sometimes this is due to a long history and familiarity with user-managed backups; sometimes it is the cost of either the disk you would need to use rman without a media manager or the cost of the media manager. For whatever reason, approximately half of Oracle customers perform user-managed backups, but this percentage goes down every day. This section discusses methods that can be used to safely back up Oracle without using rman. You can back up to disk and then back that disk up using your normal backup procedures, or you can back up directly to tape. Like most RDBMSs, Oracle databases can reside on cooked filesystem files or raw disk devices (raw disks are available only in Unix). Even if raw devices are available, many Oracle DBAs put their databases on cooked files. One of the reasons for this is that if all of the database files are accessible via the filesystem, backing up is very simple. Any standard copy utility (e.g., cp, copy) or any backup utility (e.g., dump, cpio, or commercial utility) can copy the data. If you are running Oracle on Unix and decide to put your Oracle database on raw partitions, you need to use a tool that can back up raw partitions (e.g., dd). Backups can be done offline (a cold backup) or online (a hot backup). If you're going to perform user-managed backups, you must back up all of the following:
16.3.1. Cold BackupA cold backup of an Oracle database that is based on filesystem files is the easiest of all database backups because most companies already have some system that backs up their server's filesystems. It could be a homegrown program that runs dump or ntbackup, or it could be a commercial backup product. To perform a cold backup of an Oracle database, simply perform an orderly shutdown of Oracle (not shutdown abort) before running the normal backup. An orderly shutdown performs a checkpoint, flushing any changed data stored in memory to disk, and then stops all processes that allow access to the database. This procedure puts all Oracle files into a clean, consistent, quiescent state. This procedure assumes, of course, the use of filesystem files. An Oracle database running on a Unix server also could be sitting on raw devices. A cold backup of such a database requires a little more effort because you need to understand the structure of the database. The procedure starts out the same, by shutting down the database. A filesystem backup at this point, though, gets only the executables and any database objects that reside in the filesystem, such as the control file. The database itself requires extra effort. The first thing to figure out is where all the database files are. A script can "ask" Oracle this question by querying v$datafile, but that script would have to be written. Once the locations of all files are known, dd can back them up to a file somewhere in the filesystem or send them directly to a backup volume. If they are backed up to a file in the filesystem, it must be done before the normally scheduled filesystem backup. That way, the files are automatically backed up to a backup volume. Therefore, backing up an Oracle database that uses raw partitions is harder than backing one up that is based on filesystem files. This is one reason why Oracle DBAs have historically used the filesystem to store their database files, even though raw partitions yield slightly better performance. 16.3.2. Hot BackupIf an Oracle database is providing the data for the customer service web page or any other application that requires 24-hour uptime, a cold backup is not acceptable because it requires that the database be shut down on a regular basis. Even if this is done late at night, customers accessing the web page may do so at any time. A company has a much better online image if it is able to leave the web page up all the time. What is needed, then, is a hot, or online backup.
A hot backup requires quite a bit more work than a cold backup, and this is even more true when the cold backup is of a database using raw devices. The following steps must be taken every time a hot backup is performed:
This is obviously a lot of work. A good knowledge of scripting is required, as well as a good knowledge of the commands necessary to accomplish these tasks. To explain the whole process, let's break it down by section:
16.3.3. Debunking Hot-Backup MythsWhat happens during a hot backup is widely misunderstood. I debunk two main myths here:
Many people believe that while a tablespace is in backup mode, the datafiles within that tablespace are not written to. They believe that all changes to these files are kept in the redo logs until the tablespace is taken out of backup mode, at which point all changes are applied to the datafiles just as they are during a media recovery. (The concept of media recovery is described in the section "Recovering Oracle" later in this chapter.) Although this explanation is easier to understand (and swallow) than how things really work, it is absolutely not how hot backups work in Oracle. Many people believe that when a tablespace is in backup mode, Oracle switches from logging the redo vector to logging full blocks. Neither is correct. It continues to log redo vectors, but it also logs the full image of any block that is changedbut only the first time it changes that block.
A common reaction to these statements is a very loud "What?" followed by crossed arms and a really stern look. (I reacted the same way the first time I heard it.) "How could I safely back up these files if they are changing as I'm backing them up? What do you mean it logs the full image only the first time it changes the block?" Don't worry; Oracle has it all under control. Remember that every Oracle datafile has an SCN that is changed every time an update is made to the file. Also remember that every time Oracle makes a change to a datafile, it records the vector of that change in the redo log. When a tablespace is put into backup mode, the following three things happen:
After this happens, your backup program works happily through this datafile, backing it up block by block. Since the file is being updated as you are reading it, it may read blocks just before they're changed, after they're changed, or even while they're changing! Suppose that your filesystem block size is 4 KB, and Oracle's block size is 8 KB. Your backup program will be reading in increments of 4 KB. It could back up the first 4 KB of an 8 KB Oracle data block before a change is made to that block, then back up the last 4 KB of that file after a change has been made. This results in what Oracle calls a split block. However, when your backup program reaches the point of the datafile that contains the SCN, it backs up the SCN the way it looked when the backup began because the SCN is frozen. Once you take the tablespace out of backup mode, the SCN marker is advanced to the current value, and Oracle switches back to logging change vectors and doesn't worry about full images of changed blocks. How does Oracle straighten this out during media recovery? It's actually very simple. You use your backup program to restore the datafile. When you attempt to start the instance, Oracle looks at the datafile and sees an old SCN value. Actually, it sees the value that the SCN marker had before the hot backup began. When you enter recover datafile, it begins to apply redo against this datafile. Since the redo logs contain one complete image of every block that changed during your backup, it can rebuild this file to a consistent state, regardless of when you backed up a particular block of data. The first thing it does is overwrite any blocks for which it contains full images (that is, those blocks that changed during backup). It then applies regular redo against the file to apply any changes that occurred during or after the backup. This is why it needs only the first image of any block that was changed during the backup. It just needs one image to ensure that the block is put into a known state (as opposed to a split block). It can then apply redo against that block to redo any other changes. If you're like me, you won't believe this the first time that you read it. So I'll prove it to you. Let's create a table called tapes in the tablespace test, insert the value "DLT" into it, and force a checkpoint: SQL> create table tapes (name varchar2(32)) tablespace test; Table created. SQL> insert into tapes values ('DLT'); 1 row created SQL> commit; Commit complete. SQL> alter system checkpoint; System altered. Now we ask Oracle what block number contains the new value: SQL> select dbms_rowid.rowid_block_number(rowid) blk, name from tapes; BLK NAME ------- ---------------- 3 DLT The value "DLT" is recorded in the third data block. Allowing nine blocks for the datafile headers, we can read the third block of data with dd and run strings on it to actually see that the value is there: $ dd if=/db/Oracle/a/oradata/crash/test01.dbf ibs=8192 skip=11 count=1|strings 1+0 records in 16+0 records out DLT Place the tablespace in hot-backup mode: SQL> alter tablespace test begin backup ; Tablespace altered. Now update the table, commit the update, and force a global checkpoint on the database: SQL> update tapes set name = 'AIT'; 1 row updated SQL> commit; Commit complete. SQL> alter system checkpoint; System altered. Extract the same block of data to show that the new value was actually written to disk: $ dd if=/db/Oracle/a/oradata/crash/test01.dbf ibs=8192 skip=11 count=1|strings 1+0 records in 16+0 records out DLT, AIT Now we can take the tablespace out of backup mode: SQL> alter tablespace test end backup; This test proves that datafiles are indeed being written to during hot backups! |