SPBackupRestoreSettings.GetRestoreSettings 方法

使用指定的源和方法以及其他值设置为它们的默认值创建一个SPRestoreSettings对象。

命名空间:  Microsoft.SharePoint.Administration.Backup
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
Public Shared Function GetRestoreSettings ( _
    directory As String, _
    restoreMethod As String _
) As SPRestoreSettings
用法
Dim directory As String
Dim restoreMethod As String
Dim returnValue As SPRestoreSettings

returnValue = SPBackupRestoreSettings.GetRestoreSettings(directory, _
    restoreMethod)
public static SPRestoreSettings GetRestoreSettings(
    string directory,
    string restoreMethod
)

参数

  • directory
    类型:System.String

    目录位置的源的还原操作 ;所要还原的对象的备份副本,保存。

  • restoreMethod
    类型:System.String

    恢复时,"新建"或"覆盖"的类型。

返回值

类型:Microsoft.SharePoint.Administration.Backup.SPRestoreSettings
SPRestoreSettings 对象的所有值设置为其默认值。

备注

restoreMethod必须是StringSPRestoreMethodType值的表示形式。

示例

下面的示例演示如何在还原操作中使用GetRestoreSettings方法。有关完整的示例和详细的讨论,请参阅How to: Programmatically Restore Content

static void Main(string[] args)
{
    // Create the restore settings.
    SPRestoreSettings settings = SPBackupRestoreSettings.GetRestoreSettings(@"\\Server\WSSBackups", "Overwrite");

    // Identify the content component to restore.
    Console.Write("Enter name of component to restore (default is whole farm):");
    settings.IndividualItem = Console.ReadLine();
    
    // Set optional operation parameters.
    settings.IsVerbose = true;
    settings.UpdateProgress = 10;
    
    // Create the restore operation and return its ID.
    Guid restore = SPBackupRestoreConsole.CreateBackupRestore(settings);

    SPBackupRestoreObject node = EnsureUniqueValidComponentName(settings, ref restore);

    if (node != null)
    {
        // Set the restore as the active job and run it.
        if (SPBackupRestoreConsole.SetActive(restore) == true)
        {
            if (SPBackupRestoreConsole.Run(restore, node) == false)
            {
                // Report "error" through your UI.
                String error = SPBackupRestoreConsole.Get(restore).FailureMessage;
                Console.WriteLine(error);
            }
        }
        else
        {
            // Report through your UI that another backup
            // or restore operation is underway. 
            Console.WriteLine("Another backup or restore operation is already underway. Try again when it ends.");
        }

        // Clean up the operation.
        SPBackupRestoreConsole.Remove(restore);

        Console.WriteLine("Restore attempt complete. Press Enter to continue.");
        Console.ReadLine();
    }
}// end Main
Shared Sub Main(ByVal args() As String)
    ' Create the restore settings.
    Dim settings As SPRestoreSettings = SPBackupRestoreSettings.GetRestoreSettings("\\Server\WSSBackups", "Overwrite")

    ' Identify the content component to restore.
    Console.Write("Enter name of component to restore (default is whole farm):")
    settings.IndividualItem = Console.ReadLine()

    ' Set optional operation parameters.
    settings.IsVerbose = True
    settings.UpdateProgress = 10

    ' Create the restore operation and return its ID.
    Dim restore As Guid = SPBackupRestoreConsole.CreateBackupRestore(settings)

    Dim node As SPBackupRestoreObject = EnsureUniqueValidComponentName(settings, restore)

    If node IsNot Nothing Then
        ' Set the restore as the active job and run it.
        If SPBackupRestoreConsole.SetActive(restore) = True Then
            If SPBackupRestoreConsole.Run(restore, node) = False Then
                ' Report "error" through your UI.
                Dim [error] As String = SPBackupRestoreConsole.Get(restore).FailureMessage
                Console.WriteLine([error])
            End If
        Else
            ' Report through your UI that another backup
            ' or restore operation is underway. 
            Console.WriteLine("Another backup or restore operation is already underway. Try again when it ends.")
        End If

        ' Clean up the operation.
        SPBackupRestoreConsole.Remove(restore)

        Console.WriteLine("Restore attempt complete. Press Enter to continue.")
        Console.ReadLine()
    End If
End Sub ' end Main

另请参阅

引用

SPBackupRestoreSettings 类

SPBackupRestoreSettings 成员

Microsoft.SharePoint.Administration.Backup 命名空间