Compartilhar via


SPBackupRestoreInformation.ReverseFileMapping method

Obtém o nome do arquivo de backup que contém o arquivo especificado.

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

Syntax

'Declaração
Public Function ReverseFileMapping ( _
    name As String _
) As String
'Uso
Dim instance As SPBackupRestoreInformation
Dim name As String
Dim returnValue As String

returnValue = instance.ReverseFileMapping(name)
public string ReverseFileMapping(
    string name
)

Parâmetros

  • name
    Type: System.String

    O nome de um arquivo de fonte que está contido em um arquivo de backup.

Valor retornado

Type: System.String
Um String que representa o nome do arquivo de backup que contém a cópia do name.

Comentários

Este método é usado para localizar o nome do arquivo de backup exclusivo que foi atribuído ao arquivo identificado pelo parâmetro name pelo método GenerateFileMapping . Normalmente, ela é chamada em implementações do OnRestore(). Veja o exemplo abaixo.

O formato do valor de retorno é hex. bak, onde hex é um número hexadecimal de oito dígitos; Por exemplo, "00000001.bak" ou 0000000A.bak".

O parâmetro name é também uma chave em um armazenamento interno de pares chave-valor e a cadeia de caracteres retornada por GenerateFileMapping é o valor da chave. Esse par chave-valor foi criado por GenerateFileMapping e armazenado no arquivo spbackup.xml na pasta Location .

Dica

Embora GenerateFileMapping e ReverseFileMapping retornam exatamente o mesmo valor em resposta a mesma entrada, eles estão fazendo coisas diferentes. GenerateFileMapping cria o nome de arquivo exclusivo e grava o par mapeado de nomes de arquivo para o arquivo spbackup.xml . ReverseFileMapping  o mapeamento do arquivo.

Examples

O exemplo a seguir mostra o método ReverseFileMapping usado em uma implementação de OnRestore(). Para o exemplo completo, consulte How to: Create a Content Class That Can Be Backed Up and Restored.

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);
        String mappedFileName = args.ReverseFileMapping(backupCopy.Name);
        FileInfo file = new FileInfo(args.Location + @"\" + mappedFileName);

        try
        {
            file.CopyTo(path, true);
            args.Log(SPBackupRestoreLogSeverity.Verbose, "Restored " + backupCopy.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 mappedFileName As String = args.ReverseFileMapping(backupCopy.Name)
        Dim file As New FileInfo(args.Location & "\" & mappedFileName)

        Try
            file.CopyTo(path, True)
            args.Log(SPBackupRestoreLogSeverity.Verbose, "Restored " & backupCopy.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

SPBackupRestoreInformation class

SPBackupRestoreInformation members

Microsoft.SharePoint.Administration.Backup namespace

GenerateFileMapping