Service Broker “Broker Enabled” option goes from true to false when performing backup/restore of DB

dba.stackexchange https://dba.stackexchange.com/questions/274815

  •  07-03-2021
  •  | 
  •  

Question

We have two production servers joined by an AAG, and for a specific database, the Service Broker is enabled (Options -> Service Broker -> Broker Enabled : true. We use this for SignalR.

However, every time I perform a backup and then restore the database on a test environment, I have to manually enable the broker again (ALTER DATABASE DatabaseName SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE), as it's disabled when the database has been restored on the test server.

Can any option be set when performing either the BACKUP or RESTORE command that retains this database option? I use a script for generating the BACKUP/RESTORE statements, but I don't understand why a specific database option goes from true to false just by performing a BACKUP/RESTORE. Here are examples of the BACKUP and RESTORE commands I generate:

BACKUP DATABASE [DatabaseName] TO DISK = 'B:\backups\full_DatabaseName_20200902_1.bak', DISK = 'B:\backups\full_DatabaseName_20200902_2.bak', DISK = 'B:\backups\full_DatabaseName_20200902_3.bak', DISK = 'B:\backups\full_DatabaseName_20200902_4.bak' WITH COPY_ONLY, NOFORMAT, CHECKSUM, INIT, SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 10, BLOCKSIZE=65536

RESTORE DATABASE [DatabaseName] FROM DISK = 'B:\backups\full_DatabaseName_20200902_1.bak', DISK = 'B:\backups\full_DatabaseName_20200902_2.bak', DISK = 'B:\backups\full_DatabaseName_20200902_3.bak', DISK = 'B:\backups\full_DatabaseName_20200902_4.bak' WITH FILE=1,MOVE N'DatabaseName_data' TO N'E:\Data\DatabaseName.mdf',MOVE N'DatabaseName_log' TO N'F:\Logs\DatabaseName.ldf',MOVE N'DatabaseName_index' TO N'E:\Data\DatabaseName.ndf',MOVE N'DatabaseName_data_io' TO N'f:\Data\DatabaseName_io.ndf', NOUNLOAD, STATS = 10, RECOVERY, REPLACE
Was it helpful?

Solution

Can any option be set when performing either the BACKUP or RESTORE command that retains this database option?

Edit: you can restore the database with ENABLE_BROKER. Check the sample below:

RESTORE DATABASE [WideWorldImportersA] 
FROM  DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Backup\WideWorldImporters-Full.bak'
WITH  FILE = 1,  
MOVE N'WWI_Primary' TO N'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\SB\WideWorldImporters.mdf'
,  MOVE N'WWI_UserData' TO N'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\SB\WideWorldImporters_UserData.ndf'
,  MOVE N'WWI_InMemory_Data_1' TO N'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\SB\WideWorldImporters_InMemory_Data_1'
,  MOVE N'WWI_Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\SB\WideWorldImporters.ldf'
,  STATS = 5, ENABLE_BROKER
GO

OTHER TIPS

I found the following article which describes how to restore the database with service broker enabled :-restore - service broker options

https://mattsql.wordpress.com/2012/06/07/service-broker-what-does-a-dba-need-to-know/

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top