08 June, 2012

SharePoint 2010: Backup/Restore with PowerShell Command

This article is in continuation with the backup operations thread and you can get the reference from here:
http://sharepointknowledgebase.blogspot.com/2012/06/backup-restore-in-sharepoint-2010.html

Restore Operations
Restore operations are associated with:
·         Site collection
·         Subsite
·         List and Document Libraries
Restore of the site collection
By using Powershell
Name: Restore-SPSite
Synopsis: Restores a site collection.
Syntax:  Restore-SPSite [-Identity] <String> -Path <String> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-ContentDatabase <SPContentDatabasePipeBind>] [-Force <SwitchParameter>] [-GradualDelete <SwitchParameter>] [-HostHeaderWebApplication <String>] [-WhatIf [<SwitchParameter>]] [<C
    ommonParameters>]
Description: The Restore-SPSite cmdlet performs a restoration of the site collection to a location specified by the Identity parameter. A content database may only contain one copy of a site collection. If a site collection is backed up and restored to a different URL location within the same Web application, an additional content database must be available to hold the restored copy of the site collection.
Example:
C:\PS>Restore-SPSite http://server_name/sites/site_name -Path C:\Backup\site_name.bak
This example restores a site collection from the backup file C:\Backup\site_name.bak to the site collection URL http://server_name/sites/site_name.
By using STSADM command:
For site collection restore:
    stsadm.exe -o restore
           -URL <URL>
           -filename <filename>
           [-overwrite]

How to restore the subsite
By using Powershell
Name: Import-SPWeb
Synopsis: Imports a site collection, Web application, list, or library.
Syntax: Import-SPWeb [-Identity] <SPWebPipeBind> -Path <String> [-ActivateSolutions <SwitchParameter>] [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-HaltOnError <SwitchParameter>] [-HaltOnWarning <SwitchParameter>] [-IncludeUserCustomAction <None | All>] [-IncludeUserSecurity <SwitchParameter>] [-NoFileCompression <SwitchParameter>] [-NoLogFile <SwitchParameter>] [-UpdateVersions <Append | Overwrite | Ignore>] [-WhatIf [<SwitchParameter>]] [<CommonParameters>]
Description: The Import-SPWeb cmdlet imports a site collection, Web application, list, or library. The capability to import from a library is a new feature in SharePoint 2010 Products.
Example: C:\PS>Import-SPWeb http://site -Path export.cmp -UpdateVersions –Overwrite
This example imports the contents of export.cmp into a site at http://site, overwriting the versioned content on the site with the contents of the export.cmp file.
By using STSADM command:
stsadm.exe -o import
           -URL <URL to import to>
           -filename <import file name>
           [-includeusersecurity]

How to Restore the List/Document Libraries
By using Powershell
Export-SPWeb –Identity <site URL> -Path <Filename> -Includeusersecurity
If you have any queries/questions regarding the above mentioned information then please let me know. I would be more than happy to help you as well as resolves your issuesJ J
Thank you.

22 comments:

  1. Thank you for explaining all the information in descriptive manner, plus along with examples...

    I have checked so many sites but failed to get the syntax and your blog has guided me to complete and learn the backup & Restore activities in detail manner. Million thanks once again :)

    ReplyDelete
  2. nicely written Amol!!

    ReplyDelete
  3. Fabulous information throughout the whole blog! Keep going...

    ReplyDelete
  4. is there any way to restore a library to a different name? For eg: if I backed up a library named "abc" and I want to restore it to a library named "xyz", how do I do it?

    ReplyDelete
    Replies
    1. Below comment will change the library name but if you wanna change the library URL also then that's also possible by means of SPD or explorer view. let me know in case of any queries. Thank you

      Delete
  5. You can change the name anytime. get the restore complete and change the name by means of document library settings- this will change the name. let me know in case of any queries. Thank you

    ReplyDelete
  6. Excellent piece of info! Keep it up...

    ReplyDelete
  7. How to move data from SharePoint 2007 Fab 40 template (IT Team Workspace) Template content to SharePoint 2010 Team Site Template, without using migration tool,
    We need to move manually.
    I tried by commands Export and Import, for this I am suppose to get error



    C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN>stsa
    dm -o import -url http://sp2010new:9999 -filename exportsite.cmp

    Start Time: 12/5/2013 1:27:47 PM.
    Progress: Initializing Import.
    Warning: Export only contains the last major of a file.
    Progress: Starting content import.
    Progress: De-Serializing Objects to Database.
    [Web] [occcats] Progress: Importing
    [Web] [occcats] Error: Cannot import site. The exported site is based on the t
    emplate ITTEAM#0 but the destination site is based on the template STS#0. You ca
    n import sites only into sites that are based on same template as the exported site.
    FatalError: Cannot import site. The exported site is based on the template ITTEA
    M#0 but the destination site is based on the template STS#0. You can import site
    s only into sites that are based on same template as the exported site.
    Progress: Import did not complete.
    Finish Time: 12/5/2013 1:29:22 PM.
    Duration: 00:01:34
    Finished with 1 warnings.
    Finished with 2 errors.

    ReplyDelete
    Replies
    1. ok, do one thing, its very easy.

      Source site (that you are exporting)- is using IT TEAM Workspace template

      Destination site (on which you are importing) - is using Team site template ---- Delete this site and Create a site using the same template i.e. IT TEAM Workspace template and then start the import.

      let me know the results, thanks

      Delete
  8. This is a fantastic website, could you be interested in going through an interview concerning just how you made it? You can visit my site.

    collection & recovery

    ReplyDelete
  9. Hi Amol

    I have Site Collection content DB backup of PRODUCTION Site& size is 310 GB which is on SQL server 2012 & on QA I have SQL server 2010.
    I want to restore sub-site from site collection content DB backup which is of 310 GB.
    Any suggestion for about situation..

    Thanks in Advance..

    Ajit Gaikwad

    ReplyDelete
    Replies
    1. Hello Ajit,

      Here is the plan- Irrespective of SQL server versions, i would concentrate on SP Versions present in prod and QA environments.

      Please correct me if i am wrong - from the written explanation, i understood that you wanted to take the backup of prod subsite and restore it to QA environment. If that is the case then its very easy!

      - Take the backup of prod subsite by using PowerShell
      - Move that backup file to your QA Environment.
      - Restore the site by using Powershell.

      let me know if this answers your question. In case of any queries/questions then please feel free / don't hesitate to come forward, Thank you.

      Delete
  10. Fabulous article! You have covered everything :)

    ReplyDelete
  11. This is the best article i have ever seen on backup-restore! especially syntax along with examples, Keep it up your wonderful work!!!

    ReplyDelete
  12. how to migrate sharepoint sites to sub sites
    through powershell, stsadm and central Admin
    how many ways

    ReplyDelete
    Replies
    1. I would suggest to go for PowerShell as it is most fruitful and recommended one. If you refer the above article then you will find both the ways i.e. export and import. In case of any further queries then please drop a note here. Thanks

      Delete

Your feedback is always appreciated. I will try to reply to your queries as soon as possible- Amol Ghuge

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