commands

^

Format-DbaBackupInformation

Author Stuart Moore (@napalmgram), stuart-moore.com
Availability Windows, Linux, macOS

 

Synopsis

Transforms the data in a dbatools BackupHistory object for a restore

Description

Performs various mapping on Backup History, ready restoring Options include changing restore paths, backup paths, database name and many others

Syntax

Format-DbaBackupInformation
    [-BackupHistory] <Object[]>
    [[-ReplaceDatabaseName] <Object>]
    [-ReplaceDbNameInFile]
    [[-DataFileDirectory] <String>]
    [[-LogFileDirectory] <String>]
    [[-DestinationFileStreamDirectory] <String>]
    [[-DatabaseNamePrefix] <String>]
    [[-DatabaseFilePrefix] <String>]
    [[-DatabaseFileSuffix] <String>]
    [[-RebaseBackupFolder] <String>]
    [-Continue]
    [[-FileMapping] <Hashtable>]
    [[-PathSep] <String>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> $History | Format-DbaBackupInformation -ReplaceDatabaseName NewDb

Changes as database name references to NewDb, both in the database name and any restore paths. Note, this will fail if the BackupHistory object contains backups for more than 1 database

Example: 2
PS C:\> $History | Format-DbaBackupInformation -ReplaceDatabaseName @{'OldB'='NewDb';'ProdHr'='DevHr'}

Will change all occurrences of original database name in the backup history (names and restore paths) using the mapping in the hashtable.
In this example any occurrence of OldDb will be replaced with NewDb and ProdHr with DevPR

Example: 3
PS C:\> $History | Format-DbaBackupInformation -DataFileDirectory 'D:\DataFiles\' -LogFileDirectory 'E:\LogFiles\

This example with change the restore path for all data files (everything that is not a log file) to d:\datafiles
And all Transaction Log files will be restored to E:\Logfiles

Example: 4
PS C:\> $History | Format-DbaBackupInformation -RebaseBackupFolder f:\backups

This example changes the location that SQL Server will look for the backups. This is useful if you've moved the backups to a different location

Required Parameters

-BackupHistory

A dbatools backupHistory object, normally this will have been created using Select-DbaBackupInformation

Alias
Required True
Pipeline true (ByValue)
Default Value

Optional Parameters

-ReplaceDatabaseName

If a single value is provided, this will be replaced do all occurrences a database name If a Hashtable is passed in, each database name mention will be replaced as specified. If a database's name does not appear it will not be replace DatabaseName will also be replaced where it occurs in the file paths of data and log files. Please note, that this won't change the Logical Names of data files, that has to be done with a separate Alter DB call

Alias
Required False
Pipeline false
Default Value
-ReplaceDbNameInFile

If set, will replace the old database name with the new name if it occurs in the file name

Alias
Required False
Pipeline false
Default Value False
-DataFileDirectory

This will move ALL restored files to this location during the restore

Alias
Required False
Pipeline false
Default Value
-LogFileDirectory

This will move all log files to this location, overriding DataFileDirectory

Alias
Required False
Pipeline false
Default Value
-DestinationFileStreamDirectory

This move the FileStream folder and contents to the new location, overriding DataFileDirectory

Alias
Required False
Pipeline false
Default Value
-DatabaseNamePrefix

This string will be prefixed to all restored database's name

Alias
Required False
Pipeline false
Default Value
-DatabaseFilePrefix

A string that will be prefixed to every file restored

Alias
Required False
Pipeline false
Default Value
-DatabaseFileSuffix

A string that will be suffixed to every file restored

Alias
Required False
Pipeline false
Default Value
-RebaseBackupFolder

Use this to rebase where your backups are stored.

Alias
Required False
Pipeline false
Default Value
-Continue

Indicates that this is a continuing restore

Alias
Required False
Pipeline false
Default Value False
-FileMapping

A hashtable that can be used to move specific files to a location. $FileMapping = @{'DataFile1'='c:\restoredfiles\Datafile1.mdf';'DataFile3'='d:\DataFile3.mdf'} And files not specified in the mapping will be restored to their original location This Parameter is exclusive with DestinationDataDirectory If specified, this will override any other file renaming/relocation options.

Alias
Required False
Pipeline false
Default Value
-PathSep

By default is Windows's style (\) but you can pass also, e.g., / for Unix's style paths

Alias
Required False
Pipeline false
Default Value \
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message. This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting. Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False

 

Want to see the source code for this command? Check out Format-DbaBackupInformation on GitHub.
Want to see the Bill Of Health for this command? Check out Format-DbaBackupInformation.