< Back
New-DbaDbSnapshot
Post
NAME New-DbaDbSnapshot
SYNOPSIS
Creates database snapshots
SYNTAX
New-DbaDbSnapshot [[-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>] [[-SqlCredential]
<Pscredential>] [[-Database] <System.Object[]>] [[-ExcludeDatabase] <System.Object[]>] [-AllDatabases <Switch>]
[[-Name] <String>] [[-NameSuffix] <String>] [[-Path] <String>] [-Force <Switch>] [[-InputObject]
<Microsoft.SqlServer.Management.Smo.Database[]>] [-EnableException <Switch>] [<CommonParameters>]
DESCRIPTION
Creates database snapshots without hassles
PARAMETERS
-AllDatabases [<Switch>]
Creates snapshot for all eligible databases
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Database [<System.Object[]>]
The database(s) to process - this list is auto-populated from the server. If unspecified, all databases will
be processed.
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>]
Databases with Filestream FG can be snapshotted, but the Filestream FG is marked offline
in the snapshot. To create a "partial" snapshot, you need to pass -Force explicitely
NB: You can't then restore the Database from the newly-created snapshot.
For details, check https://msdn.microsoft.com/en-us/library/bb895334.aspx
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-InputObject [<Microsoft.SqlServer.Management.Smo.Database[]>]
Allows Piping from Get-DbaDatabase
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Name [<String>]
The specific snapshot name you want to create. Works only if you target a single database. If you need to
create multiple snapshot,
you must use the NameSuffix parameter
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-NameSuffix [<String>]
When you pass a simple string, it'll be appended to use it to build the name of the snapshot. By default
snapshots are created with yyyyMMdd_HHmmss suffix
You can also pass a standard placeholder, in which case it'll be interpolated (e.g. '{0}' gets replaced with
the database name)
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Path [<String>]
Snapshot files will be created here (by default the filestructure will be created in the same folder as the
base db)
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, 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:\\>New-DbaDbSnapshot -SqlInstance sqlserver2014a -Database HR, Accounting
Creates snapshot for HR and Accounting, returning a custom object displaying Server, Database, DatabaseCreated,
SnapshotOf, SizeMB, DatabaseCreated, PrimaryFilePath, Status, Notes
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>New-DbaDbSnapshot -SqlInstance sqlserver2014a -Database HR -Name HR_snap
Creates snapshot named "HR_snap" for HR
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>New-DbaDbSnapshot -SqlInstance sqlserver2014a -Database HR -NameSuffix 'fool_{0}_snap'
Creates snapshot named "fool_HR_snap" for HR
-------------------------- EXAMPLE 4 --------------------------
PS C:\\>New-DbaDbSnapshot -SqlInstance sqlserver2014a -Database HR, Accounting -Path F:\\snapshotpath
Creates snapshots for HR and Accounting databases, storing files under the F:\\snapshotpath\\ dir
-------------------------- EXAMPLE 5 --------------------------
PS C:\\>Get-DbaDatabase -SqlInstance sql2016 -Database df | New-DbaDbSnapshot
Creates a snapshot for the database df on sql2016
RELATED LINKS
https://dbatools.io/New-DbaDbSnapshot
SYNOPSIS
Creates database snapshots
SYNTAX
New-DbaDbSnapshot [[-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>] [[-SqlCredential]
<Pscredential>] [[-Database] <System.Object[]>] [[-ExcludeDatabase] <System.Object[]>] [-AllDatabases <Switch>]
[[-Name] <String>] [[-NameSuffix] <String>] [[-Path] <String>] [-Force <Switch>] [[-InputObject]
<Microsoft.SqlServer.Management.Smo.Database[]>] [-EnableException <Switch>] [<CommonParameters>]
DESCRIPTION
Creates database snapshots without hassles
PARAMETERS
-AllDatabases [<Switch>]
Creates snapshot for all eligible databases
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Database [<System.Object[]>]
The database(s) to process - this list is auto-populated from the server. If unspecified, all databases will
be processed.
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>]
Databases with Filestream FG can be snapshotted, but the Filestream FG is marked offline
in the snapshot. To create a "partial" snapshot, you need to pass -Force explicitely
NB: You can't then restore the Database from the newly-created snapshot.
For details, check https://msdn.microsoft.com/en-us/library/bb895334.aspx
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-InputObject [<Microsoft.SqlServer.Management.Smo.Database[]>]
Allows Piping from Get-DbaDatabase
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Name [<String>]
The specific snapshot name you want to create. Works only if you target a single database. If you need to
create multiple snapshot,
you must use the NameSuffix parameter
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-NameSuffix [<String>]
When you pass a simple string, it'll be appended to use it to build the name of the snapshot. By default
snapshots are created with yyyyMMdd_HHmmss suffix
You can also pass a standard placeholder, in which case it'll be interpolated (e.g. '{0}' gets replaced with
the database name)
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Path [<String>]
Snapshot files will be created here (by default the filestructure will be created in the same folder as the
base db)
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, 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:\\>New-DbaDbSnapshot -SqlInstance sqlserver2014a -Database HR, Accounting
Creates snapshot for HR and Accounting, returning a custom object displaying Server, Database, DatabaseCreated,
SnapshotOf, SizeMB, DatabaseCreated, PrimaryFilePath, Status, Notes
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>New-DbaDbSnapshot -SqlInstance sqlserver2014a -Database HR -Name HR_snap
Creates snapshot named "HR_snap" for HR
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>New-DbaDbSnapshot -SqlInstance sqlserver2014a -Database HR -NameSuffix 'fool_{0}_snap'
Creates snapshot named "fool_HR_snap" for HR
-------------------------- EXAMPLE 4 --------------------------
PS C:\\>New-DbaDbSnapshot -SqlInstance sqlserver2014a -Database HR, Accounting -Path F:\\snapshotpath
Creates snapshots for HR and Accounting databases, storing files under the F:\\snapshotpath\\ dir
-------------------------- EXAMPLE 5 --------------------------
PS C:\\>Get-DbaDatabase -SqlInstance sql2016 -Database df | New-DbaDbSnapshot
Creates a snapshot for the database df on sql2016
RELATED LINKS
https://dbatools.io/New-DbaDbSnapshot