Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.
Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.

Daily Front End Backup

The below PowerShell can be run once per day via Task Scheduler on just one machine in a SharePoint farm to backup front end configuration.   Yes, SQL backups are wonderful and a must have for user data protection.   However, front end backups are handy for restore scenarios like:

 

  • IIS configuration
  • IIS home folder
  • WPS farm solutions
  • 14/15 hive manual changes  (yeah yeah … not best practice, but you have them too)

 

These front end artifacts might not be in a SQL full BAK.   Also, having troubleshooting options on the front end helps SharePoint admins respond quickly to a recovery without having to wait for DBAs to first restore a database.    Hope that helps.  

Smile

 

Start-Transcript

Write-Host "Starting..."
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$dest = "d:\backuptest"
$day = Get-Date -Format "yyyy-MM-dd"
("iisconfig","inetpub","farmsol","hive","ipfs") |% {New-Item "$dest\$_-$day" -ItemType Directory -ErrorAction SilentlyContinue} | Out-Null

Write-Host " - IIS config"
Copy-Item "C:\windows\system32\inetsrv\config" "$dest\iisconfig-$day" -Recurse

Write-Host " - IIS home folder"
Copy-Item "C:\inetpub" "$dest\inetpub-$day" -Recurse

Write-Host " - SharePoint farm solutions"
Get-SPSolution |% {$s=$_.SolutionFile;$n=$s.Name;$s.SaveAs("$dest\farmsol-$day\$n")}

Write-Host " - SharePoint hive folder"
$major = (Get-SPFarm).BuildVersion.Major
Copy-Item "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\$major" "$dest\hive-$day"  -Recurse

Write-Host " - InfoPath Forms Services"
Backup-SPFarm -Directory "$dest\ipfs-$day" -BackupMethod Full -Item "InfoPath Forms Services"

Write-Host " - Remove old folders"
$threshold = (Get-Date).AddDays(-2)
$files = Get-ChildItem $dest | Sort-Object LastWriteTime -Descending
$files | ?{ $_.LastWriteTime -lt $threshold } | Remove-Item -Force -Recurse

Write-Host "Operation completed successfully"

Stop-Transcript

© Copyright 2016
@ SPJeff

Return to Top ▲Return to Top ▲