BizTalk DR: Configuring BizTalk Backup for Disaster Recovery – Part 2

Originally posted by Nick Heppleston at:

This is the second of a three-part series covering the BizTalk Backup Process, where I’m looking at one of the two supported methods to backup and restore a BizTalk Server environment – Log Shipping. The series will cover the following topics:

  • In Part 1, I’ll provide a high-level overview of the backup and restore process. Part 1 is already published, go an read it now!
  • In Part 2, I’ll walk through an actual backup and restore setup, looking at the configuration steps as we go.
  • In Part 3, I’ll demonstrate a long-running BizTalk application that is restored on a sample disaster recovery environment using the backup and restore process configured in Part 2.

Please accept my apologies for the wide screenshots in this part of the series. Please also note that I have not repeated the configuration steps on the MSDN website – this is an excellent resource and I do not wish to repeat or plagarise this work. In this part of the series, I have simply added my own observations that I thought were lacking from the MSDN text.

BizTalk Log Shipping – A Quick Recap

Before we look at how the BizTalk Log Shipping process is configured, let us quickly recap on the process; for a more detailed overview, I recommend that you read Part One of this series of blog posts, specifically the section which covers The Backup and Restore Process.

The backup and restore process (BizTalk Log Shipping) is as follows:

  • The BizTalk Backup SQL Agent Job creates data and transaction-log backups from the production environment, placing log marks into the transaction-log backups. An audit table is maintained which lists the backups that have been created, the type of backup (data or transaction-log backup) and details the location of the backup files. The physical data- and log-files are then pushed to a UNC share, as shown below:

BizTalk Backup Process Overview

  • The standby environment reads the audit table maintained by the production environment, using this information to determine which data- and transaction-log files need to be restored. These files are restored from the UNC share using the SQL ‘NORECOVERY’ option, leaving the databases in a non-operational state, allowing additional transaction-logs to be applied. Note: the transaction-logs are not restored to the transaction-log mark in this step, instead the full transaction-log is restored:

BizTalk Backup Process Overview

These two steps continue throughout live operations. In the event of a disaster recovery situation, where the production environment has been lost and the standby environment needs to be brought online, three recovery steps must be performed on the standby environment:

  • The most recent transaction-log backup is restored to its transaction-log mark using the SQL ‘WITH RECOVERY’ option, placing the databases into an operationally ready state.
  • Database and registry updates statements are run to re-configure the restored databases to use the standby environment.
  • BizTalk services are brought online (including the Enterprise Single Sing-On server and Business Rules Engine service etc.) and the standby environment is made live as the production environment.

Once the live environment is recovered and the switch from the standby environment back to the live environment is ready to be made, the process is reversed, with the standby environment creating backups that are restored to the live environment.

In this post, we’ll look at how to configure each of these steps.

BizTalk Log Shipping – Prerequisites

Several prerequisites need to be setup before configuring BizTalk Log Shipping. I would recommend that you spend time to ensure that these areas work, as they will save you a great deal of pain when configuring log shipping. They include:

  1. Before starting to configure the BizTalk Log Shipping process, ensure that the production and standby servers can communicate with each other over the network;
  2. The production and standby SQL Server instances need to communicate with each other via MSDTC (Microsoft Distributed Transaction Coordinator). There are a number of excellent resources on the internet addressing MSDTC configuration issues including Troubleshooting Problems with MSDTC on the MSDN website. Ensure that the two serverscan communicate over MSDTC before starting to configure Log Shipping;
  3. The BizTalk backup and restore SQL Agent jobs should run as under an isolated user account – choose a Windows user account for this purpose and create a SQL Server login for this account. Map this SQL Server login to the BTS_BACKUP_USERS database role in the BizTalk Server databases; and finally
  4. It is recommend that the data- and transaction-log backup files are written to a highly-available UNC share. Ensure that an UNC share is created that is accessible by both the production and standby servers and that the necessary permissions are assigned. Check that you can read, write and delete files from this share using Windows Explorer on both  servers.

Configuring The Backup Job

The first task in configuring BizTalk Log Shipping is to configure the SQL Agent ‘Backup BizTalk Server (BizTalkMgmtDb)’ backup job on the production environment. This job is created by the BizTalk installer and is responsible for a number of tasks, including:

  • Creating a full database backup at the specified interval;
  • Writing a transaction-log mark to the transaction-log and creating a backup of the transaction-log; and finally
  • Clearing the backup history table, based on specified criteria.

To configure the job, follow the instructions detailed in the excellent How to Configure the Backup BizTalk Server Job on the MSDN website.

