commands

^

Invoke-DbaAdvancedRestore

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

 

Synopsis

Allows the restore of modified BackupHistory Objects For 90% of users Restore-DbaDatabase should be your point of access to this function. The other 10% use it at their own risk

Description

This is the final piece in the Restore-DbaDatabase Stack. Usually a BackupHistory object will arrive here from Restore-DbaDatabase via the following pipeline: Get-DbaBackupInformation | Select-DbaBackupInformation | Format-DbaBackupInformation | Test-DbaBackupInformation | Invoke-DbaAdvancedRestore

We have exposed these functions publicly to allow advanced users to perform operations that we don't support, or won't add as they would make things too complex for the majority of our users

For example if you wanted to do some very complex redirection during a migration, then doing the rewrite of destinations may be better done with your own custom scripts rather than via Format-DbaBackupInformation

We would recommend ALWAYS pushing your input through Test-DbaBackupInformation just to make sure that it makes sense to us.

Syntax

Invoke-DbaAdvancedRestore
    [-BackupHistory] <Object[]>
    [[-SqlInstance] <DbaInstanceParameter>]
    [[-SqlCredential] <PSCredential>]
    [-OutputScriptOnly]
    [-VerifyOnly]
    [[-RestoreTime] <DateTime>]
    [[-StandbyDirectory] <String>]
    [-NoRecovery]
    [[-MaxTransferSize] <Int32>]
    [[-BlockSize] <Int32>]
    [[-BufferCount] <Int32>]
    [-Continue]
    [[-AzureCredential] <String>]
    [-WithReplace]
    [-KeepReplication]
    [-KeepCDC]
    [[-PageRestore] <Object[]>]
    [[-ExecuteAs] <String>]
    [-StopBefore]
    [[-StopMark] <String>]
    [[-StopAfterDate] <DateTime>]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> $BackupHistory | Invoke-DbaAdvancedRestore -SqlInstance MyInstance

Will restore all the backups in the BackupHistory object according to the transformations it contains

Example: 2
PS C:\> $BackupHistory | Invoke-DbaAdvancedRestore -SqlInstance MyInstance -OutputScriptOnly
PS C:\> $BackupHistory | Invoke-DbaAdvancedRestore -SqlInstance MyInstance

First generates just the T-SQL restore scripts so they can be sanity checked, and then if they are good perform the full restore.
By reusing the BackupHistory object there is no need to rescan all the backup files again

Required Parameters

-BackupHistory

The BackupHistory object to be restored. Can be passed in on the pipeline

Alias
Required True
Pipeline true (ByValue)
Default Value

Optional Parameters

-SqlInstance

The SqlInstance to which the backups should be restored

Alias
Required False
Pipeline false
Default Value
-SqlCredential

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.

Alias
Required False
Pipeline false
Default Value
-OutputScriptOnly

If set, the restore will not be performed, but the T-SQL scripts to perform it will be returned

Alias
Required False
Pipeline false
Default Value False
-VerifyOnly

If set, performs a Verify of the backups rather than a full restore

Alias
Required False
Pipeline false
Default Value False
-RestoreTime

Point in Time to which the database should be restored. This should be the same value or earlier, as used in the previous pipeline stages

Alias
Required False
Pipeline false
Default Value (Get-Date).AddDays(2)
-StandbyDirectory

A folder path where a standby file should be created to put the recovered databases in a standby mode

Alias
Required False
Pipeline false
Default Value
-NoRecovery

Leave the database in a restoring state so that further restore may be made

Alias
Required False
Pipeline false
Default Value False
-MaxTransferSize

Parameter to set the unit of transfer. Values must be a multiple by 64kb

Alias
Required False
Pipeline false
Default Value 0
-BlockSize

Specifies the block size to use. Must be one of 0.5kb,1kb,2kb,4kb,8kb,16kb,32kb or 64kb Can be specified in bytes Refer to https://msdn.microsoft.com/en-us/library/ms178615.aspx for more detail

Alias
Required False
Pipeline false
Default Value 0
-BufferCount

Number of I/O buffers to use to perform the operation. Refer to https://msdn.microsoft.com/en-us/library/ms178615.aspx for more detail

Alias
Required False
Pipeline false
Default Value 0
-Continue

Indicates that the restore is continuing a restore, so target database must be in Recovering or Standby states When specified, WithReplace will be set to true

Alias
Required False
Pipeline false
Default Value False
-AzureCredential

AzureCredential required to connect to blob storage holding the backups

Alias
Required False
Pipeline false
Default Value
-WithReplace

Indicated that if the database already exists it should be replaced

Alias
Required False
Pipeline false
Default Value False
-KeepReplication

Indicates whether replication configuration should be restored as part of the database restore operation

Alias
Required False
Pipeline false
Default Value False
-KeepCDC

Indicates whether CDC information should be restored as part of the database

Alias
Required False
Pipeline false
Default Value False
-PageRestore

The output from Get-DbaSuspect page containing the suspect pages to be restored.

Alias
Required False
Pipeline false
Default Value
-ExecuteAs

If set, this will cause the database(s) to be restored (and therefore owned) as the SA user

Alias
Required False
Pipeline false
Default Value
-StopBefore

Switch to indicate the restore should stop before StopMark

Alias
Required False
Pipeline false
Default Value False
-StopMark

Mark in the transaction log to stop the restore at

Alias
Required False
Pipeline false
Default Value
-StopAfterDate

By default the restore will stop at the first occurence of StopMark found in the chain, passing a datetime where will cause it to stop the first StopMark atfer that datetime

Alias
Required False
Pipeline false
Default Value
-EnableException

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.

Alias
Required False
Pipeline false
Default Value False
-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts you for confirmation before running the cmdlet.

Alias cf
Required False
Pipeline false
Default Value

 

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