The site database and software metering database are supported in SQL Server version 6.5 or version 7.0. SQL Server terminology beyond that explained in Chapter 2 and SMS-related SQL Server functions are explored in this lesson.
NOTE
See Chapter 2 for information on databases, transaction logs, and devices.
SQL Server Enterprise Manager provides a facility for database and transaction log backup and restore.
Backing up a database makes copies of its system tables, user-defined objects, and data. A backup is referred to as a dump in SQL Server version 6.5.
Databases and transaction logs are backed up onto backup devices or directly to a file. A backup device may be a disk file or a tape drive. You can back up a database to one device or to multiple devices. You can back up multiple databases or transaction logs to a common device or to separate devices.
Backup responsibility is usually assigned to either the SQL Administrator (sa) or the database owner. However, permissions to back up a database or a transaction log can be transferred by the database owner to other users. In either case, the user responsible for performing database backup should set up a regular backup schedule.
NOTE
Do not use an operating system copy command to make copies of your databases. This method will not ensure transaction integrity.
Use either SQL Server Enterprise Manager or the Transact-SQL BACKUP command to back up the database.
The SQL Server Backup dialog box is accessed from the Tools menu in SQL Server version 6.5. In SQL Server version 7.0, select the database in the SQL console tree, or from the details pane (shown in Figure 13-2), select All Tasks and then choose Backup Database.
Figure 13-2. Initiating a database backup of the site database in SQL Server Enterprise Manager.
Before performing the backup, provide or change the following information:
Viewing Histories of Database Backups
SQL Server Enterprise Manager maintains a record of database backups, including backups made through other applications. For backups from SQL Server version 6.5, the Restore tab of the Database Backup Restore dialog box automatically presents a list of database backups, table backups, and transaction log backups from which to choose.
In SQL Server version 7.0, select the database in the console tree, select All Tasks, and then choose Restore Database.
When restoring the database, identify the backup device that contains the backup to be restored. Look at the header information to determine the database name, device size, and date of backup.
A database may be restored using SQL Server Enterprise Manager or the Transact-SQL LOAD command. SQL Server version 7.0 also supports the Transact-SQL RESTORE command. While LOAD will work in SQL Server version 7.0, it is only present for backward compatibility. Future versions of SQL Server will not support the LOAD statement.
Figure 13-3 shows a basic restore operation in SQL Server version 7.0.
Figure 13-3. Initiating a database restore of the site database in SQL Server Enterprise Manager.
See SQL Server Books Online for detailed information on both backing up and restoring databases. There are many differences between the two versions of SQL Server and many new options in SQL Server version 7.0.
There are several database maintenance activities that are performed automatically by the SMS SQL Monitor process. Additional Transact-SQL commands may be added and scheduled through the SMS Administrator console. These commands are added to the database maintenance activities completed by the SMS SQL Monitor. Scheduled tasks and Transact-SQL commands are configured from the Database Maintenance node in the SMS Administrator console (Figure 13-4).
Figure 13-4. The Database Maintenance node in the SMS console tree.
Automated tasks are enabled and scheduled through the SMS Administrator console, as shown in Figure 13-5.
Figure 13-5. Configuring automated tasks in the SMS Administrator console.
By default, all tasks are enabled except for the automatic database export and site server backup tasks.
Export Databases and Transaction Log Tasks
There are four tasks dedicated to backing up the site database, the software metering database, and their associated transaction logs (Figure 13-5). These tasks are disabled by default.
To use these tasks, you must first create a backup device, which is similar to configuring a backup routine directly in the SQL Server Enterprise Manager. Enter this device name in the `Export to' field, also shown in Figure 13-5. Specify a schedule and enable the task.
NOTE
If the `Truncate log on checkpoint' checkbox is selected in the SQL Server Enterprise Manager for the SMS databases, the transaction logs cannot be backed up. This is the default for SMS databases.
Back Up SMS Site Server
This task stops the SMS services and then backs up the site database, the software metering database (if it exists), the site server registry, and the Sms directory on the site server. The task then restarts the SMS services. Therefore, make sure that this backup routine runs when SMS services are not being heavily utilized.
Rebuild Indexes
This task is enabled by default to run once a week on Sundays. Indexes are used by SQL Server to speed up data retrieval. Over time, the data in the tables that are used to create the indexes change as new systems management data is collected. Therefore, it is important that the indexes are updated to the contents of the database tables in order to provide peak performance gains. The Rebuild Indexes task reorganizes the indexes to remove disk fragmentation and correct the index pointers. This maximizes SQL Server performance.
Monitor Keys and Recreate Views
This task is enabled by default to run once a week on Sundays. It monitors the integrity of the primary keys (those columns that uniquely distinguish one row from another in a database table) and writes a status message if a problem is discovered.
Delete Aged Items
These tasks are enabled by default. Old status messages are removed daily. Inventory data, discovery data, and collected files older than 90 days are removed once a week. For example, if a computer does not forward a discovery data record (DDR) to the site database for 90 days, then that computer will be deleted from the site database the next time this task runs. Heartbeat discovery is used to provide an updated DDR regularly enough so that computer resources that do not log on regularly are not deleted.
Update Statistics
This task is enabled by default to run every Monday, Wednesday, Friday, and Saturday. As the database is changed during normal SMS operations, internal statistics used to optimize SQL Server performance become less optimal. This task updates these statistics so that queries run faster. In SQL Server version 7.0, statistics are updated automatically.
Tasks are only enabled and scheduled—not created—from the Tasks node. To create an automated task, use the SQL Commands node. For example, you can add the DBCC Transact-SQL commands discussed earlier in this lesson to the details pane of the SQL Commands node. The results of a SQL command can be logged to a specified file when you configure the scheduled command. If logging is not enabled, the command still runs. To verify that the command has run, view the SMS SQL Monitor from the Component Status node in the SMS Administrator console.
In this exercise, you will configure SMS to automatically run a stored procedure on a schedule. This stored procedure will determine how much drive space is available in the SMS site database.
NOTE
Complete this exercise from the primary site server with only the SMS Administrator console running.
NOTE
The steps for enabling logging using SMS Service Manager was explained in Chapter 11, Exercise 51, "Installing SMS 2.0 on Computer 2."
The SMS console tree displays the SQL Commands and Tasks nodes.
The SQL Command Properties dialog box displays `General' settings for the new SQL command.
In this field/checkbox | You supply |
---|---|
Name | SMS site database space |
`Enable SQL command' | Selected |
SQL command | sp_spaceused |
Log status to | \\SERVER1\SMS_S01\LOGS\DBSPACE.LOG |
The SMS Administrator console appears with the new SQL command in the details pane.
In the following steps, you will use SMS status messages to verify that the SQL command was executed.
The list of SMS components appears in the details pane.
The SMS Status Message Viewer for <S01> <Central Site> window appears. Notice the messages with IDs of 2408. These messages report the processing of SQL commands and tasks. There should be one message for the sp_spaceused command.
NOTE
The status message may not appear yet, because it may take a few minutes for the SQL command to execute. You may refresh the list of status messages to determine when the command has completed.
Notice the SQL command listed as being run was SMS site database space.
In the following steps, you will use SMS log files to verify that the SQL command ran successfully.
The SMS Tracer application appears.
The SMS Tracer application displays the contents of the SMS SQL Monitor's log file.
Notice the executing SQL command for SMS site database space. Also notice a status message was written with an ID of 2408.
Notepad displays the contents of the log file created by the SQL command. Because this log file was not created by the SMS services as an SMS log file, the formatting is not the same as the standard SMS logs, and SMS Trace will not display the data properly.
Notice the sp_spaceused command, as well as the results of the command, is referenced. The results are presented in the following format, where x represents the site code and numeric values for your site.
In this exercise, you will configure the SMS database maintenance tasks to automatically back up the SMS site and software metering databases. You will begin by creating backup devices to store the backed up data.
The SQL Server Enterprise Manager MMC appears showing the Microsoft SQL Servers node.
The SQL Server Group node appears in the SQL console tree and SERVER1 appears in the details pane.
NOTE
If SERVER1 does not appear in the details pane, you must first register the SQL Server from the Action menu.
The Getting Started Taskpad appears in the details pane.
The Backup Device Properties _ New Device dialog box appears. Notice that the default path is D:\MSSQl7\BACKUP\.
The SQL Server Enterprise Manager MMC appears.
Create another backup device with the name SWMDBDump.
Notice that no files are displayed. Even though the backup devices were created in SQL Server Enterprise Manager, they are not created on the server's hard disk until they are going to be used.
In the following steps, you will configure SMS to automatically back up the SMS site database and the software metering database files.
The SMS console tree displays the SQL Commands and Tasks objects.
The details pane displays the available database maintenance tasks.
The Export Site Database Task Properties dialog box displays `General' settings for the database task.
The SMS Administrator console appears. Notice in the details pane that the Export Site Database task is now enabled.
When the automated tasks start, the databases will be backed up, and the files will appear in the directory.
Notice the backup devices were created on the server's hard disk as the databases were backed up. The file size indicates the actual number of used pages in the database.
In the following steps, you will use SMS status messages to verify that the SMS database maintenance tasks were run.
The list of SMS components appears in the details pane.
The SMS Status Message Viewer for <S01> <Central Site> window appears. Notice the messages with IDs of 2408. These messages relate to the processing of the SQL database maintenance task for backing up the databases.
Notice the SQL command listed as being run was an export of the SMS site database or the software metering database.
In the following steps, you will use SMS log files to verify that the SMS database maintenance tasks ran successfully.
The SMS Tracer application appears.
The SMS Tracer application displays the contents of the SMS SQL Monitor's log file.
The first occurrence of executing appears. This may be for the sp_spaceused command run earlier in the previous exercise.
Notice the log entry for the executing of the backup of the SMS database indicating that the backup of SMS_S01 completed successfully.
Following these entries more entries related to the backup of the software metering database will be listed.