Backing up databases used to be challenging or had to be done with SQL management tools. Thanks to new PowerShell commands shipped with SQL server 2012 and SQL server 2012 Express (the latter shipped with Lync 2013), backing up and restoring has become a lot easier.
The script examples given here presume that the Lync backend databases are on an isolated instance (colocation core services and monitoring databases). If not, it would be wise to read up on the list of databases to take backup of at http://technet.microsoft.com/en-us/library/gg398479.aspx. Then, adjust the following scripted examples to back up or restore only the databases needed for Lync.
The methods described for Lync Standard and Enterprise are slightly different. Standard Edition backup is done on the Lync Server, whereas a backup of an Enterprise Edition should be done on the SQL server.
Run the Get-CsService –CentralManagementDatabase
command to identify the server and instance where the Lync Server has its databases.
The following are the five steps to back up your databases on a Standard Edition server:
Import-Module SQLPS –DisableNameChecking
(to import the SQL commands if the SQL server is not running PowerShell v3).cd SQLSERVER:SQLFrontenserver.mydomain.comSQLInstanceDatabases
(the server and instance information was gathered in the Getting ready section).foreach
loop (no line breaks; they are here for viewing). The foreach
command here will look at all the databases in the instance (except tempdb
) and then back them up to individual files:foreach($database in (Get-ChildItem -name -force)) {' $dbName = $database' $bakFile = "c:ackup" + $dbName + "_full_.bak"' If($dbName -ne "tempdb"){' Backup-SqlDatabase -Database $dbName -BackupFile $bakFile -Initialize}}
Restoring is not much different from backing up, and here are the four easy steps to restore your databases:
Import-Module SQLPS –DisableNameChecking
(to import the SQL commands).cd SQLSERVER:SQLFrontend?server.mydomain.comSQLInstanceDatabases
(the server and instance information was gathered in the Getting ready section).rtc
with the correct database):Restore-SqlDatabase -ServerInstance SQLInstance -Database rtc ' -BackupFile "c:BackupRtc_full_.bak" –ReplaceDatabase
3.140.195.225