共用方式為


SPBackupRestoreConsole.CreateBackupRestore method (SPBackupRestoreSettings)

會建立備份或還原作業,並將其指派的識別碼。

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

Syntax

'宣告
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
)

參數

傳回值

Type: System.Guid
Guid 識別新的備份或還原作業。

Exceptions

Exception Condition
ArgumentNullException

settings是a null reference (Nothing in Visual Basic)。

SPException

備份或還原已排程的元件。

備註

備份或還原作業是SPBackupRestoreConsoleObject物件。會傳回Guid是您的程式碼可以參照作業時,它會呼叫SPBackupRestoreConsole的要徑成員的主要方法。例如,您可以使用Guid做為SetActiveRun,以及Remove方法的參數。

如果您想要取得SPBackupRestoreConsoleObject物件的直接參考,請使用Get

CreateBackupRestore方法也會建立具有相同的識別碼,做為SPBackupRestoreConsoleObject物件SPBackupRestoreHistoryObject物件。

Examples

下列範例會示範如何在備份的應用程式中使用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

請參閱

參照

SPBackupRestoreConsole class

SPBackupRestoreConsole members

CreateBackupRestore overload

Microsoft.SharePoint.Administration.Backup namespace