< Back

Format-DbaBackupInformation

Mon Jan 13, 2020 10:14 am

NAME Format-DbaBackupInformation



SYNOPSIS

Transforms the data in a dbatools BackupHistory object for a restore





SYNTAX

Format-DbaBackupInformation [-BackupHistory] <System.Object[]> [[-ReplaceDatabaseName] <System.Object>]

[-ReplaceDbNameInFile <Switch>] [[-DataFileDirectory] <String>] [[-LogFileDirectory] <String>]

[[-DestinationFileStreamDirectory] <String>] [[-DatabaseNamePrefix] <String>] [[-DatabaseFilePrefix] <String>]

[[-DatabaseFileSuffix] <String>] [[-RebaseBackupFolder] <String>] [-Continue <Switch>] [[-FileMapping]

<Hashtable>] [[-PathSep] <String>] [-EnableException <Switch>] [<CommonParameters>]





DESCRIPTION

Performs various mapping on Backup History, ready restoring



Options include changing restore paths, backup paths, database name and many others





PARAMETERS

-BackupHistory [<System.Object[]>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Continue [<Switch>]

Indicates that this is a continuing restore



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-DatabaseFilePrefix [<String>]

A string that will be prefixed to every file restored



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-DatabaseFileSuffix [<String>]

A string that will be suffixed to every file restored



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-DatabaseNamePrefix [<String>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-DataFileDirectory [<String>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-DestinationFileStreamDirectory [<String>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-FileMapping [<Hashtable>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-LogFileDirectory [<String>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-PathSep [<String>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-RebaseBackupFolder [<String>]

Use this to rebase where your backups are stored.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ReplaceDatabaseName [<System.Object>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ReplaceDbNameInFile [<Switch>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: DisasterRecovery, Backup, Restore

Author: Stuart Moore (@napalmgram), stuart-moore.com



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



-------------------------- 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



RELATED LINKS

https://dbatools.io/Format-DbaBackupInformation