< Back

Restore-DbaDbSnapshot

Mon Jan 13, 2020 1:37 pm

NAME Restore-DbaDbSnapshot



SYNOPSIS

Restores databases from snapshots





SYNTAX

Restore-DbaDbSnapshot [[-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

[[-SqlCredential] <Pscredential>] [[-Database] <System.Object[]>] [[-ExcludeDatabase] <System.Object[]>]

[[-Snapshot] <System.Object[]>] [[-InputObject] <Microsoft.SqlServer.Management.Smo.Database[]>] [-Force <Switch>]

[-EnableException <Switch>] [<CommonParameters>]





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





PARAMETERS

-Database [<System.Object[]>]

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



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



-ExcludeDatabase [<System.Object[]>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Force [<Switch>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-InputObject [<Microsoft.SqlServer.Management.Smo.Database[]>]

Allows piping from other Snapshot commands



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Snapshot [<System.Object[]>]

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



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 [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

The target SQL Server instance or instances



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: Snapshot, Backup, Restore, Database

Author: Simone Bizzotto (@niphold)



Website: https://dbatools.io

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

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



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



RELATED LINKS

https://dbatools.io/Restore-DbaDbSnapshot