IBackupRestore.OnPrepareBackup method

Provides preparation processing before a backup.

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

bool OnPrepareBackup(
	Object sender,
	SPBackupInformation args


Type: System.Object

The object that calls OnPrepareBackup.

Type: Microsoft.SharePoint.Administration.Backup.SPBackupInformation

An SPBackupInformation object that contains data about the operation.

Return value

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

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");
  • 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 noteImportant

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.

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;