commands

^

Restore-DbaDbSnapshot

Author Simone Bizzotto (@niphold)
Availability Windows, Linux, macOS

 

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

Synopsis

Restores databases from snapshots

Description

Restores the database from the snapshot, discarding every modification made to the database NB: Restoring to a snapshot will result in every other snapshot of the same database to be dropped It also fixes some long-standing bugs in SQL Server when restoring from snapshots

Syntax

Restore-DbaDbSnapshot
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-Database] <Object[]>]
    [[-ExcludeDatabase] <Object[]>]
    [[-Snapshot] <Object[]>]
    [[-InputObject] <Database[]>]
    [-Force]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Restore-DbaDbSnapshot -SqlInstance sql2014 -Database HR, Accounting

Restores HR and Accounting databases using the latest snapshot available

Example: 2
PS C:\> Restore-DbaDbSnapshot -SqlInstance sql2014 -Database HR -Force

Restores HR database from latest snapshot and kills any active connections in the database on sql2014.

Example: 3
PS C:\> Get-DbaDbSnapshot -SqlInstance sql2016 -Database HR | Restore-DbaDbSnapshot -Force

Restores HR database from latest snapshot and kills any active connections in the database on sql2016.

Example: 4
PS C:\> Get-DbaDbSnapshot -SqlInstance sql2016 | Out-GridView -PassThru | Restore-DbaDbSnapshot

Allows the selection of snapshots on sql2016 to restore

Example: 5
PS C:\> Restore-DbaDbSnapshot -SqlInstance sql2014 -Snapshot HR_snap_20161201, Accounting_snap_20161101

Restores databases from snapshots named HR_snap_20161201 and Accounting_snap_20161101

Optional Parameters

-SqlInstance

The target SQL Server instance or instances

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

Restores from the last snapshot databases with this names only. You can pass either Databases or Snapshots

Alias
Required False
Pipeline false
Default Value
-ExcludeDatabase

The database(s) to exclude - this list is auto-populated from the server

Alias
Required False
Pipeline false
Default Value
-Snapshot

Restores databases from snapshots with this names only. You can pass either Databases or Snapshots

Alias
Required False
Pipeline false
Default Value
-InputObject

Allows piping from other Snapshot commands

Alias
Required False
Pipeline true (ByValue)
Default Value
-Force

If restoring from a snapshot involves dropping any other snapshot, you need to explicitly use -Force to let this command delete the ones not involved in the restore process. Also, -Force will forcibly kill all running queries that prevent the restore process.

Alias
Required False
Pipeline false
Default Value False
-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
-WhatIf

Shows what would happen if the command were to run

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts for confirmation of every step.

Alias cf
Required False
Pipeline false
Default Value