When configuring the backup job, remember the following:

  • The Frequency parameter denotes the frequency at which a full backup is taken. By default, this is set to d (daily) which is sufficient for most BizTalk environments. If you require more frequent full backups, change this accordingly – other values include h (hourly), w (weekly), m (monthly), or y (yearly). Note that irrespective of what frequency you set here, transaction log backups will occur every time this job is run.
  • The (optional) Force full backup after partial backup failures parameter instructs the backup job to create a full backup if a transaction-log backup failed the last time the job ran, ignoring the Frequency setting. For example, if you use a setting of ‘daily’ for the Frequency parameter and the job fails to create a full set of transaction-log backups, the next time the job runs, it will create a full-backup followed by a further transaction-log backup; a second full-backup followed by a transaction-log backup will be created when the job runs again at midnight (UTC time) to honour the Frequency setting.
  • When setting the Location of backup files parameter, ensure that the user who is running this SQL Agent job has sufficient privileges to write to that location.

By default, this job runs once every fifteen minutes; this means that a transaction-log backup will be created and restored once every fifteen minutes (once you have configured the log shipping restore jobs, which execute once every minute). If you want to reduce delay in restoring these transaction-logs to your standby environment, reduce the scheduled frequency of the backup job. I would however recommend that this job is run no more frequently than once every three minutes; you will however need to find a happy medium that works best in your environment – this will be based on the load on your BizTalk Server and the rate at which your SQL Server transaction-logs grow.

Once you have configured the backup job, execute it starting at step one and ensure you have backup data- and log-files in your UNC share location, and entries in the BizTalkMgmtDb.dbo.adm_BackupHistory table, as follows:


These entries in the Backup History table will be read by the restore jobs on the standby SQL Server and used to identify which data and log files need to be restored. Of particular interest in the above screenshot of the Backup History table are the following columns:

  • The BackupSetId column, which is used during the restore to identify an entire backup-set;
  • The MarkName column, which details the Transaction-Log Mark Name given to transaction-logs (Notice how the full database-backup has a value of NULL instead of a a log mark name, as these cannot be applied to full backups);
  • The BackupFilename and BackupFileLocation columns, which are used by the restore jobs to locate the data- and log-files to restore;
  • The BackupType column, which is used by the restore jobs to identify the type of backup the backup set relates to; and finally
  • The SetComplete column, which is used by the (optional) Force full backup after partial backup failures parameter of the backup job to determine whether a full or partial backup was taken during the last execution.

One final point to note about the ‘Backup BizTalk Server (BizTalkMgmtDb)’ backup job: if the SQL Agent Service or the backup-job is disabled and misses the time-window in which the full-backup should be taken (based on the Frequency parameter), the next execution of the job will cause a full backup to be created. For example, if you use a setting of ‘daily’ for the Frequency parameter and the job is disabled between 2000 and 0200 (i.e. during the time window that the daily full-backup will occur – 0000UTC), when the job is enabled, it will detect that its ‘frequency’ has been missed and cause a full-back to be created, followed by a transaction-log backup.

Forcing a Full Backup

There may be cases where you wish to perform an ad-hoc full-backup, outside of the Frequency window specified in Backup BizTalk Server SQL Agent Job – for example, you may want to take a full backup before applying a hotfix or service pack, or when replacing hardware.

When a backup is forced, the Frequency window is ignored next time the Backup BizTalk Server job executes and both data- and log-file backups are generated. If a problem occurs in the scenarios described above and the databases need to be recovered, only one transaction log needs to be restored for each database, reducing the recovery time significantly.

To force a full backup, execute the BizTalkMgmtDb.dbo.sp_ForceFullBackup stored procedure; the next time the Backup BizTalk Server job executes, both data- and log-file backups will be generated.

Configuring BizTalk Log Shipping – The Restore Jobs

We’re now ready to configure the standby environment to automagically restore our data- and log-file backups that are created by our production environment.

Several new jobs will be created in the standby SQL Server environment to handle the restoring of backups (along with a number of tables and stored procedures in the master database, which are used to hold information about the Log Shipping process). The jobs in particular are responsible for a number of tasks, including:

  • Retrieving the backup history from the production environment;
  • Restoring the data- and transaction-log backup files to the standby SQL Server in a non-operational state, allowing further transaction-logs to be restored; and finally
  • Restoring all of the databases to an operational state, by restoring the next available transaction-log to their last log mark only when disaster recovery is invoked and the standby SQL Server environment is to be made operational.

For more detailed information on these jobs, I recommend that you read the first part of this series, specifically the section which covers the Restore Process and the BizTalk Log Shipping Jobs.

To configure log shipping on the standby environment, follow the instructions detailed in the excellent How to Configure the Destination System for Log Shipping on the MSDN website.

When configuring the backup job, remember the following:

  • The standby environment will try and read the data- and log-files from the same location as they were written to by the backup job; it is therefore prudent to use a UNC share location (mapped to a drive letter if necessary) that both the standby and production environments have read/write permissions to.
  • If you encounter problems executing the bts_ConfigureBizTalkLogShipping stored procedure, ensure that you have correctly configured MSDTC between the production and standby environments; additionally, check that you have enabled Ad Hoc Distributed Queries on the standby SQL Server (if using SQL Server 2005/2008) as this stored procedure executes distributed queries over a linked server to the production SQL Server.
  • If you need to re-configure your standby environment, re-run the configuration process including starting with the LogShipping_Destination_Schema.sql and LogShipping_Destination_Logic.sql before executing the bts_ConfigureBizTalkLogShipping stored procedure.

A note about the Physical Location of Database Files when Restoring

If you have been around SQL Server for any length of time, you will have come across some of the more ‘helpful’ features of restoring data- and transaction-log files – when you restore a backup, SQL Server will attempt to re-create the database on the standby environment in exactly the same directory structure as the data- and log-file/s appeared on the production SQL Server.

If the directory structure doesn’t exist on the standby server exactly as it did on the production server, you will receive an error similar to the following and the restore will fail:

Executed as user: BIZTALKDRBizTalkBackup. Directory lookup for the file “D:MSSQL.4MSSQLDATABizTalkMgmtDb.mdf” failed with the operating system error 3(The system cannot find the path specified.). [SQLSTATE 42000] (Error 5133) File ‘BizTalkMgmtDb’ cannot be restored to ‘D:MSSQL.4MSSQLDATABizTalkMgmtDb.mdf’. Use WITH MOVE to identify a valid location for the file. [SQLSTATE 42000] (Error 3156) Directory lookup for the file “D:MSSQL.4MSSQLDATABizTalkMgmtDb_log.LDF” failed with the operating system error 3(The system cannot find the path specified.). [SQLSTATE 42000] (Error 5133) File ‘BizTalkMgmtDb_log’ cannot be restored to ‘D:MSSQL.4MSSQLDATABizTalkMgmtDb_log.LDF’. Use WITH MOVE to identify a valid location for the file. [SQLSTATE 42000] (Error 3156) Problems were identified while planning for the RESTORE statement. Previous messages provide details. [SQLSTATE 42000] (Error 3119) RESTORE DATABASE is terminating abnormally. [SQLSTATE 42000] (Error 3013). The step failed.

There are a number of ways we can resolve this, including using the WITH MOVE statement, as suggested in the error text, however this would require us to make changes to the stored procedure that is invoked by the Restore Databases SQL Agent job – this would invalidate our warranty with Microsoft as changes to the SQL Server portion of the codebase are not supported.

SQL Server uses several techniques to determine the physical location that databases should be restored to (further information can be found in Microsoft Knowledgebase Article 221465); the easiest method is to perform an implicit ‘MOVE’ – if the database already exists on the standby environment, but at a different location than specified in the backup set, the location on the server is used during the restore.

I would therefore recommend that you create the various BizTalk databases (including the Business Rules Engine Db and SSO Db) in their correct locations on the standby environment before you enable the restore job, this way SQL Server will restore the databases to your preferred location.

Testing the Restore Functionality

With log shipping successfully configured, enable the BTS Log Shipping – Get Backup History (DBServer: “[Database Server Name]”, DBName: “[Database Name]”) SQL Agent job to retrieve backup history information from the production environment.

If everything is configured correctly, you will see entries in the standby SQL Server master.dbo.bts_LogShippingHistory table which show the backups that are yet to be restored (see the Restored and RestoredDateTime columns highlighted in Green). In the following screenshot, there is one full database backup, plus three transaction-log backups to be restored.


With the backup history successfully retrieved from the production environment, we’re now ready to start restoring the data- and log-files to our standby environment.

Enable the BTS Log Shipping – Restore Databases (DBServer: “[Database Server Name]”, DBName: “[Database Name]”) SQL Agent job. As described in the first post of this series, this job restores the BizTalk databases to a non-operational state, allowing further transaction-logs to be restored. The job uses the  ‘NORECOVERY’ option, leaving each database in the ‘Restoring…’ state, thereby allowing additional transaction-logs to be applied.

In the screenshot below, the Restore Databases job has been enabled and has executed, restoring the full backup set (BackupType ‘Db’) and two transaction-log backup sets (BackupType ‘Lg”) as highlighted in Green; the transaction log set that has not been restored – highlighted in Orange – is the N-1 backup-set that is only restored when the standby environment is to be brought online as the new production environment; this is to ensure that we always have one transaction-log that can be restored to the transaction-log mark. Also note that the RestoredDateTime column is populated with the UTC time, not the actual system time.


One final point to take away when restoring databases is the way in which the restore job handles full backups (BackupType ‘Db’). If the production environment creates a full backup – either because the Backup job has crossed its Frequency window, or the BizTalk Administrator has forced a full backup – the Log Shipping Restore job will only restore the transaction log created during the full backup – it skips the data-file backup as this isn’t required to maintain database integrity. As demonstrated in the screenshot below, the transaction logs before and after the full backup have been restored (highlighted in Green), however the data-file backup hasn’t been restored (highlighted in Purple); finally, the N-1 transaction log set is yet to be restored (highlighted in Orange):


Cleaning the Standby Environment

You may want to clean the standby environment without performing a full reconfiguration of BizTalk Log Shipping, so that the restore process starts from scratch: the databases are re-created and restoration starts as if it is the first time it has run.

To achieve this, execute the master.dbo.bts_LogShippingClean stored procedure on the standby environment. This stored procedure deletes all references to the previously restored backup-sets and physically deletes the databases that are in the ‘restoring’ state. The bts_LogShippingClean stored proc accepts a single parameter @SourceId; the value you should use for this  parameter is based on your log shipping configuration which is available in the master.dbo.bts_LogShippingDatabases table, an example of which is shown below:


These two actions force the BTS Log Shipping – Restore Databases job to re-create the databases in a restoring state by applying the last full backup, followed by subsequent transaction log backups the next time it runs. This is demonstrated in the screenshot below – the data-file and transaction-log backups are restored (highlighted in Green), with the N-1 transaction log set is yet to be restored (highlighted in Orange); also notice how the full- and transaction log backups are restored sequentially at the same time, within a few seconds of each other (see the RestoredDateTime column):


Handling Partial Backup-Sets

One of the most common errors I encountered while putting together this series of blog posts related to partially restored backups-sets. The SQL Agent BTS Log Shipping – Restore Databases job automagically detects this condition and raises an error in the Event Log similar to the following:

Executed as user: BIZTALKDRSqlAgent. A partial set has been detected but a valid full backup set does not exist yet.  Please force a full backup on the source server. [SQLSTATE 42000] (Error 50000)  @LastSetId: 487 [SQLSTATE 01000] (Error 0)  @RestoredToMark: 0 [SQLSTATE 01000] (Error 0)  Here101 [SQLSTATE 01000] (Error 0)  @NextSetId: 488 [SQLSTATE 01000] (Error 0)  Here102 [SQLSTATE 01000] (Error 0)   [SQLSTATE 01000] (Error 0)  Statement2: 1 [SQLSTATE 01000] (Error 0)  Statement3: 1 [SQLSTATE 01000] (Error 0).  The step failed.

The restore job identifies this error condition by simply checking for a backup set that has both restored and non-restored entries, as shown in the screenshot below (highlighted in Orange):


When a partially restored backup-set is detected, the restore job will attempt to identify and restore a more recent full data- and transaction-log backup, thereby minimizing the synchronization gap between the production and standby environments. If a more recent full backup cannot be found, the job will fail reporting the error detailed above and either wait until a new full backup is created as the backup job passes its Frequency window, or when the BizTalk Administration forces a full backup.


So that’s the end of Part 2. We’ve walked through configuring the backup and restore jobs and looked at how to check that these jobs are working correctly, how to force full backups and problems caused by partial restores.

In Part 3, we’ll demonstrate a long-running BizTalk application that is restored and brought operational on a standby environment using the instructions detailed here.

Postscript: Creating a Sandbox Environment to Test Log Shipping

Before jumping into configuring Log Shipping on a production environment, I would suggest that you become familiar with how the process itself works, either in a test or sandboxed environment. In writing this series of blog posts, I created a small VirtualBox based virtual-machine sandbox with which I could test the various scenario’s I planned on writing about. This sandbox consisted of:

  • A ‘production’ server hosting BizTalk and the BizTalk databases in an operational state;
  • A ‘standby’ server hosting BizTalk and the restored BizTalk databases;
  • A standalone server acting as an Active Directory Domain Controller.

All three servers communicate through a private VirtualBox network and cannot be seen outside of the physical host machine. The ‘production’ and ‘standby’ servers run Windows Server 2008, plus BizTalk Server 2009 and SQL Server 2008 (all Enterprise Edition), running with 512Mb RAM; the AD server runs Windows Server 2008 Core, running with 256Mb RAM. All three virtual-machines run extremely well given their small amount of RAM, however they need to be located on a separate HDD to the physical machine’s OS otherwise heavy I/O thrashing causes a significant degradation in performance.

Reblog this post [with Zemanta]