Using the Windows Scheduler to run a SharePoint PowerShell Backup Script

來源:互聯網
上載者:User

標籤:des   http   os   io   for   ar   art   cti   

Problem

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?

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 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 Script.

$args[0] = http://SPFarm:20045/ [Source site location URL] $args[1] = C:\backup\backup_site.bak [Destination path] 
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 are .ps1 files.) Now you have to call 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 you have 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 be set with admin permissions to run it properly.
  • See http://www.geeksengine.com/article/how-to-use-windows-task-scheduler.html if you do not know how to use Task Scheduler.

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
Next Steps
  • Download the complete script from here.
  • 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

Refer:http://www.mssharepointtips.com/tip.asp?id=1100.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.