Skip to content

Instantly share code, notes, and snippets.

@cloudchristoph
Created November 10, 2016 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloudchristoph/3bce43a43cd1999622449827e5337b9a to your computer and use it in GitHub Desktop.
Save cloudchristoph/3bce43a43cd1999622449827e5337b9a to your computer and use it in GitHub Desktop.
param(
[Parameter(Mandatory=$true)][string]$BackupPath,
[bool]$DateTimePrefix = $true,
[bool]$OverwriteExistingBackups = $false
)
if ($DateTimePrefix) {
$date_time_prefix = Get-Date -Format "yyMMdd_HHmmss_"
} else {
$date_time_prefix = "";
}
write-host "Creating backups from all site collections" -ForegroundColor Cyan
write-host "----------------------------------------------------------------" -ForegroundColor White
write-host "Loading site collections..."
asnp *share*
$sites = Get-SPSite -Limit All
$site_count = $sites.Count
$current_site_count = 0
foreach ($site in $sites)
{
$current_site_count++
$name = $date_time_prefix + $site.Url.Replace("http://", "").Replace("https://", "").Replace("/", "_").Replace(".", "_") + ".sitebackup";
$full_path = ($BackupPath + "\" + $name)
Write-Progress -Activity "Backup all site collections" -status $site.Url -percentComplete ($current_site_count / $site_count * 100)
write-host "Creating backup from" $site.Url "... " -NoNewline
if ($OverwriteExistingBackups) {
Backup-SPSite -Identity $site.Id -Path $full_path -Force -ErrorAction Inquire
} else {
Backup-SPSite -Identity $site.Id -Path $full_path -ErrorAction Inquire
}
write-host "finished" -ForegroundColor Green
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment