IDatabaseSnapshotRestore.OnPreRestore Method
Provides preparation processing for the restoration of a database (SPDatabase object) from one of its snapshots.
Namespace: Microsoft.SharePoint.Administration.Backup
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'Declaration
Sub OnPreRestore ( _
args As SPDatabaseSnapshotRestoreEvent _
)
'Usage
Dim instance As IDatabaseSnapshotRestore
Dim args As SPDatabaseSnapshotRestoreEvent
instance.OnPreRestore(args)
void OnPreRestore(
SPDatabaseSnapshotRestoreEvent args
)
Parameters
args
Type: Microsoft.SharePoint.Administration.Backup.SPDatabaseSnapshotRestoreEventAn object that contains a reference to the snapshot from which the database is restored.
Remarks
Implement this method to provide custom logic that executes before a database is restored from a snapshot. Consider using your implementation to give the user an opportunity to cancel the restoration.
Important
Your implementation must throw an exception if it cannot execute any necessary precondition to restoration. For more information, see the reference topics for the overloads of SPDatabaseSnapshot.Restore().
Do not call this method from your own code. The restoration process calls it.
Examples
The following example shows an implementation that might be used for a database. The “this” refers to an object of a custom type called SupplementalDatabase that a developer has derived from SPDatabase and that implements IDatabaseSnapshotRestore. The method takes the database offline and then pauses the thread for 5 seconds before letting the restoration proceed.
public void OnPreRestore(SPDatabaseSnapshotRestoreEvent args)
{
if (args == null)
{
throw new ArgumentNullException("args");
}
try
{
this.Status = SPObjectStatus.Offline;
this.Update();
Thread.Sleep(5000);
}
catch (exception)
{
Exception e = new Exception(String.Format("Restoration from {0} cancelled because pre-restoration steps could not be executed.", args.Snapshot.Name), exception);
throw e;
}
}
See Also
Reference
IDatabaseSnapshotRestore Interface