Sunday, November 17, 2013

Move Lync Server 2013 Backend Databases

Today I had to move the Lync Server 2013 backend databases from one SQL server to another SQL server. There is a procedure on Nexthop for Lync Server 2010 which is very useful but it is not complete for Lync Server 2013. I did use the procedure below in a production environment with success :-)

The first part is to move the Central Management Store (CMS) to a temporary server. Just install a Lync server Standard Edition and move the CMS to it. Before moving do check if CMS replication is healthy!
When the CMS is running on the new temporary server and CMS replication is healthy you can start with the procedure to move the Lync pool backend databases.
Step 1: Prepare databases for backup
Stop Lync services on all frontend servers in the pool. (Stop-CsWindowsServices)
Remember in which order the Lync services on the frontend servers are stopped. (third server, second server, first server)
Start Microsoft SQL Server Management Studio and connect to the current SQL Lync instance.
Run the SQL script on the Lync databases:

ALTER DATABASE cpsdyn SET OFFLINE WITH ROLLBACK AFTER 10 Seconds
ALTER DATABASE cpsdyn SET SINGLE_USER
ALTER DATABASE cpsdyn SET ONLINE

ALTER DATABASE rgsconfig SET OFFLINE WITH ROLLBACK AFTER 10 Seconds
ALTER DATABASE rgsconfig SET SINGLE_USER
ALTER DATABASE rgsconfig SET ONLINE

ALTER DATABASE rgsdyn SET OFFLINE WITH ROLLBACK AFTER 10 Seconds
ALTER DATABASE rgsdyn SET SINGLE_USER
ALTER DATABASE rgsdyn SET ONLINE

ALTER DATABASE rtcab SET OFFLINE WITH ROLLBACK AFTER 10 Seconds
ALTER DATABASE rtcab SET SINGLE_USER
ALTER DATABASE rtcab SET ONLINE

ALTER DATABASE rtcshared SET OFFLINE WITH ROLLBACK AFTER 10 Seconds
ALTER DATABASE rtcshared SET SINGLE_USER
ALTER DATABASE rtcshared SET ONLINE

ALTER DATABASE rtcxds SET OFFLINE WITH ROLLBACK AFTER 10 Seconds
ALTER DATABASE rtcxds SET SINGLE_USER
ALTER DATABASE rtcxds SET ONLINE

Step 2: Backup databases
USE Master;
GO
BACKUP DATABASE cpsdyn
TO DISK = ‘C:\CSBackup\cpsdyn.bak’

GO
BACKUP DATABASE rgsconfig
TO DISK = ‘C:\CSBackup\rgsconfig.bak’

GO
BACKUP DATABASE rgsdyn
TO DISK = ‘C:\CSBackup\rgsdyn.bak’

GO
BACKUP DATABASE rtcab
TO DISK = ‘C:\CSBackup\rtcab.bak’

GO
BACKUP DATABASE rtcshared
TO DISK = ‘C:\CSBackup\rtcshared.bak’

GO
BACKUP DATABASE rtcxds
TO DISK = ‘C:\CSBackup\rtcxds.bak’
Step 3: Copy the folder C:\CSBackup to new SQL Server.

Step 4: Update Topology Document
Open the Topology builder on your temporary Lync server where the CMS is hosted
Define a new SQL Store

Update the Frontend pool with the new SQL Store

Publish the topology, the new Lync databases will be created.

Step 5: Prepare databases for restore
Start Microsoft SQL Server Management Studio and connect to the new SQL Lync instance.
Run the SQL script on the Lync databases:


ALTER DATABASE cpsdyn SET OFFLINE WITH ROLLBACK AFTER 10 Seconds
ALTER DATABASE cpsdyn SET SINGLE_USER
ALTER DATABASE cpsdyn SET ONLINE

ALTER DATABASE rgsconfig SET OFFLINE WITH ROLLBACK AFTER 10 Seconds
ALTER DATABASE rgsconfig SET SINGLE_USER
ALTER DATABASE rgsconfig SET ONLINE

ALTER DATABASE rgsdyn SET OFFLINE WITH ROLLBACK AFTER 10 Seconds
ALTER DATABASE rgsdyn SET SINGLE_USER
ALTER DATABASE rgsdyn SET ONLINE

ALTER DATABASE rtcab SET OFFLINE WITH ROLLBACK AFTER 10 Seconds
ALTER DATABASE rtcab SET SINGLE_USER
ALTER DATABASE rtcab SET ONLINE

ALTER DATABASE rtcshared SET OFFLINE WITH ROLLBACK AFTER 10 Seconds
ALTER DATABASE rtcshared SET SINGLE_USER
ALTER DATABASE rtcshared SET ONLINE

ALTER DATABASE rtcxds SET OFFLINE WITH ROLLBACK AFTER 10 Seconds
ALTER DATABASE rtcxds SET SINGLE_USER
ALTER DATABASE rtcxds SET ONLINE



