Created
March 22, 2021 16:47
-
-
Save imamkhaira/f53c9ba88ad08cba327f41ae502bfc59 to your computer and use it in GitHub Desktop.
sharepoint-backup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PsSnapin Microsoft.SharePoint.PowerShell | |
Set-Location $home | |
$subdomains = "epesb", "epehr" | |
# CHANGE TTHE VARIABLE BELOW To AN APPROPRIATE BACKUP LOCATION. | |
$backupdir = "C:\Users\SPFarm\Desktop" | |
New-Item -Path $backupdir -ItemType directory | |
ForEach ($subdomain in $subdomains) { | |
# CHANGE THE VARIABLE BELOW To AN APPROPRIATE SITE ROOT URL. | |
$fullURL = "https://$subdomain.s2m.online/sites/*" | |
$sites = Get-SPSite -Identity $fullURL -Limit ALL | |
# for every single site found, perform the backup and | |
# put the timestamp in the file name. | |
ForEach ($site in $sites){ | |
$filename = "$subdomain-$($site.Url.toString().Remove(0,(26+$subdomain.Length)))" | |
Write-Output "Backing up $($site.Url.ToString()) ==TO== $filename.bak ..." | |
Backup-SPSite $site.Url.ToString() -Path "$backupdir$filename.bak" -UseSQLSnapshot | |
Write-Output "OK" | |
} | |
Write-Output "Done." | |
# repeat. | |
} | |
Write-Output "Backup to $backupdir has been finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment