INF: Database Device File Image Backup and sp_dboptionLast reviewed: April 30, 1997Article ID: Q134788 |
The information in this article applies to:
SUMMARYOne of the advantages of using Microsoft SQL Server version 6.0 is the variety of methods that can be used to perform a database backup. This article explores a variation of the file image backup. There are two tape formats used on the Windows NT platform, and they are incompatible with each other. The first is the tape format supported by Windows NT, NTBACKUP.EXE, and other third party tape archiving products which use the Microsoft Tape Format (MTF). The second is the SQL Server tape format. In some scenarios, customers have elected to have an operator change tapes in between NTBackup's backup operation, and those database dumps to tape performed by SQL Server. Other customers have chosen to have SQL Server dump to disk, and then use NTBackup to archive this dump to tape. There are two basic backup strategies for SQL Server. The primary backup strategy for SQL Server is the database dump which can then be loaded in a recovery scenario. This method is used primarily by companies whose servers must be in operation 7 days a week and 24 hours a day. Many of these companies also use the hot backup server strategy in which the dump is loaded to the backup server. These SQL Server database dumps are frequently performed to disk locally, to a network drive, and to tape. The second basic SQL Server backup strategy is the use of a file image backup, where SQL Server is shutdown and the all the database device files are archived to tape using NTBackup. Because this method uses the NET STOP/NET START SQL Server commands, most customers use this method by combining batch scripts which are setup using the AT command and run by the Windows NT Scheduler Service.
MORE INFORMATIONWith the release of SQL Server version 6.0, you can perform some of the same operations without stopping SQL Server and select which databases and the associated device files are archived to tape. Before going further, there are several precautions that must be stated:
Here is an example which uses a 4 MB database called 'test' which has two 2MB devices, one called 'testdata,' located on C:\SQL60\DATA\TESTDATA.DAT, and the second called 'testlog,' located on C:\SQL60\DATA\TESTLOG.DAT. The database options on test are TRUNCATE LOG ON CHECKPOINT and SELECT/INTO BULK COPY.
Step 1Issue the command:
sp_dboption test,offline,true goWhich results in the following messages returned to the client:
Database is now offline Closing device 'testdata' and marking it 'deferred'. Device option set. Closing device 'testlog' and marking it 'deferred'. Device option set.This command resets the status for the 'test' database, and the value in sysdatabase.status will be 512 plus the status at the time the stored procedure was executed. Verify this with the following command:
select name,dbid,status,mode from master..sysdatabases where dbid = db_name('test')which results in the following:
name dbid status mode ------------------------------ ------ ------ ------ test 6 524 0The stored procedure checks to ensure that there are no users currently using the database; if there are, the following message is returned:
Msg 5160, Level 16, State 1: Cannot take 'test' offline because usecount=1. Msg 15245, Level 16, State 1: 'DBCC DBCONTROL' error. Database not placed offline. Step 2Now execute the extended stored procedure to either copy the associated database device files from share to share, or, as in this example, execute NTBackup:
xp_cmdshell 'ntbackup backup c:\sql60\data /a /v /d "Image Backup of Test Database" /t Incremental /tape:0'The basis for the above command is that when NTBackup performs a 'NORMAL' backup, the archive attribute for a file is cleared until it is subsequently changed. If all the archive bits are cleared for a set of database device files, when a database is taken offline the database device files will be marked with +A or the archive bit set on. An incremental backup will locate these files, back them up, and reset the archive bit to an off position. The files in the directories specified with the archive bit set on will tend to be those most recently closed, and this status bit set. (See the NTBackup Help file for details regarding the command line execution of NTBACKUP.EXE, or Windows NT Help Commands for additional information on the Attrib command)
Step 3When the above command completes, bring the database back online with the following command:
sp_dboption test,offline,false gowhich returns the following statements:
Opening device 'testdata' and marking it as non-deferred. Device option set. Opening device 'testlog' and marking it as non-deferred. Device option set. Recovering database 'test' Database is now online.If there is a problem opening one of the devices, the following errors are displayed:
Opening device 'testdata' and marking it as non-deferred. Device option set. Opening device 'testlog' and marking it as non-deferred. Msg 5153, Level 16, State 1: Failed to open device 'testlog', see errorlog for details. Msg 15246, Level 16, State 1: Cannot bring database online due to problem opening device 'testlog'.The selected database should now be online and accessible.
|
Additional query words: sql6 methods
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |