Backup‑SqlDscDatabase - dsccommunity/SqlServerDsc GitHub Wiki
Performs a backup of a SQL Server database.
Backup-SqlDscDatabase -ServerObject <Server> -Name <String> -BackupFile <String> [-BackupType <String>]
[-CopyOnly] [-Compress] [-Checksum] [-Description <String>] [-RetainDays <Int32>] [-Initialize] [-Refresh]
[-Force] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]
Backup-SqlDscDatabase -DatabaseObject <Database> -BackupFile <String> [-BackupType <String>] [-CopyOnly]
[-Compress] [-Checksum] [-Description <String>] [-RetainDays <Int32>] [-Initialize] [-Force] [-PassThru]
[-WhatIf] [-Confirm] [<CommonParameters>]
This command performs a backup of a SQL Server database using SQL Server Management Objects (SMO). It supports full, differential, and transaction log backups with options for compression, verification, and copy-only backups.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Backup-SqlDscDatabase -Name 'MyDatabase' -BackupFile 'C:\Backups\MyDatabase.bak'
Performs a full backup of the database named MyDatabase to the specified backup file.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$databaseObject = $serverObject | Get-SqlDscDatabase -Name 'MyDatabase'
$databaseObject | Backup-SqlDscDatabase -BackupFile 'C:\Backups\MyDatabase.bak' -Force
Performs a full backup of the database named MyDatabase using a database object from the pipeline, without prompting for confirmation.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Backup-SqlDscDatabase -Name 'MyDatabase' -BackupFile 'C:\Backups\MyDatabase_Diff.bak' -BackupType 'Differential'
Performs a differential backup of the database named MyDatabase.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Backup-SqlDscDatabase -Name 'MyDatabase' -BackupFile 'C:\Backups\MyDatabase.trn' -BackupType 'Log'
Performs a transaction log backup of the database named MyDatabase.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Backup-SqlDscDatabase -Name 'MyDatabase' -BackupFile 'C:\Backups\MyDatabase_CopyOnly.bak' -CopyOnly
Performs a copy-only full backup of the database named MyDatabase. This backup does not affect the normal backup chain.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Backup-SqlDscDatabase -Name 'MyDatabase' -BackupFile 'C:\Backups\MyDatabase.bak' -Compress -Checksum
Performs a compressed full backup with checksum verification of the database named MyDatabase.
$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$databaseObject = $serverObject | Backup-SqlDscDatabase -Name 'MyDatabase' -BackupFile 'C:\Backups\MyDatabase.bak' -PassThru -Force
$databaseObject | Set-SqlDscDatabaseProperty -RecoveryModel 'Simple' -Force
Performs a full backup of the database named MyDatabase and returns the database object for further pipeline operations.
Specifies the full path to the backup file.
For full and differential
backups, use the .bak extension.
For transaction log backups, use
the .trn extension.
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the type of backup to perform. Valid values are 'Full', 'Differential', and 'Log'. Default value is 'Full'.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: Full
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies that checksums should be calculated and verified during the backup operation to help detect backup media errors.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies that the backup should be compressed. Backup compression requires SQL Server 2008 Enterprise or later, or SQL Server 2008 R2 Standard or later.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies that a copy-only backup should be performed. Copy-only backups do not affect the sequence of conventional backups and are useful for taking backups for special purposes without disrupting the normal backup chain. This is particularly useful in AlwaysOn Availability Group scenarios.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies a database object to backup.
Type: Database
Parameter Sets: DatabaseObject
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalseSpecifies a description for the backup set. This description is stored in the backup media and can be useful for identifying backups.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies that the backup should be performed without any confirmation.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies that the backup media should be initialized (overwritten) rather than appending to existing backup sets. Use with caution as this will destroy any existing backups on the media.
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 to backup.
Type: String
Parameter Sets: ServerObject
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseReturns the database object that was backed up. By default, this command does not generate any output.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies that the ServerObject's databases should be refreshed before accessing the database. 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, or pass in DatabaseObject.
Type: SwitchParameter
Parameter Sets: ServerObject
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the number of days that must elapse before the backup media can be overwritten. This provides protection against accidental overwrites.
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: FalseSpecifies the current server connection object.
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.