Pages

Tuesday, June 22, 2010

SharePoint 2010: Backup/Restore with PowerShell Command

If you want to backup/restore your site collection in SharePoint 2010, you can do with PowerShell command. I’ll spilt the post in two sections. One is on how to backup/restore in the same site collection and another is how to backup from one server/site collection to another. For the former (backup/restore in the same site collection), SharePoint provides nice easy GUI page in Central Administration page. However, for second one (backup/restore between different server) you need to run PowerShell scripts.

Backup/Restore in the same server and same site  collection

Sometimes you may want to backup from a site collection and your intention is to restore the backup in the same site collection. One example might be you have a site collection, say “http://myserver” and you are going to run code to test something against the site. However, you fear that running the code may break something and before you run the code, you want to backup the site so that in case running the code breaks something you can restore the backup taken before running the code. In the case, where you need to backup/restore is centered around same server and site collection, you can take SharePoint Central administration UI to do the backup/restore.

Backup Steps

1. Navigate to the Central Administration => Backup and Restore

2. Under “Farm Backup and Restore” section click “Perform a backup”.

3. Now you’ll be landed in the following page where you can select the site or site collection you want to take backup:

image

4. Click next and you’ll be navigated to the following page where you can select backup type (full or differential) and backup location:

image

 

Restoring Steps

To restore follow the steps:

1. Navigate to the Central Administration => Backup and Restore.

2. Under “Farm Backup and Restore” section click “Restore from a backup”. Follow the wizard to restore from a backup.

 

Backup/Restore from one server to another or from one Site Collection to another (with PowerShell command)

In some cases, you have developed a SharePoint site collection in your dev or stg machine and now you want to move the site with data from dev/stg to production. In such cases the process shown in the section “Backup/Restore in the same server and same site  collection” will not work. The recommended way is to use PowerShell command to take backup and restore the backup.

Backup a Site collection with PowerShell command

In SharePoint 2010, PowerShell command Backup-SPSite is used for taking backup. you can get details of the command from the msdn link. The following command will backup the site collection ‘http://myserver’.

Backup-SPSite -Identity http://myserver -Path "c:\backup\file.bak"

Restore a Site Collection with PowerShell command

To restore site collection you’ll use the following command. Use –Force if you want to overwrite the existing site collection

Restore-SPSite -Identity http://myserver -Path "c:\backup\file.bak"

However, once I had restored the backup I could not access the site. The problem was that I needed to deploy the custom SharePoint solution. So in case of site collection migration (with backup/restore) from one server to another or from one site collection to another, the steps should be:

  1. Restore the backup.

  2. If your source site collection (from where you taken backup) uses custom SharePoint solution, then deploy the solution in the destination site collection (where you are restoring the backup). If you try to access the site without deploying solution then you may get the site non-functional.

  3. Now you can try to access the site.

The important point here is that if you take backup from one server to another and restore it, the custom solution related to backup doesn’t go with backup. So after restoring backup you need to manually deploy the solution on the destination server. Then it’ll hopefully work.

30 comments:

  1. Thanks for sharing this real-world scenario.

    ReplyDelete
    Replies
    1. Hi danny, you can check video version of this on : http://sharepointshah.blogspot.in/2012/07/backup-and-restore-sharepoint-2010-site.html

      Delete
  2. Worked Great! Thanks for sharing!

    ReplyDelete
  3. Hi, do you know if it's possible after a backup to send the report to an e-mail address ???

    ReplyDelete
  4. If you want to send email then you can develop a small program that will backup using SharePoint Object model and send email. You can then schedule the program to run on an interval.

    ReplyDelete
  5. Great ! I am not able to do this process successfully and is facing so many problem doing so. After having read the whole process I have figured out what I was doing wrong. Thanks for explaining the process so nicely using screen shots.

    ReplyDelete
  6. Glad to know that the post helps others. Thanks for your comment.

    ReplyDelete
    Replies
    1. Hey I got a problem in configuring backup and restore process.
      It shows always Status: Caution A backup or restore is currently in progress. Backup and Restore Job Status
      what should I do for that?
      Please do help.

      Delete
    2. "A backup or restore is currently in progress. Backup and Restore Job Status"
      Same problem, how do you fixed that?

      Delete
  7. Hi, I have a doubt. I have migrated my site from SP2007 to SP2010 and now when I use Site content and structure to migrate to my sites using tree picker i get an error "there was error in the call back" . Is there any way I can resolve it. pls help!!

    ReplyDelete
  8. Plagiarize MSDN => Add verbiage => Auto-promote via google => MVP

    ReplyDelete
  9. Thanks kitty for your thoughts. We people have different views and that's why google, microsoft, apple and so many companies. Surely MSDN is the key piece of resources for MS based developers. But you can't deny individual MVP's efforts to get those MSDN docs meaningful to users. If MSDN was enough then people would go to MSDN always rather than searching others' blogs.

    ReplyDelete
  10. There are some who don't like the good work done by others and Kitty seems to be one of them and by the way as Sohel said, had MSDN be the only source for information then I believe Kitty would not have been here on this page in the first place.
    Lastly, good work Sohel and keep doing it.

    ReplyDelete
  11. Any idea on the Sujith's doubt?
    Hi, I have a doubt. I have migrated my site from SP2007 to SP2010 and now when I use Site content and structure to migrate to my sites using tree picker i get an error "there was error in the call back" . Is there any way I can resolve it. pls help!!

    I am about to take the path into migration of 2007 farm to 2010, any help regarding this would be helpful.

    ReplyDelete
  12. Hi Anirudhk,
    I've not worked on migration from Sp07 to 2010. So maybe I can't help but you can go to SharePoint forums in MSDN to look for help.

    ReplyDelete
  13. How do I know which bak file to pisk when restoring a site collection from a farm backup? I have over 100 bak files in my backup directory

    Thanks!

    ReplyDelete
  14. The file names starts with filename00.bak, filename01.bak etc. Use the filename.bak.

    ReplyDelete
  15. Restore-SPSite -Identity http://myserver -Path "c:\backup\file.bak"

    Does this actually work? From the documentation on technet (http://technet.microsoft.com/en-us/library/ff607788.aspx) it looks like the form must be http://myserver/sites/. When I try to restore to a root site collection it doesn't work, but does if I restore to as a site collection under "sites".

    ReplyDelete
  16. What's the site collection will be depends on your local site collection url. The site collection url can be http://mysite or http://mysite/sites. So please use your proper site collection url

    ReplyDelete
  17. Has anyone tried to use the -BackMethod (Full/Differential), incorporated into the actual backup statement?

    I am having real problems trying to use the -BackupMethod, in the statement. Each time I use it, in Powershell, I get an error message and the backup fails. The error refers to the paramenter -BackupMethod not being able to be matched....

    Has anyone encountered this problem?
    The backup itself works fine, whenever I omit the -Backupmethod option.

    ReplyDelete
  18. Hi

    I have a solution "solution1.wsp" and a site collection level feature "feature 1", solution is deployed and feature is activated on server 1 and everything working well.
    no i performed a backup and restored on server 2, would i be able to see "feature 1"? feature 1 is part of solution file and i have not deployed solution file on server2.

    ReplyDelete
  19. @Shafaqat, The sharepoint backup only takes backup of the database not for the 12/14 hive. Any artifacts deployed through sharepoint solution package will not be included in the backup. So in short the feature1 will not be available in the server 2 unless you don't deploy the solution.

    ReplyDelete
  20. Its Very Simple and very clear.. good work bro..

    ReplyDelete
  21. Thank you very much for sharing this fantastic article. This will definitely helps the whole sharepoint community and many users gets benefited from the same. Thanks again :-), keep posting such valuable information.

    ReplyDelete
  22. Nice article, even you can check video version and other nice article on this blog: -> http://sharepointshah.blogspot.in

    ReplyDelete
  23. Thanks for article! It was helful. Here is also good article http://pragmaticcoding.com/index.php/sharepoint-2010-simple-backuprestore-via-powershell/

    ReplyDelete
  24. please try to bakcup and restore using the power shell
    go to
    http://profadmins.com

    ReplyDelete
  25. Hi there, nice post and a good source of information. It really shows that you're an expert in this field. I'm looking for some tips on how to do a full site backup wordpress in this site. Thanks for sharing. Keep it up!

    ReplyDelete
  26. Use Sharepoint Database Repair Tool can also easy recover all sharepoint databases like tables, indexes, documents, labels, and stored procedures from inaccessible MDF files.

    See at: http://www.filesrecoverytool.com/sharepoint-database-repair.html

    ReplyDelete

Note: Only a member of this blog may post a comment.