1.
Open the notepad and copy the below script.
Add-PsSnapin Microsoft.SharePoint.PowerShell
Start-SPAssignment -Global
$mySite="http://sitecollectionURL"
$backupLocation="D:\SiteBackup"
$logFile="$backupLocation\BackupLog.log"
$today=Get-Date -format "MM-dd-yyyy
HH.mm.ss"
try
{
Backup-SPSite $mySite -Path
$backupLocation\SPSite_$today.bak -force
write "$today $mySite successfully backed
up">>$logFile
}
catch
{
write-Host Backup process failed
See $logFile for more information.
write "$today
Error: $_">>$logFile
}
Stop-SPAssignment -Global
Remove-PsSnapin Microsoft.SharePoint.PowerShell
write-Host "Task Finished"
- In the script specify your site collection url at variable $mySite =”http://sitecollectionURL”
- Specify the backup location at variable $backupLocation="D:\SiteBackup"
- Create a Backup log text file in the same backup location with the name “BackupLog”
- Provide an appropriate name for the file and save the file with a “.ps1” extension.
You can repeat the process from step 1 to 5 for different site
collections. In this way you can have multiple PowerShell scripts for every
site collection.
And add
additional Backup-SPSite command in the above script.
Example: Backup-SPSite $mySite1 -Path $backupLocation\Site1_$today.bak –force
Backup-SPSite $mySite2 -Path $backupLocation\Site2_$today.bak –force
Example: Backup-SPSite $mySite1 -Path $backupLocation\Site1_$today.bak –force
Backup-SPSite $mySite2 -Path $backupLocation\Site2_$today.bak –force
Example:
Add-PsSnapin
Microsoft.SharePoint.PowerShell
Start-SPAssignment -Global
$mySite1=”http://site1.domain.com”
$mySite2=”http://site2.domain.com”
$mySite3=”http://site3.domain.com”
$mySite4=”http://site4.domain.com”
$backupLocation="D:\SiteBackup"
$logFile="$backupLocation\BackupLog"
$today=Get-Date -format
"MM-dd-yyyy HH.mm.ss"
try
{
Backup-SPSite $mySite1 -Path
$backupLocation\Site_IAM_$today.bak –force
write "$today $mySite1 successfully backed
up.">>$logFile
Backup-SPSite $mySite2 -Path
$backupLocation\Site_ArtWork_$today.bak –force
write "$today $mySite2 successfully backed
up.">>$logFile
Backup-SPSite $mySite3 -Path $backupLocation\Site_ContractsDB_$today.bak
–force
write "$today $mySite3 successfully backed
up.">>$logFile
Backup-SPSite $mySite4 -Path
$backupLocation\Site_Partners_$today.bak –force
write "$today $mySite4 successfully backed
up.">>$logFile
}
catch
{
write "$today Error: $_">>$logFile
}
Stop-SPAssignment -Global
Remove-PsSnapin Microsoft.SharePoint.PowerShell
Now schedule the backup task to automate and
execute it whenever you require such as daily, weekly, monthly or yearly using
Task Scheduler.
- Start the Windows Task Scheduler by clicking on Start -> Administrative Tools ->Task Scheduler.
- From Actions, select Create Task.
- Under the General Tab, provide a name and a description (Ex: Backup of SharePoint Sites….) and choose the “Run whether user is logged on or not” and check the “Run with highest privileges” checkbox.
- Under the Triggers tab, click New and schedule a Daily or as often as you like to run the task and click OK.
- Under the Actions
tab, click New and keep the Action parameter as Start a program. In the Program/script
textbox type powershell.exe and next to Add arguments textbox, provide the path
of your script file location (Ex: D:\SPBackup\SPSite_Backup.ps1) click OK and
provide the credentials of FARM Admin or at least Site Collection Administrator
when prompted.