Skip to content

Invoke-BackupSQLDB

SYNOPSIS

Backup a SQL Server database to a specified location.

SYNTAX

Invoke-BackupSQLDB [-Source] <String> [-Target] <String> [[-enddate] <String>] [<CommonParameters>]

DESCRIPTION

This function performs a backup of a SQL Server database to a specified UNC path. If the specified path does not exist, the backup will be placed in the default backup directory of the SQL Server instance. It supports optional decryption of encrypted databases and handles backup file naming based on an optional end date.

EXAMPLES

EXAMPLE 1

Invoke-BackupSQLDB -Source "TestDB - SQLSource" -Target "\\server\backups"

Backs up the "TestDB" database from "SQLSource" to the specified UNC path.

EXAMPLE 2

Invoke-BackupSQLDB -Source "TestDB - SQLSource" -Target "Default"

Backs up the "TestDB" database from "SQLSource" to the default backup directory of the SQL Server instance.

EXAMPLE 3

Invoke-BackupSQLDB -Source "TestDB - SQLSource" -Target "\\server\backups" -EndDate "2025-04-01"

Backs up the "TestDB" database from "SQLSource" to the specified UNC path with the end date appended to the backup file name.

PARAMETERS

-Source

The name of the database and SQL Server in the format: `%databasename% - %databaseserver%`.

Type: String
Parameter Sets: (All)
Aliases:

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

-Target

The UNC path (directory) where the backup should be created. If "Default" is specified, the default backup directory of the SQL Server instance will be used.

Type: String
Parameter Sets: (All)
Aliases:

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

-enddate

Optional parameter to append a specific end date to the backup file name.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
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

OUTPUTS

NOTES