Export (0) Print
Expand All

SPBackupRestoreObject Class

Provides helper functions for backup and restore operations and acts as a container for an SPBackupRestoreInformation object and its correlated IBackupRestore object.

System.Object
  Microsoft.SharePoint.Administration.Backup.SPBackupRestoreObject

Namespace:  Microsoft.SharePoint.Administration.Backup
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class SPBackupRestoreObject

Because it has an IBackupRestore property that returns an IBackupRestore object, a SPBackupRestoreObject object can be thought of as representing a content component of a type that can be backed up or restored.

SPBackupRestoreObject objects can be nested. For more information see the Parent and Children properties. Typically, a tree of SPBackupRestoreObject objects will mirror a tree of content components, such as farm, Web service, Web application, and content database. However, the Reparent method enables you to create trees for backup and restore operations that do not exactly mirror any part of your deployment's tree of components.

This class has no public constructor. Get a reference to an SPBackupRestoreObject object with a method that returns objects of this class; for example GetRoot, or use an indexer to get a reference to a particular member of an SPBackupRestoreObjectCollection object.

This class has several constants that are used to extract information from the object in the Information property.

An SPBackupRestoreObject object persists as an <SPBackupObject> element in an spbackup.xml or an sprestore.xml that is saved in a subfolder of the backup location identified in the Location property of the object in the Information property.

The following shows the SPBackupRestoreObject class being used in a method that will ensure that the component name submitted by a user uniquely identifies a single component to be the top of the tree of components that will be processed by a backup or restore operation. For the full example and a detailed discussion of it, see How to: Programmatically Back Up Content.

private static SPBackupRestoreObject EnsureUniqueValidComponentName(SPBackupRestoreSettings settings, ref Guid operationGUID)
{
    SPBackupRestoreObjectCollection list = SPBackupRestoreConsole.FindItems(operationGUID, settings.IndividualItem);
    SPBackupRestoreObject component = null;

    if (list.Count <= 0)
    {
        Console.WriteLine("There is no component with that name. Run again with a new name.");
        Console.WriteLine("Press Enter to continue.");
        Console.ReadLine();
    }
    else if (list.Count > 1)  // The component name specified is ambiguous. Prompt user to be more specific.
    {
        Console.WriteLine("More than one component matches the name you entered.");
        Console.WriteLine("Run again with one of the following:");
        for (int i = 0; i < list.Count; i++)
        {
            Console.WriteLine("\t{0}", list[i].ToString());
        }
        Console.WriteLine("Press Enter to continue.");
        Console.ReadLine();
    }
    else
    {
        component = list[0];
    }

    return component;

}// end EnsureUniqueValidComponentName

The following is an example of an <SPBackupObject> element in an sprestore.xml file. The component represented by the element is a SharePoint Foundation Web application named "SharePoint - 80".

<SPBackupObject Name="SharePoint - 80">
    <SPBackupRestoreClass>Microsoft.SharePoint.Administration.SPWebApplication, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</SPBackupRestoreClass>
    <SPBackupSelectable>True</SPBackupSelectable>
    <SPRestoreSelectable>True</SPRestoreSelectable>
    <SPName>SharePoint - 80</SPName>
    <SPId>6abb0dec-eeab-42d2-8996-af63b8a3ef60</SPId>
    <SPCanBackup>True</SPCanBackup>
    <SPCanRestore>True</SPCanRestore>
    <SPCurrentProgress>100</SPCurrentProgress>
    <SPLastUpdate>04/27/2009 12:34:56</SPLastUpdate>
    <SPCurrentPhase>Done</SPCurrentPhase>
    <SPParameters>
        <SPParameter Key="6abb0dec-eeab-42d2-8996-af63b8a3ef60STATE.xml"><![CDATA[00000003.bak]]></SPParameter>
        <SPParameter Key="ApplicationPoolId"><![CDATA[SharePoint Content Application Pool]]></SPParameter>
        <SPParameter Key="Features.xml"><![CDATA[0000001B.bak]]></SPParameter>
        <SPParameter Key="IdentityType"><![CDATA[SpecificUser]]></SPParameter>
        <SPParameter Key="OutboundMailServer"><![CDATA[smtp.example.com]]></SPParameter>
        <SPParameter Key="SPDescription"><![CDATA[Content and configuration data for this Web application.]]></SPParameter>
        <SPParameter Key="SPName" InputDescription="New web application name:"><![CDATA[SharePoint - 80]]></SPParameter>
        <SPParameter Key="SPServer" InputDescription="New web application URL:" ForceLtr="true"><![CDATA[http://sharepoint.example.com/]]></SPParameter>
        <SPParameter Key="SPUserName"><![CDATA[DOMAIN\username]]></SPParameter>
        <SPParameter Key="WebApplicationId"><![CDATA[67bf6cdb-8fc9-457f-9764-6a8bbf07769e]]></SPParameter>
    </SPParameters>
</SPBackupObject>

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft