Partager via


SPBackupRestoreConsole.CreateBackupRestore - Méthode (SPBackupRestoreSettings)

Crée une opération de sauvegarde ou de restauration et lui attribue un code.

Espace de noms :  Microsoft.SharePoint.Administration.Backup
Assembly :  Microsoft.SharePoint (dans Microsoft.SharePoint.dll)

Syntaxe

'Déclaration
Public Shared Function CreateBackupRestore ( _
    settings As SPBackupRestoreSettings _
) As Guid
'Utilisation
Dim settings As SPBackupRestoreSettings
Dim returnValue As Guid

returnValue = SPBackupRestoreConsole.CreateBackupRestore(settings)
public static Guid CreateBackupRestore(
    SPBackupRestoreSettings settings
)

Paramètres

Valeur renvoyée

Type : System.Guid
Guid qui identifie la nouvelle opération de sauvegarde ou de restauration.

Exceptions

Exception Condition
ArgumentNullException

settings est une référence Null (Rien dans Visual Basic).

SPException

Le composant est déjà planifié pour une sauvegarde ou une restauration.

Remarques

L'opération de sauvegarde ou de restauration est un objet SPBackupRestoreConsoleObject . Le Guid retourné est le principal moyen de votre code peut faire référence à l'opération lorsqu'il appelle les membres critiques de SPBackupRestoreConsole. Par exemple, vous utilisez la Guid en tant que paramètre pour les méthodes SetActive, Runet Remove .

Si vous souhaitez obtenir une référence directe à l'objet SPBackupRestoreConsoleObject , utilisez Get.

La méthode CreateBackupRestore crée également un objet SPBackupRestoreHistoryObject qui possède le même ID que l'objet SPBackupRestoreConsoleObject .

Exemples

L'exemple suivant montre comment utiliser la méthode CreateBackupRestore dans une application de sauvegarde. Pour l'exemple complet et une description détaillée de ce dernier, consultez 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

Voir aussi

Référence

SPBackupRestoreConsole classe

SPBackupRestoreConsole - Membres

CreateBackupRestore - Surcharge

Microsoft.SharePoint.Administration.Backup - Espace de noms