Thursday, 12 July 2012

Automatic Sharepoint 2010 Site Collection BackUP Script

You can Take Site collection backup Using SharePoint 2010 Central Administration.
Central Administration -> Backup And Restore -> Specify  Site Collection and path to save backup.
But Most simple way to Use Power Shell Command 

Backup-Spsite -identity  “SiteURL”  -Path “File Name With Path”.

this is Manual Process,  You can automate this Process using PowerShell and Windows Task Scheduler , This will automate your Back process.

Step 1: 
Open Note pad and Paste Below written Script in it , Also modify Function call According to your  Environment (SiteCollection Url, path and Initial/prefix of you FileName).

Add-PsSnapin Microsoft.SharePoint.Powershell –ErrorAction SilentlyContinue
Function BackupSite([string]$SiteURL,[string]$path,[string]$BackUpInitial)
$today=(Get-Date  -Format dd-MMMM-yyyy-"'Time'"-hh-mm)
backup-Spsite -identity $SiteURL -Path $path\$BackUpInitial-$today.bak
#Function Call – Replace Parameter according to you requirements.
BackupSite "http://sp2010/" "C:\Backups" "SP2010"

Step2 : Save this File as ps1 Extension  (MyScript.ps1)

Step 3: Add this Script you Windows Task Scheduler.
            Start -> Administrative Tools -> Task Scheduler - > Create Task.
            Specify Task Name, Specify User to Run this Task in General Tab,
            Specify Trigger Time (to Automatic Trigger this Task)
Specify Action in Action Tab. select Action to Start Program from Dropdown, Write     
Program/Script “powershell.exe” Or you can select path from Browse Button.
            Add Argument s Write the PS1 File Name with path. 
You can read More details about windows task scheduler at technet Article  
You can Run this this Task Manually To test it, Select the Task, right Click and Click RUN.