New‑SqlDscDatabaseSnapshot - dsccommunity/SqlServerDsc GitHub Wiki
Creates a new database snapshot in a SQL Server Database Engine instance.
New-SqlDscDatabaseSnapshot -ServerObject <Server> -Name <String> -DatabaseName <String>
[-FileGroup <DatabaseFileGroupSpec[]>] [-Force] [-Refresh] [-WhatIf]
[-Confirm] [<CommonParameters>]
New-SqlDscDatabaseSnapshot -DatabaseObject <Database> -Name <String> [-FileGroup <DatabaseFileGroupSpec[]>]
[-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
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.
$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.
$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.
$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.
$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.
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: FalseSpecifies 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: FalseSpecifies 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: FalseSpecifies 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: FalseSpecifies 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: FalseSpecifies 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: FalseSpecifies 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: FalsePrompts 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: FalseShows 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: FalseThis cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
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.