Partilhar via


IBackupRestore.OnPrepareBackup Method

Provides preparation processing before a backup.

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

Syntax

'Declaration
Function OnPrepareBackup ( _
    sender As Object, _
    args As SPBackupInformation _
) As Boolean
'Usage
Dim instance As IBackupRestore
Dim sender As Object
Dim args As SPBackupInformation
Dim returnValue As Boolean

returnValue = instance.OnPrepareBackup(sender, _
    args)
bool OnPrepareBackup(
    Object sender,
    SPBackupInformation args
)

Parameters

  • sender
    Type: System.Object

    The object that calls OnPrepareBackup.

Return Value

Type: System.Boolean
true if successful; otherwise, false.

Remarks

A major purpose of OnPrepareBackup is to use the SetParameter() method to set the parameters of the SPBackupInformation object (args) so that they can be used by later event handlers, especially OnPreRestore and OnRestore.

Some examples of what can be done in OnPrepareBackup:

  • Always set the SPName parameter of args with the value of the Name property.

  • If the content component represented by the IBackupRestore object is some kind of database, OnPrepareBackup can be used to specify settings information needed to connect with the database application.

  • If the content component represented by the IBackupRestore object is duplicated on every Front End server, OnPrepareBackup can be used to specify which server that will be the source of the backup operation. Set the SPServer parameter with the URL of the chosen server as shown in this example:

    args.SetParameter(SPBackupRestoreObject.SPServer, "some_URL");
    
    args.SetParameter(SPBackupRestoreObject.SPServer, "some_URL")
    
  • If your implementation of OnPrepareBackup takes a significant portion of the total time for the backup operation, set args.CurrentProgess() to an appropriate value.

Important

Do not stop or pause a service or Web application in the OnPrepareBackup method. See OnBackup(Object, SPBackupInformation) for why.

The OnPrepareBackup method will always run when the IBackupRestore object has been selected for backup. If it returns false, neither the OnBackup nor the OnBackupComplete methods will run.

Examples

The following example shows a minimal implementation of OnPrepareBackup, which is often all that is needed

public Boolean OnPrepareBackup(Object sender, SPBackupInformation args)
{
    if (args == null)
    }
        throw new ArgumentNullException("args");
    }
    args.SetParameter(SPBackupRestoreObject.SPName, this.Name);
    return true;
}
Public Function OnPrepareBackup(ByVal sender As Object, ByVal args As SPBackupInformation) As Boolean
    If args Is Nothing Then
        Throw New ArgumentNullException("args")
    End If
    args.SetParameter(SPBackupRestoreObject.SPName, Me.Name)
    Return True
End Function

See Also

Reference

IBackupRestore Interface

IBackupRestore Members

Microsoft.SharePoint.Administration.Backup Namespace