Saturday, September 29, 2012

Back up your Lync 2013 Preview Standard Server

**This is a very old post, please go to: http://tech.rundtomrundt.com/search/label/Backup" to see all newer versions of this script**

I really like the new approach to High Availability and Recovery in the new Lync 2013 Preview server. And one of the many new feature you probably will familiar yourself with really fast is the Backup-cspool to create a paired pool in a different site.

But even if you can fail over to somewhere else, a complete disaster recovery plan should also contain an offline backup to some other media. And this is where traditional backup comes in.

This is why I have modified my original Lync SE backup script to work on the Lync 2013 Preview server. Before you go on and download the script and run it, I would like to highlight some minor and major changes to the script.

This script can be run without any input or change, but feel free to change the paths I have created. One of the first changes I made was to have the script enumerate the local file share path as described in a previous post.

There are many new features and enhancements in Lync 2013 Powershell, and new RGS commands are a part of that. You no longer need to install the ResKit tool, and import the "RgsImportExport.ps1" in order to run the Export-CsRgsConfiguration command.

Another change, is how to import/export user data. We used to utilize the dbimpexp.exe in the tools folder. This is now obsolete, and we are now provided with the Export-CsUserData powershell command. The syntax I have used in the script looks like this:
#################################################################
# Export User information 
#################################################################

write-host "Export Userinformation (contacts and conferencing) " -ForegroundColor Green
Export-CsUserData -PoolFqdn $fqdnLync -FileName $backupfile12

The next big change in my script, is to use a new SQL 2013 Powershell command called Backup-SqlDatabase. This new backup cmdlet made much more sense to me, than the old way. But that might just because I'm no SQL server guy.

This is what the SQL backup now looks like
#################################################################
# Backing up SQL
#################################################################

write-host "Backup SQL " -ForegroundColor Green
Import-Module SQLPS -DisableNameChecking
$InstanceSQL = Get-CsService -CentralManagementDatabase | Select-Object SqlInstanceName
$instancenamesql = $InstanceSQL.SqlInstanceName.toupper()
$inst=$null
$Dest = $filepath3;    # Backup path on server (optional).   
$ServerName = $sysinfo.Name.tostring()  
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.ConnectionInfo');            
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.Management.Sdk.Sfc');            
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO');            
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMOExtended'); 
 
# Go to sql Path
cd SQLSERVER:\SQL\$ServerName\$instancenamesql\Databases 
#start full backups
$cdate = Get-Date -Format MMddyy
foreach($database in (Get-ChildItem -name -force)) {
$dbName = $database
$bakFile = $dest + "_" + $dbName + "_full_" + $cdate + ".bak"
If($dbName -ne "tempdb"){
Backup-SqlDatabase -Database $dbName -BackupFile $bakFile -Initialize}}

Now here is a portion of the script I have REM out for now. I think the syntax of the Export-CsPersistentChatData is right, but I don't have a persistent chat server in my lab to verify it's functionality. (And I would really appreciate if anyone could test it for me, if you have a persistent chat in your environment.)
#################################################################
# Export Persistant Chat  
# This part of the script will be updated once I can verify it
#################################################################

write-host "Export Persistant Chat (contacts and conferencing) " -ForegroundColor Green
$SQLInstance = Get-CsConfigurationStoreLocation | Select-Object BackEndServer
$PersistandBU = $SQLInstance.BackEndServer.ToLower()
Export-CsPersistentChatData -DBInstance $PersistandBU -FileName $backupfile13

A word of caution to me readers, I had tested the 2010 backup script many times before posting it to my blog. But this script has only been tested a few times in a LAB environment. I suggest you do the same before running it in a production environment. Not that a bunch of export commands would ruin anything, but just verify you get the backups you like.

The script can be downloaded right here, and will very soon be published on my script page as well.

Please let me know if you find any errors, or you have suggestions for improvements.