< Back

Get-DbaBackupInformation

Mon Jan 13, 2020 10:24 am

NAME Get-DbaBackupInformation



SYNOPSIS

Scan backup files and creates a set, compatible with Restore-DbaDatabase





SYNTAX

Get-DbaBackupInformation -Path <System.Object[]> -SqlInstance <DbaInstanceParameter> [-SqlCredential

<Pscredential>] [-DatabaseName <System.String[]>] [-SourceInstance <System.String[]>] [-NoXpDirTree <Switch>]

[-DirectoryRecurse <Switch>] [-EnableException <Switch>] [-MaintenanceSolution <Switch>] [-IgnoreLogBackup

<Switch>] [-ExportPath <String>] [-AzureCredential <String>] [-Anonymise <Switch>] [-NoClobber <Switch>]

[-PassThru <Switch>] [<CommonParameters>]



Get-DbaBackupInformation -Path <System.Object[]> [-DatabaseName <System.String[]>] [-SourceInstance

<System.String[]>] [-EnableException <Switch>] [-MaintenanceSolution <Switch>] [-IgnoreLogBackup <Switch>]

[-ExportPath <String>] [-AzureCredential <String>] [-Import <Switch>] [-Anonymise <Switch>] [-NoClobber <Switch>]

[-PassThru <Switch>] [<CommonParameters>]





DESCRIPTION

Upon being passed a list of potential backups files this command will scan the files, select those that contain

SQL Server



backup sets. It will then filter those files down to a set



The function defaults to working on a remote instance. This means that all paths passed in must be relative to the

remote instance.



XpDirTree will be used to perform the file scans



Various means can be used to pass in a list of files to be considered. The default is to non recursively scan the

folder



passed in.





PARAMETERS

-Anonymise [<Switch>]

If specified we will output the results with ComputerName, InstanceName, Database, UserName, Paths, and

Logical and Physical Names hashed out

This options is mainly for use if we need you to submit details for fault finding to the dbatools team



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-AzureCredential [<String>]

The name of the SQL Server credential to be used if restoring from an Azure hosted backup



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-DatabaseName [<System.String[]>]

An array of Database Names to filter by. If empty all databases are returned.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-DirectoryRecurse [<Switch>]

If specified the provided path/directory will be traversed (only applies if not using XpDirTree)



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

Replaces user friendly yellow warnings with bloody red exceptions of doom!

Use this if you want the function to throw terminating errors you want to catch.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ExportPath [<String>]

If specified the output will export via CliXml format to the specified file. This allows you to store the

backup history object for later usage, or move it between computers



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-IgnoreLogBackup [<Switch>]

This switch only works with the MaintenanceSolution switch. With an Ola Hallengren style backup we can be sure

that the LOG folder contains only log backups and skip it.

For all other scenarios we need to read the file headers to be sure.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Import [<Switch>]

When specified along with a path the command will import a previously exported BackupHistory object from an

xml file.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-MaintenanceSolution [<Switch>]

This switch tells the function that the folder is the root of a Ola Hallengren backup folder



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-NoClobber [<Switch>]

If specified will stop Export from overwriting an existing file, the default is to overwrite



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-NoXpDirTree [<Switch>]

If this switch is set, then Files will be parsed as locally files. This can cause failures if the running user

can see files that the parsing SQL Instance cannot



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-PassThru [<Switch>]

When data is exported the cmdlet will return no other output, this switch means it will also return the normal

output which can be then piped into another command



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Path [<System.Object[]>]

Path to SQL Server backup files.



Paths passed in as strings will be scanned using the desired method, default is a non recursive folder scan

Accepts multiple paths separated by ','



Or it can consist of FileInfo objects, such as the output of Get-ChildItem or Get-Item. This allows you to

work with

your own file structures as needed



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SourceInstance [<System.String[]>]

If provided only backup originating from this destination will be returned. This SQL instance will not be

connected to or involved in this work



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).



Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory -

Integrated are all supported.



For MFA support, please use Connect-DbaInstance.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlInstance [<DbaInstanceParameter>]

The SQL Server instance to be used to read the headers of the backup files



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: Chrissy LeMaire (@cl) | Stuart Moore (@napalmgram)



Website: https://dbatools.io

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

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



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Get-DbaBackupInformation -SqlInstance Server1 -Path c:\\backups\\ -DirectoryRecurse



Will use the Server1 instance to recursively read all backup files under c:\\backups, and return a dbatools

BackupHistory object

-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Get-DbaBackupInformation -SqlInstance Server1 -Path c:\\backups\\ -DirectoryRecurse -ExportPath

c:\\store\\BackupHistory.xml



PS C:\\> robocopy c:\\store\\ \\\\remoteMachine\\C$\\store\\ BackupHistory.xml

PS C:\\> Get-DbaBackupInformation -Import -Path c:\\store\\BackupHistory.xml | Restore-DbaDatabase -SqlInstance

Server2 -TrustDbBackupHistory



This example creates backup history output from server1 and copies the file to the remote machine in order to

preserve backup history. It is then used to restore the databases onto server2.

-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Get-DbaBackupInformation -SqlInstance Server1 -Path c:\\backups\\ -DirectoryRecurse -ExportPath

C:\\store\\BackupHistory.xml -PassThru | Restore-DbaDatabase -SqlInstance Server2 -TrustDbBackupHistory



In this example we gather backup information, export it to an xml file, and then pass it on through to

Restore-DbaDatabase.

This allows us to repeat the restore without having to scan all the backup files again

-------------------------- EXAMPLE 4 --------------------------



PS C:\\>Get-ChildItem c:\\backups\\ -recurse -files | Where-Object {$_.extension -in ('.bak','.trn') -and

$_.LastWriteTime -gt (get-date).AddMonths(-1)} | Get-DbaBackupInformation -SqlInstance Server1 -ExportPath

C:\\backupHistory.xml



This lets you keep a record of all backup history from the last month on hand to speed up refreshes

-------------------------- EXAMPLE 5 --------------------------



PS C:\\>$Backups = Get-DbaBackupInformation -SqlInstance Server1 -Path \\\\network\\backups



PS C:\\> $Backups += Get-DbaBackupInformation -SqlInstance Server2 -NoXpDirTree -Path c:\\backups



Scan the unc folder \\\\network\\backups with Server1, and then scan the C:\\backups folder on

Server2 not using xp_dirtree, adding the results to the first set.

-------------------------- EXAMPLE 6 --------------------------



PS C:\\>$Backups = Get-DbaBackupInformation -SqlInstance Server1 -Path \\\\network\\backups -MaintenanceSolution



When MaintenanceSolution is indicated we know we are dealing with the output from Ola Hallengren backup scripts.

So we make sure that a FULL folder exists in the first level of Path, if not we shortcut scanning all the files as

we have nothing to work with

-------------------------- EXAMPLE 7 --------------------------



PS C:\\>$Backups = Get-DbaBackupInformation -SqlInstance Server1 -Path \\\\network\\backups -MaintenanceSolution

-IgnoreLogBackup



As we know we are dealing with an Ola Hallengren style backup folder from the MaintenanceSolution switch, when

IgnoreLogBackup is also included we can ignore the LOG folder to skip any scanning of log backups. Note this also

means they WON'T be restored



RELATED LINKS

https://dbatools.io/Get-DbaBackupInformation