Backup and Restore of SharePoint 2010 site Collection using Power Shell

Posted by Manish Kumar | computer


Backup:

Open sharepoint 2010 Management Shell from Start menu -> Microsoft Sharepoint 2010 Products -> Sharepoint 2010 Management Shell. 

A powershell  Command Prompt will be opened,

Now Write this Command in PowerShell Command Prompt window :

 Backup-SPSite -Identity http://ServerName:port -Path "c:file.bak"

For example:

 Backup-SPSite – Identity http://sharepointsite:80 –Path “c:sitebackup.bak”

profile picture

By Running this Command You will get the backup File in the folder that you have specified in Your command.

 

Restore:

IF You have a sharepoint site backup, You can restore it to any existing site or you can create a new site and restore the backup.

The Command to restore the backup:

Restore-SPSite -Identity http://Servername:port -Path "c:file.bak" –force

For Exapmle:

Restore-SPSite –Identity http://newsharepointsite:80 – Path “c:sitebackup.bak” -force

profile picture
By executing this command, the previous site will be overwritten, and the site will be restored.

 

Issues while Restoring SharePoint Site backup to a new site:

The Preffered way for Backup/Restore a sharepoint site is using Sharepoint Powershell Management Command Prompt, But You may be encountered with some errors while restoring if you  didn’t do it properly. The errors may arises If you don’t follow these steps :

1.  The Version of Your Microsoft Sharepoint server on which you restoring the backup must be same or higher than the Version of backup site Sharepoint Server.

For Checking the Version of Microsoft Sharepoint server:

Go To Start menu -> Sharepoint 2010 Central Administration

In Sharepoint Central Administration navigate to 

Upgrade and Migration -> Check Product and Patch installation Status

Match the Versions and Update it If Your New Microsoft Sharepoint Server Has Lower Version.

profile picture

 

For Downloading Updates Click Here:  Download Updates Here

2.  Match Database Schema Version on Both The Sharepoint Site. Again, The Database Schema Version of Your Microsoft Sharepoint server on which you restoring the backup must be same or        higher than the Database Schema Version of backup site Sharepoint Server.
       

          For Checking the Database Schema Version of Microsoft Sharepoint server:
 
         Go To Start menu -> Sharepoint 2010 Central Administration

In Sharepoint Central Administration navigate to 

Upgrade and Migration -> Review Database Status 

Select your databse name to check.

Match the Versions and Update it If Your New Microsoft Sharepoint Server Has Lower database schema Version.
For Updating Database Schema Version, Go to sharepoint 2010 Management Shell command prompt and execute the following Command :
   
      Upgrade-SPContentDatabase mydatabasename

      For example : 
     
      Upgrade-SPContentDatabase WSS_Content

profile picture

3.    Check and deploy all the wsp solutions (if Have) from backup site to the site new site.

For checking and Downloading the wsp solutions from the old site, follow the following steps:

•    Go To Start menu -> Sharepoint 2010 Central Administration 
•    In Sharepoint Central Administration navigate to 
•    System Setting-> Manage Farm Solutions

For Downloading the solution :

Open Notepad and write the following command to notepad:

$farm = Get-SpFarm  
$file = $farm.Solutions.Item(“YourSolutionname.wsp”).SolutionFile  
$file.SaveAs(“C:UsersDesktopYourSolutionname.wsp”)

Change the solution name to your solution name, Save File by any name with .ps1 extension, as download.ps1

Now open,  sharepoint 2010 Management Shell command prompt and go to your .ps1 notepad file location, and just type the file name and hit enter.

Your solution will be downloaded on the address provided in .ps1 file.

For Deploying the solution to the new site:

 Just open sharepoint 2010 Management Shell command prompt

Now For Adding the solution to the Farm solution write the following command :

Add-SPSolution "C:UsersDesktopyoursolutionname.wsp "        //replace your own solution address here

For Deploying the solution:

You can either deploy your solution globally or can deploy to a specific web application.

For deploying globally, just write the following command:

 Install-SPSolution -identity "yoursolutionname.wsp" –GACDeploymen  //change your solution name

For Deploying on specific site, write the following command:

Install-SPSolution –Identity "yoursolutionname.wsp" –WebApplication http://sharepointsite:80 -GACDeployment
 // change your own solution and site here..

 

4.    Match the web.config file for both the site carefully and modify the new sharepoint site web config file.

      You can find web.config file at,
      C:inetpubwwwrootwssVirtualDirectories80          //here 80 can be any port number.