{"id":1101,"date":"2014-06-29T00:01:00","date_gmt":"2014-06-29T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/06\/29\/weekend-scripter-basic-lync-server-2013-backup-and-restorepart-2\/"},"modified":"2014-06-29T00:01:00","modified_gmt":"2014-06-29T00:01:00","slug":"weekend-scripter-basic-lync-server-2013-backup-and-restorepart-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-basic-lync-server-2013-backup-and-restorepart-2\/","title":{"rendered":"Weekend Scripter: Basic Lync Server 2013 Backup and Restore&#8212;Part 2"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Use native automation and Windows PowerShell cmdlets to back up Lync Server 2013.<\/span>\nHonorary Scripting Guy, Sean Kearney, is here to finish up my crazy weekend fun automating Lync backup.\nSo we&#8217;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 <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2014\/06\/28\/weekend-scripter-basic-lync-server-2013-backup-and-restore-part-1.aspx\" target=\"_blank\">Basic Lync Server 2013 Backup and Restore&mdash;Part 1<\/a>.\nNow what else could be backed up? How about the firewall settings?\nObtaining the firewall configuration of your servers is incredibly easy within Windows Server&nbsp;2012&nbsp;R2. One single cmdlet gets us everything:<\/p>\n<p style=\"margin-left:30px\">Get-NetFirewallRule &ndash;enabled True\nIf we&#8217;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:<\/p>\n<p style=\"margin-left:30px\">$Name=(Hostname)+&#8217;-FirewallConfig.xml&#8217;; Get-NetFirewallRule &ndash;enabled True | Export-CLIXML $Name\nRunning this on each Lync server would give us the present inbound and outbound firewall rules as a single file that we could back up.\nBelieve it or not, we&#8217;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.\nNow 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 &#8220;Screenshot\/Print Game&#8221; or get creative with a little automation?\nYes, little Johnny in the back. I see you jumping up and down shouting, &#8220;Automation! Automation!&#8221;\nAutomation it is.\nHowever this time, we won&#8217;t be using Windows PowerShell (now stop crying, Johnny). We&#8217;ll be using the built-in administration commands in IIS.\nIf you&#8217;ve played with the ARR role, it&#8217;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&#8217;ll need the configuration for the ARR.\nI 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: <a href=\"http:\/\/serverfault.com\/questions\/113561\/how-can-i-export-url-rewrite-rules\" target=\"_blank\">How can I export URL rewrite rules?<\/a>\nYou can use the command <b>AppCmd<\/b> to work with the IIS configuration. To pull out all the rules for ARR, you&#8217;ll have to run the following commands:<\/p>\n<p style=\"margin-left:30px\">C:Windowssystem32inetsrvappcmd list config &#8220;websitename\/appname&#8221; -section:system.webServer\/rewrite\/rules &ndash;xml<\/p>\n<p style=\"margin-left:30px\">C:Windowssystem32inetsrvappcmd list config -section:system.webServer\/rewrite\/globalRules &ndash;xml<\/p>\n<p style=\"margin-left:30px\">C:Windowssystem32inetsrvappcmd list config -section:webFarms\/ -xml\nWe can also make this a lot more readable in DOS. Why not swap out the directory name with a variable to boot?<\/p>\n<p style=\"margin-left:30px\">SET APPCMD=C:windowssystem32inetsrv<\/p>\n<p style=\"margin-left:30px\">%APPCMD%appcmd list config &#8220;websitename\/appname&#8221; -section:system.webServer\/rewrite\/rules &ndash;xml<\/p>\n<p style=\"margin-left:30px\">%APPCMD%appcmd list config -section:system.webServer\/rewrite\/globalRules &ndash;xml<\/p>\n<p style=\"margin-left:30px\">%APPCMD%appcmd list config -section:webFarms\/ -xml\nThis is of course relatively useless because it only dumps a pile of information on the screen. So we&#8217;ll have to capture this. We&#8217;ll have to go &#8220;old school&#8221; with a redirector. And we&#8217;ll use a DOS variable for the folder name too.<\/p>\n<p style=\"margin-left:30px\">Set Backup=C:Backup<\/p>\n<p style=\"margin-left:30px\">%APPCMD%appcmd list config &#8220;websitename\/appname&#8221; -section:system.webServer\/rewrite\/rules &ndash;xml &gt; %BACKUP%rewriterules.xml<\/p>\n<p style=\"margin-left:30px\">%APPCMD%appcmd list config -section:system.webServer\/rewrite\/globalRules &ndash;xml &gt; %BACKUP%globalrewriterules.xml<\/p>\n<p style=\"margin-left:30px\">%APPCMD%appcmd list config -section:webFarms\/ -xml &gt; %BACKUP%webfarms.xml\nWe 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.<\/p>\n<p style=\"margin-left:30px\">$Computer=(GET-WMIOBJECT Win32_computersystem)<\/p>\n<p style=\"margin-left:30px\">$Ram=$Computer.TotalPhysicalMemory<\/p>\n<p style=\"margin-left:30px\">$Servername=$Computer.Name<\/p>\n<p style=\"margin-left:30px\">$Domain=$Server.Domain<\/p>\n<p style=\"margin-left:30px\">$DiskInfo=GET-WmiObject &ndash;query &#8216;Select * from Win32_Logicaldisk where DriveType = 3&#8217;<\/p>\n<p style=\"margin-left:30px\">$DataOut = new-object PSObject<\/p>\n<p style=\"margin-left:30px\">$DataOut = Add-Member &ndash;MemberType NoteProperty &ndash;name &#8220;ServerName&#8221; &ndash;Value $Servername<\/p>\n<p style=\"margin-left:30px\">$DataOut = Add-Member &ndash;MemberType NoteProperty &ndash;name &#8220;PhysicalRam&#8221; &ndash;Value $Ram<\/p>\n<p style=\"margin-left:30px\">$DataOut = Add-Member &ndash;MemberType NoteProperty &ndash;name &#8220;Domain&#8221; &ndash;Value $Domain<\/p>\n<p style=\"margin-left:30px\">Foreach ($Disk in $DiskInfo)<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">$DataOut = Add-Member &ndash;MemberType NoteProperty &ndash;name &#8220;DriveLetter&#8221; &ndash;Value $Disk.DeviceID<\/p>\n<p style=\"margin-left:30px\">$DataOut = Add-Member &ndash;MemberType NoteProperty &ndash;name &#8220;DriveSize&#8221; &ndash;Value $Disk.Size<\/p>\n<p style=\"margin-left:30px\">}<\/p>\n<p style=\"margin-left:30px\">$DataOut | Export-CSV C:BackupServerConfig.csv\nThis 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&#8217;s an interesting thought!\nStop by tomorrow because I can sure smell something good cooking up on the Hey, Scripting Guy! Blog.\nI invite you to follow the Scripting Guys on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send an email to the Scripting Guys at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then just remember, the Power of Shell is in You.\n<b>Sean Kearney, <\/b>Windows PowerShell MVP and Honorary Scripting Guy&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;ve already gone through probably the trickiest part, which is getting the bulk of the Lync server infrastructure backed up. To read about [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[56,389,154,61,45],"class_list":["post-1101","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-lync","tag-sean-kearney","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>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&#8217;ve already gone through probably the trickiest part, which is getting the bulk of the Lync server infrastructure backed up. To read about [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=1101"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1101\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=1101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=1101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=1101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}