Tag Archives: Backup
VIDEO – How to install Ola Hallengren "Maintenance Solution" TSQL on new SQL Server 2016
Full demo video for installing “Maintenance Solution” TSQL on new SQL Server 2016 including:
- SQL Management Studio
- Set backup retention time
- Set backup folder
- Set schedule for SQL Agent jobs
Video
Download
- SQL Server Backup, Integrity Check, and Index and Statistics Maintenance
- https://ola.hallengren.com/
Estimated Arrival Time (ETA) for PowerShell
Ever had a script that takes a long time to run? Would it be nice to see an estimated time for completion? Well, the code below is for you. ![]()
Percentage complete is an easy calculation for any loop operation. Deriving time from that requires us to hold ($start) with the time our loop began. From there we can multiply out and calculate total seconds. When total seconds remaining is added to the current time .. then … you have ETA. Example below.
# Data Source
$sites = Get-SPSite -Limit All
# Initialize Tracking
$start = Get-Date
$i = 0
$total = $sites.Count
# Loop
foreach ($site in $sites) {
# Progress Tracking
$i++
$prct = [Math]::Round((($i / $total) * 100.0), 2)
$elapsed = (Get-Date) - $start
$totalTime = ($elapsed.TotalSeconds) / ($prct / 100.0)
$remain = $totalTime - $elapsed.TotalSeconds
$eta = (Get-Date).AddSeconds($remain)
# Display
$file = $site.Url.Split('/')[4]
Write-Progress -Activity "Backup $file ETA $eta" -Status "$prct" -PercentComplete $prct
# Operation
Backup-SPSite $site.Url -Path "D:\TEMP\$file.site" -WhatIf
}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. ![]()
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
