Partilhar via


SPBackupRestoreInformation.ReverseFileMapping Method

Gets the name of the backup file that contains the specified file.

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

Syntax

'Declaration
Public Function ReverseFileMapping ( _
    name As String _
) As String
'Usage
Dim instance As SPBackupRestoreInformation
Dim name As String
Dim returnValue As String

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

Parameters

  • name
    Type: System.String

    The name of a source file that is contained in a backed up file.

Return Value

Type: System.String
A String that represents the name of the backup file that contains the backed up copy of name.

Remarks

This method is used to find the unique backup file name that was assigned to the file identified by the name parameter by the GenerateFileMapping method. It is typically called in implementations of OnRestore(). See the example below.

The format of the return value is hex.bak, where hex is an eight digit hexadecimal number; for example, "00000001.bak" or 0000000A.bak".

The name parameter is also a key in an internal store of key-value pairs and the string returned by GenerateFileMapping is the value of the key. This key-value pair was created by GenerateFileMapping and stored in the spbackup.xml file in the Location folder.

Note

Although GenerateFileMapping and ReverseFileMapping return exactly the same value in response to the same input, they are doing different things. GenerateFileMapping creates the unique file name and writes the mapped pair of file names to the spbackup.xml file. ReverseFileMapping reads the mapping in that file.

Examples

The following example shows the ReverseFileMapping method used in an implementation of OnRestore(). For the full example, see 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

See Also

Reference

SPBackupRestoreInformation Class

SPBackupRestoreInformation Members

Microsoft.SharePoint.Administration.Backup Namespace

GenerateFileMapping