SPBackupRestoreConsole.CreateBackupRestore 方法 (SPBackupRestoreSettings)
创建备份或还原操作,并为其分配一个 id。
命名空间: Microsoft.SharePoint.Administration.Backup
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Shared Function CreateBackupRestore ( _
settings As SPBackupRestoreSettings _
) As Guid
用法
Dim settings As SPBackupRestoreSettings
Dim returnValue As Guid
returnValue = SPBackupRestoreConsole.CreateBackupRestore(settings)
public static Guid CreateBackupRestore(
SPBackupRestoreSettings settings
)
参数
settings
类型:Microsoft.SharePoint.Administration.Backup.SPBackupRestoreSettings设置为备份或还原操作的图案。
返回值
类型:System.Guid
Guid 标识新的备份或还原操作。
异常
异常 | 条件 |
---|---|
ArgumentNullException | settings是空引用(无 在 Visual Basic 中)。 |
SPException | 该组件已经预定的备份或还原。 |
备注
在备份或还原操作是一个SPBackupRestoreConsoleObject对象。返回Guid为您的代码可以引用该操作时,它调用SPBackupRestoreConsole的关键成员的主要方式。例如,您使用Guid的SetActive, Run和Remove方法的参数。
如果您想要获取对SPBackupRestoreConsoleObject对象的直接引用,请使用Get。
CreateBackupRestore方法还会创建一个SPBackupRestoreHistoryObject对象,该对象具有相同的SPBackupRestoreConsoleObject对象 ID。
示例
下面的示例演示如何在备份应用程序中使用CreateBackupRestore方法。有关完整的示例和详细的讨论,请参阅How to: Programmatically Back Up Content。
static void Main(string[] args)
{
// Identify the location for the backup storage.
Console.Write("Enter full UNC path to the directory where the backup will be stored:");
String backupLocation = Console.ReadLine();
// Create the backup settings.
SPBackupSettings settings = SPBackupRestoreSettings.GetBackupSettings(backupLocation, "Full");
// Identify the content component to backup.
Console.Write("Enter name of component to backup (default is whole farm):");
settings.IndividualItem = Console.ReadLine();
// Set optional operation parameters.
settings.IsVerbose = true;
settings.UpdateProgress = 10;
settings.BackupThreads = 10;
// Create the backup operation and return its ID.
Guid backup = SPBackupRestoreConsole.CreateBackupRestore(settings);
// Ensure that user has identified a valid and unique component.
SPBackupRestoreObject node = EnsureUniqueValidComponentName(settings, ref backup);
// Ensure that there is enough space.
Boolean targetHasEnoughSpace = false;
if (node != null)
{
targetHasEnoughSpace = EnsureEnoughDiskSpace(backupLocation, backup, node);
}
// If there is enough space, attempt to run the backup.
if (targetHasEnoughSpace)
{
// Set the backup as the active job and run it.
if (SPBackupRestoreConsole.SetActive(backup) == true)
{
if (SPBackupRestoreConsole.Run(backup, node) == false)
{
// Report "error" through your UI.
String error = SPBackupRestoreConsole.Get(backup).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(backup);
Console.WriteLine("Backup attempt complete. Press Enter to continue.");
Console.ReadLine();
}
}// end Main
Shared Sub Main(ByVal args() As String)
' Identify the location for the backup storage.
Console.Write("Enter full UNC path to the directory where the backup will be stored:")
Dim backupLocation As String = Console.ReadLine()
' Create the backup settings.
Dim settings As SPBackupSettings = SPBackupRestoreSettings.GetBackupSettings(backupLocation, "Full")
' Identify the content component to backup.
Console.Write("Enter name of component to backup (default is whole farm):")
settings.IndividualItem = Console.ReadLine()
' Set optional operation parameters.
settings.IsVerbose = True
settings.UpdateProgress = 10
settings.BackupThreads = 10
' Create the backup operation and return its ID.
Dim backup As Guid = SPBackupRestoreConsole.CreateBackupRestore(settings)
' Ensure that user has identified a valid and unique component.
Dim node As SPBackupRestoreObject = EnsureUniqueValidComponentName(settings, backup)
' Ensure that there is enough space.
Dim targetHasEnoughSpace As Boolean = False
If node IsNot Nothing Then
targetHasEnoughSpace = EnsureEnoughDiskSpace(backupLocation, backup, node)
End If
' If there is enough space, attempt to run the backup.
If targetHasEnoughSpace Then
' Set the backup as the active job and run it.
If SPBackupRestoreConsole.SetActive(backup) = True Then
If SPBackupRestoreConsole.Run(backup, node) = False Then
' Report "error" through your UI.
Dim [error] As String = SPBackupRestoreConsole.Get(backup).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(backup)
Console.WriteLine("Backup attempt complete. Press Enter to continue.")
Console.ReadLine()
End If
End Sub ' end Main