OpsMgr 2007/2012: How to Configure SQL Server Log Shipping
Introduction
This document provides deployment guidance for installing and configuring the SQL Server 2005, SQL Server 2008, and SQL Server 2008 R2 Log Shipping feature as an option to provide redundancy of the System Center Operations Manager 2007 or System Center 2012 Operations Manager operational database between two SQL Server servers in the same management group. This configuration is intended to compliment your recovery strategy.
Excerpts regarding the consideration of implementing sub-minute log shipping was originally published here - http://sqlcat.com/sqlcat/b/technicalnotes/archive/2009/02/24/scheduling-sub-minute-log-shipping-in-sql-server-2008.aspx and have been reproduced here with slight modifications.
SQL Log Shipping Overview and Recommendations
Log shipping consists of three operations:
- Back up the transaction log at the primary server instance.
- Copy the transaction log file to the secondary server instance.
- Restore the log backup on the secondary server instance.
The log can be shipped to multiple secondary server instances. In such cases, operations 2 and 3 are duplicated for each secondary server instance.
A log shipping configuration does not automatically fail over from the primary server to the secondary server. If the primary database becomes unavailable, any of the secondary databases can be brought online manually and Operations Manager will need to be reconfigured in order to reference the secondary server.
In SQL Server 2005, 2008, and 2008 R2, SQL Server Management Studio user interface allows the frequency of the scheduled jobs to be one minute or more, which means that the minimum latency of log shipping is as long as three minutes (one minute each for the backup, copy, and restore jobs). The scheduling of the jobs can be set for sub-minute frequency (the minimum is ten seconds), however, there are some important considerations that you should be aware of which could impact your overall strategy:
- The next execution of the job will not start until the previous execution has completed. Let’s assume you have set the frequency interval of the log backup job to 10 seconds, but one execution of the log backup takes 12 seconds to complete. The next backup job will start at the next scheduled time, which is 20 seconds after the start of the previous backup job. One execution of the job is skipped in this case.
- Every time a log backup is completed, a message similar to the following is shown in the SQL Server ERRORLOG:
2009-02-09 15:25:56.94 Backup Log was backed up. Database: Test_LS, creation date(time): 2009/02/09(14:27:24), first LSN: 19:145:1, last LSN: 19:145:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {'\PRIMARY_DL380\LSBackup\Test_LS_20090209232551.trn'}). This is an informational message only. No user action is required.
If you take a log backup every 10 or 15 seconds, the SQL Server ERRORLOG flooded with such messages.
If you don’t want these messages flooding the SQL Server ERRORLOG, you can enable trace flag 3226. This trace flag doesn’t alter the behavior of backup jobs; it just suppresses the backup completion messages, preventing them from getting into the SQL Server ERRORLOG. Note that this trace flag suppresses all backup messages – database backup as well as transaction log backup.
- Information about each backup is also recorded in the msdb database (the msdb.dbo.backupset, msdb.dbo.backupmediaset, msdb.dbo.backupmediafamily, msdb.dbo.backupfile, and msdb.dbo.backupfilegroup system tables). If you back up too frequently, you can expect these tables to grow faster than usual. You should periodically check the size of these tables and delete or archive the old information as necessary. To delete the old backup history, use the stored procedure sp_delete_backuphistory.
- The backup compression feature in SQL Server 2008 provides significant space and time savings. Backup compression results in smaller backups, and it helps improve the performance of all the operations performed by log shipping by providing the following:
- Faster backup of the transaction log on the primary server.
- Faster copying of the transaction log backup file to the secondary over network.
- Faster restore of the log backup on the secondary.
However, the benefits of backup compression come with the price of higher processor utilization. If your log backup jobs use compression and are scheduled too frequently, you may notice frequent spikes in processor utilization on the primary server. Restoring from a compressed backup uses more processing power, and you could see frequent spikes in processor utilization on the secondary servers as well.
Operations Manager Prerequisites
Selecting an Account for the SQL Server Agent Service
The service startup account defines the Microsoft Windows account in which SQL Server Agent runs and its network permissions. SQL Server Agent runs as a specified user account. In order to support the log shipping feature of SQL Server, this service must run under a domain user account and is a member of the local SQLServer2005SQLAgentUser$Computername$Instance group for SQL Server 2005 and for SQL 2008 and 2008 R2, the account should be a member of the SQLServerSQLAgentUser$ComputerName$Instance group.
For further information, please review, Setting up Windows Service Accounts in the SQL Server Books Online.
Firewall Access for SQL Server
To access an instance of SQL Server through a firewall, you must configure firewall rules to allow access for the following ports:
Scenario | Port |
SQL Server Default Instance | TCP Port 1433 |
File and Printer Sharing | TCP Ports 137, 138, and 139 |
For further information, please review Configuring the Windows Firewall to Allow SQL Server Access in the SQL Server Books Online.
Create the Backup Folder
Before you configure log shipping, you must create a share to make the transaction log backups available to the secondary server. This is a share of the directory where the transaction log backups will be generated.
- Log onto the primary SQL Server hosting the OperationsManager database with administrative credentials.
- Create a directory to backup the transaction log files to. Example: D:\TransLogs.
- Share the directory created in Step 2 and grant the domain user account associated with the SQL Agent (Instance) service account Full Control rights.
- Grant the SQL Agent (Instance) service account Full Control NTFS permissions on the directory created in Step 2.
- Repeat steps 1 through 4 on the secondary SQL Server.
Set the Full Recovery Model for the OperationsManager Database
By default, when the databases are created in support of Operations Manager, they are set with the simple recovery mode, as it inherits its recovery model from the model database. In order to support SQL Server 2005, 2008, 2008 R2 Log Shipping, the database must be reconfigured to use the full recovery model. By changing this setting, it is important to note that the transaction logs will continuously grow and will not be truncated until a transactional backup has successfully completed as part of the log shipping configuration. Scheduling the backup of the transaction logs to occur every 15 minutes is recommended and should complement your overall backup strategy for the databases. Test this configuration in a lab environment before implementing in production and monitor closely in order to ensure you have defined an appropriate schedule frequency which will complete all three log shipping activities within that window and avoids performance or storage space issues on the primary SQL server.
Enable Log Shipping
- Right click the OperationsManager database, and then click Properties.
- Under Select a page, click Transaction Log Shipping.
- Select the Enable this as a primary database in a log shipping configuration check box.
- Under Transaction log backups, click Backup Settings.
- In the Network path to the backup folder box, type the network path to the share you created for the transaction log backup folder.
- If the backup folder is located on the primary server, type the local path to the backup folder in the If the backup folder is located on the primary server, type a local path to the folder box. (If the backup folder is not on the primary server, you can leave this box empty.)
- Configure the Delete files older than and Alert if no backup occurs within parameters.
- Note the backup schedule listed in the Schedule box under Backup job. If you want to customize the schedule for your installation, then click Schedule and adjust the SQL Server Agent schedule as needed.
- Click OK.
- Under Secondary server instances and databases, click Add.
- Click Connect and connect to the instance of SQL Server that you want to use as your secondary server.
- In the Secondary Database box, choose the OperationsManager database from the list.
- On the Initialize Secondary database tab, choose the option that you want to use to initialize the secondary database. Note: If you choose to have Management Studio initialize the secondary database from a database backup, the data files created on the secondary server will have the same names as those on the primary server, and will be created in an identical directory structure, including the drive letter.
- On the Copy Files tab, in the Destination folder for copied files box, type the path of the folder into which the transaction logs backups should be copied. This folder is often located on the secondary server.
- Note the copy schedule listed in the Schedule box under Copy job. If you want to customize the schedule for your installation, click Schedule and then adjust the SQL Server Agent schedule as needed. The frequency of 15 minutes is recommended for the schedule.
- On the Restore tab, under Database state when restoring backups, choose the Standby mode option.
- If you chose the Standby mode option, choose if you want to disconnect users from the secondary database while the restore operation is underway.
- Note the restore schedule listed in the Schedule box under Restore job. If you want to customize the schedule for your installation, click Schedule and then adjust the SQL Server Agent schedule as needed. The frequency of 15 minutes is recommended for the schedule.
- Click OK.
- Under History retention, choose the length of time you want to retain a record of your log shipping history.
- Click OK.
- On the Database Properties dialog box, click OK to begin the configuration process.
Once you have completed setting up log shipping, the transaction (.TRN) files should start to appear in the pre-defined shares created to host the transaction log files on both servers. To confirm that log shipping is functioning correctly, check the log shipping jobs have been successful in the Job Activity Monitor under the SQL Server Agent in SQL Management Studio on both servers.
Failing Over to a Log Shipping Secondary
Preparing for a Controlled Failover
Typically, the primary and secondary databases are unsynchronized, because the primary database continues to be updated after its latest backup job. Also, in some cases, recent transaction log backups not have been copied to the secondary server instances, or some copied log backups might still not have been applied to the secondary database. We recommend that you begin by synchronizing all of the secondary databases with the primary database, if possible.
- Copy any uncopied backup files from the backup share to the copy destination folder of each secondary server.
- Apply any unapplied transaction log backups in sequence to each secondary database.
- After the secondary server is synchronized, you can fail over by recovering its secondary database and redirecting the Root Management Server and management servers in the Operations Manager 2007 R2 management group to that server instance. For an Operations Manager 2012 management group, you can fail over by redirecting the management servers. Recovering puts the database into a consistent state and brings it online.
For more information about using this function in SQL Server, see the SQL Server documentation at http://technet.microsoft.com/en-us/library/ms191233.
Recover a Database without Restoring
- Open SQL Server Management Studio.
- In the Connect to Server dialog box, select the appropriate values in the Server type list, in the Server name list, in the Authentication list, and then click Connect.
- Click New Query.
- In the query window, enter the following query: RESTORE DATABASE OperationsManager WITH RECOVERY
- Click Execute.
- Close SQL Server Management Studio.
Preparing the Operations Manager 2007 R2 Management Group
- Stop the Operations Manager services (System Center Data Access, System Center Management, and System Center Management Configuration for Root Management Servers and System Center Management for management servers) in the management group.
- In a clustered Root Management Server environment, use Cluster Administrator to configure each of the three services listed above with the Take Offline option.
- Update the registry on each management server in the management group to reference the new SQL Server-based computer. Complete this step also on the Root Management Server, and if the Root Management Server is clustered, then you must complete this step on all the nodes in the cluster. Note: Before editing the Registry, follow your site's backup policies with regard to the registry.
- Log onto the management server with administrator permissions.
- Click Start, select Run, type regedit in the Open box, and then click OK to start Registry Editor.
- Under HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft Operations Manager\3.0\Setup, double-click the value DatabaseServerName, and then change the value to the hostname of the SQL Server-based computer now hosting the OperationsManager database.
- Click OK.
- Close the Registry Editor.
- Update the OperationsManager Database with the New Database Server Name, ensure that the account that you are logged on with has sufficient privileges on the SQL Server instance.
- Open SQL Server Management Studio.
- Expand Databases, OperationsManager and Tables.
- Right-click dbo.MT_ManagementGroup, and then click Open Table.
- Change the value in the SQLServerName_6B1D1BE8_EBB4_B425_08DC_2385C5930B04 column to reflect the name of the new SQL Server-based computer.
- Save your change.
- On the new server hosting the OperationsManager database, add the correct permission for the Login of the Root Management Server on which the SDK Account is running, as follows:
- Open Microsoft SQL Server Management Studio, and in the Object Explorer pane, navigate to Security and then expand Logins.
- Locate the SDK Account - add the account if it is not listed. Note: If the SDK Account is running as LocalSystem, use the format <domain\computername$> in SQL Logins, where <computername> is the name of the Root Management Server.
- Right-click the SDK Account, and select Properties.
- In the Login Properties dialog box, in the Select a page pane, select User Mapping.
- In the Users mapped to this login list, in the Map column, check the box that corresponds to OperationsManager (default name).
- In the Database role membership for: OperationsManager list, ensure that the following items are checked: configsvc_users, db_datareader, db_datawriter, db_ddladmin, and sdk_users.
- Click OK to save your changes and to close the Login Properties dialog box.
- On the new server hosting the OperationsManager database, add the correct permission for the Login of the Root Management Server on which the Action Account is running, as follows:
- Open Microsoft SQL Server Management Studio, and in the Object Explorer pane, navigate to Security and then expand Logins.
- Locate the Action Account - add the account if it is not listed. If the Action Account is running as LocalSystem, use the format <domain\computername$> in SQL Logins, where <computername> is the name of the Root Management Server
- Right-click the Action Account, and select Properties.
- In the Login Properties dialog box, in the Select a page pane, select User Mapping.
- In the Users mapped to this login list, in the Map column, check the box that corresponds to OperationsManager (default name).
- In the Database role membership for: OperationsManager list, ensure that the following items are checked: db_datareader, db_datawriter, db_ddladmin, and dbmodule_users.
- Click OK to save your changes and to close the Login Properties dialog box.
- On the new server hosting the OperationsManager database, add the correct permission for the Login of the Data Warehouse Server on which the Data Warehouse Action Account is running, as follows:
- Open Microsoft SQL Server Management Studio, and in the Object Explorer pane, navigate to Security and then expand Logins.
- Locate the Data Warehouse Action Account - add the account if it is not listed.
- Right-click the Data Warehouse Action Account, and select Properties.
- In the Login Properties dialog box, in the Select a page pane, select User Mapping.
- In the Users mapped to this login list, in the Map column, check the box that corresponds to OperationsManager (default name).
- In the Database role membership for: OperationsManager list, ensure that the following items are checked: db_datareader and dwsynch_users.
- Click OK to save your changes and to close the Login Properties dialog box.
Preparing the Operations Manager 2012 Management Group
- Stop the Operations Manager services (System Center Data Access, System Center Management, and System Center Management Configuration) on all the management servers in the management group.
- Update the registry on each management server in the management group to reference the new SQL Server-based computer. Note: Before editing the Registry, follow your site's backup policies with regard to the registry.
- Log onto the management server with administrator permissions.
- Click Start, select Run, type regedit in the Open box, and then click OK to start Registry Editor.
- Under HKEY_LOCAL_MACHINE\Software\Microsoft\System Center\2010\Common\Database, double-click the value DatabaseServerName, and then change the value to the hostname of the SQL Server-based computer now hosting the operational database. Note: If you are using a named instance of SQL Server, be sure to use the ServerName\Instance name format.
- Click OK.
- Close the Registry Editor.
- On each management server, edit the following file: %ProgramFiles%\System Center 2012\Operations Manager\Server\ConfigService.config. In the <Category> tag named “Cmdb”, change the value for ServerName to the name of the new SQL server.
- Update the operational database with the new database server name.
- Open SQL Management Studio.
- Expand Databases, OperationsManager, and Tables.
- Right-click dbo.MT_Microsoft$SystemCenter$ManagementGroup, and then click Edit Top 200 Rows.
- Change the value in the SQLServerName_6B1D1BE8_EBB4_B425_08DC_2385C930B04 column to reflect the name of the new SQL Server-based computer.
- Save the change.
- On the new SQL server hosting the operational database, expand Security, then expand Logins, and then add the data writer account. For more information, see How to: Create a SQL Server Login.
- Also in Logins, add the action account.
- Also in Logins, add the Data Access Service (DAS) computer account, using the form “domain\computername$”.
- For the DAS computer account, add the following user mappings (Note: If an account has note existed before in the SQL instance in which you are adding it, the mapping will be picked up by SID automatically from the restored operations database. If the account has existed in that SQL instance before, you receive an error indicating failure for that login, although the account appears in Logins. If you are creating a new login, ensure the User Mapping for that login and database are set to the same values as the previous login: DW Data Writer: apm_datareader, apm_datawriter, db_datareader, dwsynch_users, DAS/Configuration account: ConfigService, db_accessadmin, db_datareader, db_datawriter, db_ddladmin, db_securityadmin, sdk_users, sql_dependency_subscriber. If DAS/Configuration uses the LocalSystem account, specify computer account in form <domain>\computername>$. ):
- ConfigService
- db_accessadmin
- db_datareader
- db_datawriter
- db_ddladmin
- db_securityadmin
- sdk_users
- sql_dependency_subscriber
- Execute the following SQL commands on the operational database instance:
- sp_configure ‘show advanced options’,1
- reconfigure
- sp_configure ‘clr enabled’,1
- reconfigure
- Click Execute.
To Set ENABLE_BROKER
Before you can run tasks and use the Discovery Wizard to install agents, you need to set the ENABLE_BROKER value.
After moving the OperationsManager database, the status of the Sql Broker Availability Monitor might be set to ‘critical’ or to 'Sql Broker is disabled'. You can check the state of the Sql Broker Availability Monitor by running the following SQL query: SELECT is_broker_enabled FROM sys.databases WHERE name='OperationsManager'
Where ‘OperationsManager’ is the default database name, replace this name as appropriate.
If the query result is ‘0’, then the Sql Broker is disabled and you must re-enable it using the following procedure.
- Open SQL Server Management Studio.
- In the Connect to Server dialog box, select the appropriate values in the Server type list, in the Server name list, in the Authentication list, and then click Connect.
- Click New Query.
- In the query window, enter the following query:
- ALTER DATABASE OperationsManager SET SINGLE_USER WITH ROLLBACK IMMEDIATE
- Click Execute.
- Enter the following query:
- ALTER DATABASE OperationsManager SET ENABLE_BROKER
- Click Execute.
- Close SQL Server Management Studio. Note: Closing SQL Server Management Studio closes the connection to the database in single user mode. Depending on your configuration, you may have to manually kill any process that is connected to the database before completing the ALTER query below.
- Open SQL Server Management Studio.
- In the Connect to Server dialog box, select the appropriate values in the Server type list, in the Server name list, in the Authentication list, and then click Connect.
- Click New Query.
- In the query window, enter the following query:
- ALTER DATABASE OperationsManager SET MULTI_USER
- Click Execute.
You can verify the setting for ENABLE_BROKER is set to 1 by using this SQL query: SELECT is_broker_enabled FROM sys.databases WHERE name='OperationsManager'.
Start the Operations Manager services (System Center Data Access, System Center Management, and System Center Management Configuration) on all the management servers in the Operations Manager 2012 management group.
Start the System Center Management Configuration, System Center Data Access Service, and System Center Management service on the Root Management Server, and then restart only the System Center Management service on the remaining management servers in the Operations Manager 2007 R2 management group.
Important
Do not start the System Center Management Configuration and System Center Data Access Service on the management servers, as these services should only be running on the Root Management Server.