Step 6: Restore databases
RESTORE DATABASE [cpsdyn] FROM DISK = N’C:\CSBackup\cpsdyn.bak’ WITH FILE = 1,
MOVE N’cpsdyn_data’ TO N’E:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL_LYNC_2013\MSSQL\Data\cpsdyn.mdf’,
MOVE N’cpsdyn_log’ TO N’F:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL_LYNC_2013\MSSQL\Data\CPSDYN.LDF’,
NOUNLOAD, REPLACE, STATS = 10
GO

RESTORE DATABASE [rgsconfig] FROM DISK = N’C:\CSBackup\rgsconfig.bak’ WITH FILE = 1,
MOVE N’rgsconfig_data’ TO N’E:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL_LYNC_2013\MSSQL\Data\rgsconfig.mdf’,
MOVE N’rgsconfig_log’ TO N’F:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL_LYNC_2013\MSSQL\Data\RGSCONFIG.LDF’,
NOUNLOAD, REPLACE, STATS = 10
GO

RESTORE DATABASE [rgsdyn] FROM DISK = N’C:\CSBackup\rgsdyn.bak’ WITH FILE = 1,
MOVE N’rgsdyn_data’ TO N’E:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL_LYNC_2013\MSSQL\Data\rgsdyn.mdf’,
MOVE N’rgsdyn_log’ TO N’F:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL_LYNC_2013\MSSQL\Data\RGSDYN.LDF’,
NOUNLOAD, REPLACE, STATS = 10
GO

RESTORE DATABASE [rtcab] FROM DISK = N’C:\CSBackup\rtcab.bak’ WITH FILE = 1,
MOVE N’rtcab_data’ TO N’E:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL_LYNC_2013\MSSQL\Data\rtcab.mdf’,
MOVE N’rtcab_log’ TO N’F:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL_LYNC_2013\MSSQL\Data\RTCAD.LDF’,
NOUNLOAD, REPLACE, STATS = 10
GO

RESTORE DATABASE [rtcshared] FROM DISK = N’C:\CSBackup\rtcshared.bak’ WITH FILE = 1,
MOVE N’rtcshared_data’ TO N’E:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL_LYNC_2013\MSSQL\Data\rtcshared.mdf’,
MOVE N’rtcshared_log’ TO N’F:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL_LYNC_2013\MSSQL\Data\RTCSHARED.LDF’,
NOUNLOAD, REPLACE, STATS = 10
GO

RESTORE DATABASE [rtcxds] FROM DISK = N’C:\CSBackup\rtcxds.bak’ WITH FILE = 1,
MOVE N’rtcxds_data’ TO N’E:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL_LYNC_2013\MSSQL\Data\rtcxds.mdf’,
MOVE N’rtcxds_log’ TO N’F:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL_LYNC_2013\MSSQL\Data\RTCXDS.LDF’,
NOUNLOAD, REPLACE, STATS = 10
GO


Step 7: Finalizing restore databases

ALTER DATABASE cpsdyn SET multi_USER
ALTER DATABASE rgsconfig SET multi_USER
ALTER DATABASE rgsdyn SET multi_USER
ALTER DATABASE rtcadb SET multi_USER
ALTER DATABASE rtcshared SET multi_USER
ALTER DATABASE rtcxds SET multi_USER

 

After this Enable cross-database ownership chaining on RTCshared database  – Right click RTCShared database –> New Query

sp_dboption rtcshared, ‘db chaining’, TRUE
Step 8: Restart the Lync Services
Restart the Lync Services on the frontend server in reverse order they were stopped. (first server, second server, third server.) Give every server enough time to start all services before starting the next one.
In the Event viewer you should see a message that the new databases store is used.




After this you can move the CMS back to the frontend pool just as you move the CMS to the temporary server.

4 comments:

  1. Why do you need to move the databases to a temporary server. Why can't you take Lync offline and just do the rest of the steps without doing that.

    ReplyDelete
    Replies
    1. Hi, adding and removing servers in Lync needs to be done by the Lync Topology Builder which than updates the topology in the Central Management Database (CMS). If you need to move Lync databases to another SQL server you need access to that same CMS. If you move database without telling Lync you can a serious problem.

      Delete
  2. Hello, I recently went through this and may be able to provide some helpful info. Please bear in mind that I've only been working with Lync for a short time so someone should probably verify my suggestion with an expert and test in a lab before attempting.

    Since Lync 2013 differs from Lync 2010 in that the databases are replicated to the front end servers, I was able to complete this task while skipping the parts about backing up and restoring the databases.

    I first moved the CMS over to a temp server as suggested. I then simply created the new SQL stores in the topology builder which created the databases. I then simply switched the front end pool to use the new SQL server. Like magic, the data replicated from a front end server to the SQL store. The Lync environment remained available to users the entire time.

    After this, (and I would imagine this would apply to the complete version of the procedure too), I had to reboot the Front End servers before our Address Book began replicating and updating.

    I then moved the CMS to the new sql server and all is well with Lync.

    ReplyDelete
    Replies
    1. Do you have the procedure to install the CMS to a temp server?

      Delete