SPBackupRestoreConsole class

Provides static methods for running and managing backup and restore operations.

System.Object
  Microsoft.SharePoint.Administration.Backup.SPBackupRestoreConsole

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

'Declaration
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class SPBackupRestoreConsole
'Usage
Dim instance As SPBackupRestoreConsole

The SPBackupRestoreConsole class is also designed to provide a basis on which you can easily build a UI for backup and restore management.

An SPBackupRestoreConsole object loads the first time any of its members is referenced and it remains loaded until the next reset of Internet Information Server (ISS). It uses very little memory, however.

There is never more than one SPBackupRestoreConsole object.

The methods of this class work primarily with objects of the lightweight type SPBackupRestoreConsoleObject. Each object of the latter class represents a particular backup or restore operation.

The following example shows the many ways in which an SPBackupRestoreConsole object is used in a backup application. For the full example and a detailed discussion of it, see How to: Programmatically Back Up Content.

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

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: