Summary: Use native automation and Windows PowerShell cmdlets to back up Lync Server 2013.
Honorary Scripting Guy, Sean Kearney, is here to finish up my crazy weekend fun automating Lync backup.
So we’ve already gone through probably the trickiest part, which is getting the bulk of the Lync server infrastructure backed up. To read about that, see Basic Lync Server 2013 Backup and Restore—Part 1.
Now what else could be backed up? How about the firewall settings?
Obtaining the firewall configuration of your servers is incredibly easy within Windows Server 2012 R2. One single cmdlet gets us everything:
Get-NetFirewallRule –enabled True
If we’d like to grab a copy of the rules, we could store each within an XML file, and maybe even name the file based on the server name:
$Name=(Hostname)+’-FirewallConfig.xml’; Get-NetFirewallRule –enabled True | Export-CLIXML $Name
Running this on each Lync server would give us the present inbound and outbound firewall rules as a single file that we could back up.
Believe it or not, we’ve already backed up the edge server. How did that happen? The edge server configuration (independent of firewall settings and certificates) simply relies on the topology XML file for defining its configuration.
Now on to our IIS server, which is performing the role of Application Request Routing (ARR). How shall we back up that one? Do you want to play the “Screenshot/Print Game” or get creative with a little automation?
Yes, little Johnny in the back. I see you jumping up and down shouting, “Automation! Automation!”
Automation it is.
However this time, we won’t be using Windows PowerShell (now stop crying, Johnny). We’ll be using the built-in administration commands in IIS.
If you’ve played with the ARR role, it’s storing configuration information that does nothing more than translate one FQDN to another. To restore the ARR role on that server (other than the server name and the actual features), you’ll need the configuration for the ARR.
I will not take credit on this solution. The answer came from a brilliant fellow on serverfault.com as I was searching for the very same answer: How can I export URL rewrite rules?
You can use the command AppCmd to work with the IIS configuration. To pull out all the rules for ARR, you’ll have to run the following commands:
C:Windowssystem32inetsrvappcmd list config “websitename/appname” -section:system.webServer/rewrite/rules –xml
C:Windowssystem32inetsrvappcmd list config -section:system.webServer/rewrite/globalRules –xml
C:Windowssystem32inetsrvappcmd list config -section:webFarms/ -xml
We can also make this a lot more readable in DOS. Why not swap out the directory name with a variable to boot?
%APPCMD%appcmd list config “websitename/appname” -section:system.webServer/rewrite/rules –xml
%APPCMD%appcmd list config -section:system.webServer/rewrite/globalRules –xml
%APPCMD%appcmd list config -section:webFarms/ -xml
This is of course relatively useless because it only dumps a pile of information on the screen. So we’ll have to capture this. We’ll have to go “old school” with a redirector. And we’ll use a DOS variable for the folder name too.
%APPCMD%appcmd list config “websitename/appname” -section:system.webServer/rewrite/rules –xml > %BACKUP%rewriterules.xml
%APPCMD%appcmd list config -section:system.webServer/rewrite/globalRules –xml > %BACKUP%globalrewriterules.xml
%APPCMD%appcmd list config -section:webFarms/ -xml > %BACKUP%webfarms.xml
We could go even further with our backup process for Lync servers (or other servers, for that matter) to extend it to near disaster recovery scenarios. We could the get the memory, disk sizes, and server configuration! Nothing stopping us from doing that in Windows PowerShell. The output could be a simple CSV file too.
$DiskInfo=GET-WmiObject –query ‘Select * from Win32_Logicaldisk where DriveType = 3’
$DataOut = new-object PSObject
$DataOut = Add-Member –MemberType NoteProperty –name “ServerName” –Value $Servername
$DataOut = Add-Member –MemberType NoteProperty –name “PhysicalRam” –Value $Ram
$DataOut = Add-Member –MemberType NoteProperty –name “Domain” –Value $Domain
Foreach ($Disk in $DiskInfo)
$DataOut = Add-Member –MemberType NoteProperty –name “DriveLetter” –Value $Disk.DeviceID
$DataOut = Add-Member –MemberType NoteProperty –name “DriveSize” –Value $Disk.Size
$DataOut | Export-CSV C:BackupServerConfig.csv
This should give you a starting point for getting all of the most critical information out of our small Lync environment. It is not so tricky to do. But extending this backup to a self-documenting system? There’s an interesting thought!
Stop by tomorrow because I can sure smell something good cooking up on the Hey, Scripting Guy! Blog.
I invite you to follow the Scripting Guys on Twitter and Facebook. If you have any questions, send an email to the Scripting Guys at firstname.lastname@example.org, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then just remember, the Power of Shell is in You.
Sean Kearney, Windows PowerShell MVP and Honorary Scripting Guy