Compartilhar via


IBackupRestore.OnRestore method

Lê o conteúdo e copiá-lo para o destino da operação de restauração.

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

Syntax

'Declaração
Function OnRestore ( _
    sender As Object, _
    args As SPRestoreInformation _
) As Boolean
'Uso
Dim instance As IBackupRestore
Dim sender As Object
Dim args As SPRestoreInformation
Dim returnValue As Boolean

returnValue = instance.OnRestore(sender, _
    args)
bool OnRestore(
    Object sender,
    SPRestoreInformation args
)

Parâmetros

Valor retornado

Type: System.Boolean
true se for bem-sucedida; Caso contrário, false.

Comentários

Se sua classe de conteúdo pode ser migrado, seu código deve verificar para ver o que é o método de restauração e chamar Rename() se o método é New.

Se sua classe de conteúdo não possui nenhum conteúdo fora de todos os objetos filho IBackupRestore pode ter, sua implementação deve simplesmente definir o CurrentProgess() pelo menos 50 por cento e retornar true , como mostrado no exemplo a seguir. Fazer chamada o método OnRestore de todos os objetos filho IBackupRestore .

public Boolean OnRestore(Object sender, SPRestoreInformation args)
{
    if (args == null)
    {
        throw new ArgumentNullException("args");
    }
    if (args.RestoreMethod == SPRestoreMethodType.New)
    {
        args.Rename();
    }

    args.CurrentProgress = 50;
    return true;
}
Public Function OnRestore(ByVal sender As Object, ByVal args As SPRestoreInformation) As Boolean
    If args Is Nothing Then
        Throw New ArgumentNullException("args")
    End If
    If args.RestoreMethod = SPRestoreMethodType.New Then
        args.Rename()
    End If

    args.CurrentProgress = 50
    Return True
End Function

Se sua classe does ter conteúdo fora todos os objetos filho IBackupRestore pode ter, sua implementação deve copiar o conteúdo para o destino de restauração. Retorne false, se por algum motivo a cópia de conteúdo falhar.

O exemplo a seguir mostra a estrutura geral de uma implementação sólida do OnRestore():

public Boolean OnRestore(Object sender, SPRestoreInformation args)
{
    if (args == null)
    {
        throw new ArgumentNullException("args");
    }
    if (args.RestoreMethod == SPRestoreMethodType.New)
    {
        args.Rename();
    }

    args.CurrentProgress = 50;
    Boolean successSignal = true;

    // TODO: Implement copying your content to the destination.
    //       If the copy fails, set successSignal to false.

    return successSignal;
}
Public Function OnRestore(ByVal sender As Object, ByVal args As SPRestoreInformation) As Boolean
    If args Is Nothing Then
        Throw New ArgumentNullException("args")
    End If
    If args.RestoreMethod = SPRestoreMethodType.New Then
        args.Rename()
    End If

    args.CurrentProgress = 50
    Dim successSignal As Boolean = True

    ' TODO: Implement copying your content to the destination.
    '       If the copy fails, set successSignal to false.

    Return successSignal
End Function

Se um serviço do Windows ou um aplicativo, precisa ser interrompido ou pausado durante a restauração, você pode fazer isso no início do OnRestore. (Reiniciar o serviço ou aplicativo em OnPostRestore(Object, SPBackupInformation)). Fazer esse trabalho em OnPreRestore(Object, SPBackupInformation) que o último método é chamado para cada componente, mesmo que ele não está sendo restaurado; mas OnBackupComplete é chamado somente para componentes que são restauradas, portanto não há nenhuma garantia de que um serviço ou aplicativo parado no estágio de preparação poderia obter reiniciado.

O método OnRestore não será executado se OnPreRestore retornará false. Se OnRestore retornar false, o método OnPostRestore não será executado.

Examples

O exemplo a seguir mostra uma implementação de OnRestore que restaura arquivos para um servidor front-end. FrontEndFilePaths é um campo particular. Ele contém uma coleção de caminhos dos arquivos a serem restaurados.

public Boolean OnRestore(Object sender, SPRestoreInformation args)
{
    if (args == null)
    {
        throw new ArgumentNullException("args");
    }

    // If the CriticalFiles object was deleted from the farm after it was
    // backed up, restore it to the configuration database.
    CriticalFiles cf = SPFarm.Local.GetChild<CriticalFiles>(this.Name);
    if (cf == null)
    {
        this.Update();
        args.Log(SPBackupRestoreLogSeverity.Verbose, this.Name + " added back to configuration database.");
    }

    Boolean successSignal = true;

    // TODO: The following loop restores files to the local server. If there are 
    //       multiple front end servers, your code must iterate through all of 
    //       SPFarm.Local.Servers and restore the same files to every server whose
    //       Role property is SPServerRole.WebFrontEnd

    foreach (String path in FrontEndFilePaths)
    {
        FileInfo backupCopy = new FileInfo(path);
        FileInfo file = new FileInfo(args.Location + @"\" + backupCopy.Name);
        try
        {
            file.CopyTo(path, true);
            args.Log(SPBackupRestoreLogSeverity.Verbose, "Restored " + file.Name);
        }
        catch (Exception e)
        {
            args.Log(SPBackupRestoreLogSeverity.Verbose, file.Name + " not restored: " + e.Message);
            successSignal = false;
        }
    }
    
    args.CurrentProgress = 50;
    return successSignal;
}
Public Function OnRestore(ByVal sender As Object, ByVal args As SPRestoreInformation) As Boolean
    If args Is Nothing Then
        Throw New ArgumentNullException("args")
    End If

    ' If the CriticalFiles object was deleted from the farm after it was
    ' backed up, restore it to the configuration database.
    Dim cf As CriticalFiles = SPFarm.Local.GetChild(Of CriticalFiles)(Me.Name)
    If cf Is Nothing Then
        Me.Update()
        args.Log(SPBackupRestoreLogSeverity.Verbose, Me.Name & " added back to configuration database.")
    End If

    Dim successSignal As Boolean = True

    ' TODO: The following loop restores files to the local server. If there are 
    '       multiple front end servers, your code must iterate through all of 
    '       SPFarm.Local.Servers and restore the same files to every server whose
    '       Role property is SPServerRole.WebFrontEnd

    For Each path As String In FrontEndFilePaths
        Dim backupCopy As New FileInfo(path)
        Dim file As New FileInfo(args.Location & "\" & backupCopy.Name)
        Try
            file.CopyTo(path, True)
            args.Log(SPBackupRestoreLogSeverity.Verbose, "Restored " & file.Name)
        Catch e As Exception
            args.Log(SPBackupRestoreLogSeverity.Verbose, file.Name & " not restored: " & e.Message)
            successSignal = False
        End Try
    Next path

    args.CurrentProgress = 50
    Return successSignal
End Function

Ver também

Referência

IBackupRestore interface

IBackupRestore members

Microsoft.SharePoint.Administration.Backup namespace