Using the Windows Scheduler to run a SharePoint PowerShell Backup Script
Written By: MJ Ferdous -- 3/15/2011 --
(3787) comments --
Categories: Configurations, PowerShell, SharePoint 2010, SharePoint Foundation 2010, System Administration
SharePoint administrators need to run regular backups using PowerShell, the STSADM
tool or in Central Administration. There is no "built in" way to automate
these backups. Wouldn't it be great to devise a method to automated these jobs?
The solution is
just to create a batch file that can execute a PowerShell script, and then
launch it from the Windows Task Scheduler.
PowerShell Command to Backup SharePoint Site Collection
backup-spsite -identity http://SPFarm:20045/ -path C:\Backup\Backup.bak
backup-spsite -identity http://SPFarm:20045/ -path C:\Backup\Backup.bak –force
//Note: use force to overwrite existing file
So, you can use the backup-spsite command to do site backup (the example
shows http://SPFarm:20045/). The following script will start a full backup to C:\backup where you
can send a site collection URL and backup file name as a parameter to the PowerShell
$args = http://SPFarm:20045/ [Source site location URL]
$args = C:\backup\backup_site.bak [Destination path]
Step 1: Create Windows PowerShell script
backup-spsite -identity $args -path $args -force
(You could) save it as C:\Scripts\BackupSPSite.ps1 - - (Windows PowerShell script files are .ps1 files.) Now you have to call this script from batch file.
Step 2: Create Batch Script to execute PowerShell script
echo "backup Started at" %DATE% >> C:\ backup\Log.txt
powershell -command C:\Scripts\BackupSPSite.ps1 %SOURCE_SITE% %DEST%
echo "Backup completed successfully at %DEST%" on %DATE% >> C:\ backup\Log.txt
Save it as C:\Scripts\BackupSPSite.bat. Now you have to run this script.
Step 3: Run Batch Script to execute PowerShell script
So now you can automate your daily backup of a SharePoint Site.
You can also run an entire Farm backup just by using the following command in a PowerShell Script (i.e. C:\Scripts\BackupSPSite.ps1)
Backup-SPFarm -Directory C:\Backup -BackupMethod full
- Download the complete script from
- Modify the script for your source site and backup location.
- Return to MSSharepointTips to read
about other topics and ideas.
- Check out MSSQLTips.com for great
information about Microsoft SQL Server