New‑SqlDscDatabaseSnapshot - dsccommunity/SqlServerDsc GitHub Wiki

SYNOPSIS

Creates a new database snapshot in a SQL Server Database Engine instance.

SYNTAX

ServerObject

New-SqlDscDatabaseSnapshot -ServerObject <Server> -Name <String> -DatabaseName <String>
 [-FileGroup <DatabaseFileGroupSpec[]>] [-Force] [-Refresh] [-WhatIf]
 [-Confirm] [<CommonParameters>]

DatabaseObject

New-SqlDscDatabaseSnapshot -DatabaseObject <Database> -Name <String> [-FileGroup <DatabaseFileGroupSpec[]>]
 [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]

DESCRIPTION

This command creates a new database snapshot in a SQL Server Database Engine instance using SMO. It provides an automated and DSC-friendly approach to snapshot management by leveraging the existing New-SqlDscDatabase command for the actual creation.

EXAMPLES

EXAMPLE 1

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | New-SqlDscDatabaseSnapshot -Name 'MyDatabase_Snapshot' -DatabaseName 'MyDatabase'

Creates a new database snapshot named MyDatabase_Snapshot from the source database MyDatabase.

EXAMPLE 2

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$databaseObject = $serverObject | Get-SqlDscDatabase -Name 'MyDatabase'
$databaseObject | New-SqlDscDatabaseSnapshot -Name 'MyDatabase_Snapshot' -Force

Creates a new database snapshot named MyDatabase_Snapshot from the database object MyDatabase without prompting for confirmation.

EXAMPLE 3

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | New-SqlDscDatabaseSnapshot -Name 'MyDB_Snap' -DatabaseName 'MyDatabase' -Force

Creates a new database snapshot named MyDB_Snap from the source database MyDatabase without prompting for confirmation.

EXAMPLE 4

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$sourceDb = $serverObject.Databases['MyDatabase']

$dataFile = New-SqlDscDataFile -Name 'MyDatabase_Data' -FileName 'C:\Snapshots\MyDatabase_Data.ss' -AsSpec $fileGroup = New-SqlDscFileGroup -Name 'PRIMARY' -Files @($dataFile) -AsSpec

$serverObject | New-SqlDscDatabaseSnapshot -Name 'MyDB_Snap' -DatabaseName 'MyDatabase' -FileGroup @($fileGroup) -Force

Creates a new database snapshot named MyDB_Snap from the source database MyDatabase with a specified sparse file location without prompting for confirmation.

PARAMETERS

-DatabaseName

Specifies the name of the source database from which to create a snapshot. This parameter is used in the ServerObject parameter set.

Type: String
Parameter Sets: ServerObject
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-DatabaseObject

Specifies the source database object to snapshot. This parameter can be provided via pipeline and is used in the DatabaseObject parameter set.

Type: Database
Parameter Sets: DatabaseObject
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-FileGroup

Specifies an array of DatabaseFileGroupSpec objects that define the file groups and data files for the database snapshot. Each DatabaseFileGroupSpec contains the file group name and an array of DatabaseFileSpec objects for the sparse files. When not specified, the cmdlet automatically generates DatabaseFileGroupSpec and DatabaseFileSpec entries based on the source database's file structure, resulting in sparse files being created in the default data directory with automatically generated names.

Type: DatabaseFileGroupSpec[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Force

Specifies that the snapshot should be created without any confirmation.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Name

Specifies the name of the database snapshot to be created.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Refresh

Specifies that the ServerObject's databases should be refreshed before creating the snapshot. This is helpful when databases could have been modified outside of the ServerObject, for example through T-SQL. But on instances with a large amount of databases it might be better to make sure the ServerObject is recent enough.

Type: SwitchParameter
Parameter Sets: ServerObject
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-ServerObject

Specifies the current server connection object. This parameter is used in the ServerObject parameter set.

Type: Server
Parameter Sets: ServerObject
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-WhatIf

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

Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

[Microsoft.SqlServer.Management.Smo.Server]

Specifies the SQL Server connection object to create the snapshot in.

[Microsoft.SqlServer.Management.Smo.Database]

Specifies the source database object to create a snapshot from.

OUTPUTS

[Microsoft.SqlServer.Management.Smo.Database]

Returns the newly created database snapshot object.

NOTES

This command is for snapshot creation only and does not support modification of existing snapshots.

Database snapshots are only supported in certain SQL Server editions (Enterprise, Developer, and Evaluation editions). The command will validate edition support before attempting to create the snapshot.

RELATED LINKS

⚠️ **GitHub.com Fallback** ⚠️