Problem
SharePoint administrators need to run regular backups using PowerShell, the STSADM tool or in central administration. There is no ' built in ' to automate these backups. Wouldn ' t it being great to devise a method to automated these jobs?
Solution
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
OR
Backup-spsite-identity http://SPFarm:20045/-path c:\backup\backup.bak–force//note:use Force to overwrite existing fil E
So, you can use the Backup-spsite command-to-do site backup (the example shows http://SPFarm:20045/). The following script would start a full backup to C:\backup where can send a site collection URL and backup file name a s a parameter to the PowerShell Script.
Step 1:create Windows PowerShell Script
Add-pssnapin Microsoft.SharePoint.PowerShell backup-spsite-identity $args [0]-path $args [1]-force
(You could) save it as C:\Scripts\BackupSPSite.ps1--(Windows PowerShell script files is. ps1 files.) Now we have a to call the this script from batch file.
Step 2:create Batch script to execute PowerShell script
@echo OffSET source_site=http://spfarm:20045/set Dest=c:\backup\backup_site.bakecho "Backup Started at"%date% > > C \ backup\log.txtpowershell-command C:\Scripts\BackupSPSite.ps1 %source_site%%dest%echo "Backup completed Successfully at%dest% "on%date% >> c \ Backup\log.txt@echo on
Save it as C:\Scripts\BackupSPSite.bat. Now there is a to run this script.
Step 3:run Batch script to execute PowerShell script
- Run Batch script to check successful backup and log creation at C:\Backup.
- Now run it from the Windows Task Scheduler. In the Task Scheduler, the account needs to is set with admin permissions to run it properly.
- See http://www.geeksengine.com/article/how-to-use-windows-task-scheduler.html If you don't know how to use task Schedule R.
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\BackupS PSITE.PS1)
Backup-spfarm-directory C:\Backup-BackupMethod Full
Next Steps
- Download the complete script from here.
- Modify the script for your source site and backup location.
- Return to Mssharepointtips to read on other topics and ideas.
- Check out mssqltips.com for great information about Microsoft SQL Server
Refer:http://www.mssharepointtips.com/tip.asp?id=1100.