IBackupRestore.OnBackup method
建立並儲存內容元件的備份複本。
Namespace: Microsoft.SharePoint.Administration.Backup
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Function OnBackup ( _
sender As Object, _
args As SPBackupInformation _
) As Boolean
'用途
Dim instance As IBackupRestore
Dim sender As Object
Dim args As SPBackupInformation
Dim returnValue As Boolean
returnValue = instance.OnBackup(sender, _
args)
bool OnBackup(
Object sender,
SPBackupInformation args
)
參數
sender
Type: System.Object會啟動備份作業的物件。
args
Type: Microsoft.SharePoint.Administration.Backup.SPBackupInformationSPBackupInformation物件包含關於作業的資料。
傳回值
Type: System.Boolean
true如果成功 ;否則,請false。
備註
如果您的內容類別不有可能會有任何IBackupRestore子物件以外的任何內容,實作應該只是將**CurrentProgess()**設為至少 50%,並傳回true ,如下列範例所示。不要呼叫任何IBackupRestore子物件的OnBackup方法。
public Boolean OnBackup(Object sender, SPBackupInformation args)
{
if (args == null)
{
throw new ArgumentNullException("args");
}
args.CurrentProgress = 50;
return true;
}
Public Function OnBackup(ByVal sender As Object, ByVal args As SPBackupInformation) As Boolean
If args Is Nothing Then
Throw New ArgumentNullException("args")
End If
args.CurrentProgress = 50
Return True
End Function
如果沒有在類別有可能會有任何IBackupRestore子物件以外的內容,則您實作必須將此內容複製args。Location。會傳回false,如果有任何原因失敗之複本的內容。
下列範例會顯示**OnBackup()**一些實作的整體結構:
public Boolean OnBackup(Object sender, SPBackupInformation args)
{
if (args == null)
{
throw new ArgumentNullException("args");
}
args.CurrentProgress = 50;
Boolean successSignal = true;
// TODO: Implement copying your content to args.Location
// If the copy fails, set successSignal to false.
return successSignal;
}
Public Function OnBackup(ByVal sender As Object, ByVal args As SPBackupInformation) As Boolean
If args Is Nothing Then
Throw New ArgumentNullException("args")
End If
args.CurrentProgress = 50
Dim successSignal As Boolean = True
' TODO: Implement copying your content to args.Location
' If the copy fails, set successSignal to false.
Return successSignal
End Function
如果 Windows 服務或某些應用程式,需要停止或暫停在備份期間,您可以這麼OnBackup(Object, SPBackupInformation)的開頭。(或重新啟動服務應用程式中OnBackupComplete。)不會做這項工作的OnPrepareBackup後者方法會呼叫針對每個元件,即使未完成 ; 備份但OnBackupComplete呼叫僅針對要備份的元件,所以在停止服務或應用程式不保證準備備份階段會取得重新啟動。
OnBackup方法不會執行OnPrepareBackup會傳回 false。如果OnBackup會傳回 false,將不會執行OnBackupComplete方法。
Examples
下列範例會顯示OnBackup ,將檔案複製到備份位置的實作。FrontEndFilePaths是私人的欄位。它是保留所要備份檔案的路徑的字串集合。
public Boolean OnBackup(Object sender, SPBackupInformation args)
{
if (args == null)
{
throw new ArgumentNullException("args");
}
Boolean successSignal = true;
foreach (String path in FrontEndFilePaths)
{
FileInfo file = new FileInfo(path);
try
{
file.CopyTo(args.Location + @"\" + file.Name, true);
args.Log(SPBackupRestoreLogSeverity.Verbose, "Backed up " + file.Name);
}
catch (Exception e)
{
args.Log(SPBackupRestoreLogSeverity.Verbose, file.Name + " not backed up: " + e.Message);
successSignal = false;
}
}
args.CurrentProgress = 50;
return successSignal;
}
Public Function OnBackup(ByVal sender As Object, ByVal args As SPBackupInformation) As Boolean
If args Is Nothing Then
Throw New ArgumentNullException("args")
End If
Dim successSignal As Boolean = True
For Each path As String In FrontEndFilePaths
Dim file As New FileInfo(path)
Try
file.CopyTo(args.Location & "\" & file.Name, True)
args.Log(SPBackupRestoreLogSeverity.Verbose, "Backed up " & file.Name)
Catch e As Exception
args.Log(SPBackupRestoreLogSeverity.Verbose, file.Name & " not backed up: " & e.Message)
successSignal = False
End Try
Next path
args.CurrentProgress = 50
Return successSignal
End Function