< Back
Backup-DbaDatabase
Post
NAME Backup-DbaDatabase
SYNOPSIS
Backup one or more SQL Sever databases from a single SQL Server SqlInstance.
SYNTAX
Backup-DbaDatabase [-SqlCredential <Pscredential>] [-Database <System.Object[]>] [-ExcludeDatabase
<System.Object[]>] [-Path <System.String[]>] [-FilePath <String>] [-ReplaceInName <Switch>] [-CopyOnly <Switch>]
[-Type <String>] [-CreateFolder <Switch>] [-FileCount <Int>] [-CompressBackup <Switch>] [-Checksum <Switch>]
[-Verify <Switch>] [-MaxTransferSize <Int>] [-BlockSize <Int>] [-BufferCount <Int>] [-AzureBaseUrl
<System.String[]>] [-AzureCredential <String>] [-NoRecovery <Switch>] [-BuildPath <Switch>] [-WithFormat <Switch>]
[-Initialize <Switch>] [-SkipTapeHeader <Switch>] [-TimeStampFormat <String>] [-IgnoreFileChecks <Switch>]
[-OutputScriptOnly <Switch>] [-EncryptionAlgorithm <String>] [-EncryptionCertificate <String>] [-EnableException
<Switch>] [<CommonParameters>]
Backup-DbaDatabase -SqlInstance <DbaInstanceParameter> [-SqlCredential <Pscredential>] [-Database
<System.Object[]>] [-ExcludeDatabase <System.Object[]>] [-Path <System.String[]>] [-FilePath <String>]
[-ReplaceInName <Switch>] [-CopyOnly <Switch>] [-Type <String>] [-CreateFolder <Switch>] [-FileCount <Int>]
[-CompressBackup <Switch>] [-Checksum <Switch>] [-Verify <Switch>] [-MaxTransferSize <Int>] [-BlockSize <Int>]
[-BufferCount <Int>] [-AzureBaseUrl <System.String[]>] [-AzureCredential <String>] [-NoRecovery <Switch>]
[-BuildPath <Switch>] [-WithFormat <Switch>] [-Initialize <Switch>] [-SkipTapeHeader <Switch>] [-TimeStampFormat
<String>] [-IgnoreFileChecks <Switch>] [-OutputScriptOnly <Switch>] [-EncryptionAlgorithm <String>]
[-EncryptionCertificate <String>] [-EnableException <Switch>] [<CommonParameters>]
Backup-DbaDatabase [-SqlCredential <Pscredential>] [-Database <System.Object[]>] [-ExcludeDatabase
<System.Object[]>] [-Path <System.String[]>] [-FilePath <String>] [-ReplaceInName <Switch>] [-CopyOnly <Switch>]
[-Type <String>] -InputObject <System.Object[]> [-CreateFolder <Switch>] [-FileCount <Int>] [-CompressBackup
<Switch>] [-Checksum <Switch>] [-Verify <Switch>] [-MaxTransferSize <Int>] [-BlockSize <Int>] [-BufferCount <Int>]
[-AzureBaseUrl <System.String[]>] [-AzureCredential <String>] [-NoRecovery <Switch>] [-BuildPath <Switch>]
[-WithFormat <Switch>] [-Initialize <Switch>] [-SkipTapeHeader <Switch>] [-TimeStampFormat <String>]
[-IgnoreFileChecks <Switch>] [-OutputScriptOnly <Switch>] [-EncryptionAlgorithm <String>] [-EncryptionCertificate
<String>] [-EnableException <Switch>] [<CommonParameters>]
DESCRIPTION
Performs a backup of a specified type of 1 or more databases on a single SQL Server Instance. These backups may be
Full, Differential or Transaction log backups.
PARAMETERS
-AzureBaseUrl [<System.String[]>]
The URL(s) to the base container of an Azure Storage account to write backups to.
If specifying the AzureCredential parameter you can only provide 1 value as page blobs do not support multiple
URLs
If using Shared Access keys, you may specify as many URLs as you want, as long as a corresponding credential
exists on the source server.
If specified, the only other parameters than can be used are "CopyOnly", "Type", "CompressBackup", "Checksum",
"Verify", "AzureCredential", "CreateFolder".
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-AzureCredential [<String>]
The name of the credential on the SQL instance that can write to the AzureBaseUrl, only needed if using
Storage access keys
If using SAS credentials, the command will look for a credential with a name matching the AzureBaseUrl. As
page blobs are used with this option we force the number of files to 1 and ignore any value passed in for
BlockSize or MaxTransferSize
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-BlockSize [<Int>]
Specifies the block size to use. Must be one of 0.5KB, 1KB, 2KB, 4KB, 8KB, 16KB, 32KB or 64KB. This can be
specified in bytes.
Refer to https://msdn.microsoft.com/en-us/library/ms178615.aspx for more detail
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-BufferCount [<Int>]
Number of I/O buffers to use to perform the operation.
Refer to https://msdn.microsoft.com/en-us/library/ms178615.aspx for more detail
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-BuildPath [<Switch>]
By default this command will not attempt to create missing paths, this switch will change the behaviour so
that it will
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Checksum [<Switch>]
If this switch is enabled, the backup checksum will be calculated.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-CompressBackup [<Switch>]
If this switch is enabled, the function will try to perform a compressed backup if supported by the version
and edition of SQL Server. Otherwise, this function will use the server(s) default setting for compression.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-CopyOnly [<Switch>]
If this switch is enabled, CopyOnly backups will be taken. By default function performs a normal backup, these
backups interfere with the restore chain of the database. CopyOnly backups will not interfere with the restore
chain of the database.
For more details please refer to this MSDN article - https://msdn.microsoft.com/en-us/library/ms191495.aspx
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-CreateFolder [<Switch>]
If this switch is enabled, each database will be backed up into a separate folder on each of the paths
specified by Path.
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
-EncryptionAlgorithm [<String>]
Specified the Encryption Algorithm to used. Must be one of 'AES128','AES192','AES256' or 'TRIPLEDES'
Must specify one of EncryptionCertificate or EncryptionKey as well.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EncryptionCertificate [<String>]
The name of the certificate to be used to encrypt the backups. The existance of the certificate will be
checked, and will not proceed if it does not exist
Is mutually exclusive with the EncryptionKey option
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
-FileCount [<Int>]
This is the number of striped copies of the backups you wish to create. This value is overwritten if you
specify multiple Backup Directories.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-FilePath [<String>]
The name of the file to backup to. This is only accepted for single database backups.
If no name is specified then the backup files will be named DatabaseName_yyyyMMddHHmm (i.e.
"Database1_201714022131") with the appropriate extension.
If the same name is used repeatedly, SQL Server will add backups to the same file at an incrementing position.
SQL Server needs permissions to write to the specified location. Path names are based on the SQL Server (C:\\
is the C drive on the SQL Server, not the machine running the script).
Passing in NUL as the FilePath will backup to the NUL: device
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-IgnoreFileChecks [<Switch>]
This switch stops the function from checking for the validity of paths. This can be useful if SQL Server only
has read access to the backup area.
Note, that as we cannot check the path you may well end up with errors.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Initialize [<Switch>]
Initializes the media as part of the backup operation.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-InputObject [<System.Object[]>]
Internal parameter
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-MaxTransferSize [<Int>]
Sets the size of the unit of transfer. Values must be a multiple of 64kb.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-NoRecovery [<Switch>]
This is passed in to perform a tail log backup if needed
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-OutputScriptOnly [<Switch>]
Switch causes only the T-SQL script for the backup to be generated. Will not create any paths if they do not
exist
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Path [<System.String[]>]
Path in which to place the backup files. If not specified, the backups will be placed in the default backup
location for SqlInstance.
If multiple paths are specified, the backups will be striped across these locations. This will overwrite the
FileCount option.
If the path does not exist, Sql Server will attempt to create it. Folders are created by the Sql Instance, and
checks will be made for write permissions.
File Names with be suffixed with x-of-y to enable identifying striped sets, where y is the number of files in
the set and x ranges from 1 to y.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ReplaceInName [<Switch>]
If this switch is set, the following list of strings will be replaced in the FilePath and Path strings:
instancename - will be replaced with the instance Name
servername - will be replaced with the server name
dbname - will be replaced with the database name
timestamp - will be replaced with the timestamp (either the default, or the format provided)
backuptype - will be replaced with Full, Log or Differential as appropriate
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SkipTapeHeader [<Switch>]
Initializes the media as part of the backup operation.
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 [<DbaInstanceParameter>]
The SQL Server instance hosting the databases to be backed up.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-TimeStampFormat [<String>]
By default the command timestamps backups using the format yyyyMMddHHmm. Using this parameter this can be
overridden. The timestamp format should be defined using the Get-Date formats, illegal formats will cause an
error to be thrown
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Type [<String>]
The type of SQL Server backup to perform. Accepted values are "Full", "Log", "Differential", "Diff", "Database"
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Verify [<Switch>]
If this switch is enabled, the backup will be verified by running a RESTORE VERIFYONLY against the SqlInstance
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-WithFormat [<Switch>]
Formats the media as the first step of the backup operation. NOTE: This will set Initialize and SkipTapeHeader
to $true.
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: DisasterRecovery, Backup, Restore
Author: Stuart Moore (@napalmgram), stuart-moore.com
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance Server1 -Database HR, Finance
This will perform a full database backup on the databases HR and Finance on SQL Server Instance Server1 to Server1
default backup directory.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance sql2016 -Path C:\\temp -Database AdventureWorks2014 -Type Full
Backs up AdventureWorks2014 to sql2016 C:\\temp folder.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance sql2016 -AzureBaseUrl https://dbatoolsaz.blob.core.windows.net/azbackups/
-AzureCredential dbatoolscred -Type Full -CreateFolder
Performs a full backup of all databases on the sql2016 instance to their own containers under the
https://dbatoolsaz.blob.core.windows.net/azbackups/ container on Azure blog storage using the sql credential
"dbatoolscred" registered on the sql2016 instance.
-------------------------- EXAMPLE 4 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance sql2016 -AzureBaseUrl https://dbatoolsaz.blob.core.windows.net/azbackups/
-Type Full
Performs a full backup of all databases on the sql2016 instance to the
https://dbatoolsaz.blob.core.windows.net/azbackups/ container on Azure blog storage using the Shared Access
Signature sql credential "https://dbatoolsaz.blob.core.windows.net/azbackups" registered on the sql2016 instance.
-------------------------- EXAMPLE 5 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance Server1\\Prod -Database db1 -Path
\\\\filestore\\backups\\servername\\instancename\\dbname\\backuptype -Type Full -ReplaceInName
Performs a full backup of db1 into the folder \\\\filestore\\backups\\server1\\prod\\db1
-------------------------- EXAMPLE 6 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance Server1\\Prod -Path
\\\\filestore\\backups\\servername\\instancename\\dbname\\backuptype -FilePath dbname-backuptype-timestamp.trn -Type Log
-ReplaceInName
Performs a log backup for every database. For the database db1 this would results in backup files in
\\\\filestore\\backups\\server1\\prod\\db1\\Log\\db1-log-31102018.trn
-------------------------- EXAMPLE 7 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance Sql2017 -Database master -FilePath NUL
Performs a backup of master, but sends the output to the NUL device (ie; throws it away)
-------------------------- EXAMPLE 8 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance Sql2016 -Database stripetest -AzureBaseUrl
https://az.blob.core.windows.net/sql,ht ... ws.net/sql
Performs a backup of the database stripetest, striping it across the 2 Azure blob containers at
https://az.blob.core.windows.net/sql and https://dbatools.blob.core.windows.net/sql, assuming that Shared Access
Signature credentials for both containers exist on the source instance
-------------------------- EXAMPLE 9 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance Sql2017 -Database master -EncryptionAlgorithm AES256 -EncryptionCertificate
BackupCert
Backs up the master database using the BackupCert certificate and the AES256 algorithm.
RELATED LINKS
SYNOPSIS
Backup one or more SQL Sever databases from a single SQL Server SqlInstance.
SYNTAX
Backup-DbaDatabase [-SqlCredential <Pscredential>] [-Database <System.Object[]>] [-ExcludeDatabase
<System.Object[]>] [-Path <System.String[]>] [-FilePath <String>] [-ReplaceInName <Switch>] [-CopyOnly <Switch>]
[-Type <String>] [-CreateFolder <Switch>] [-FileCount <Int>] [-CompressBackup <Switch>] [-Checksum <Switch>]
[-Verify <Switch>] [-MaxTransferSize <Int>] [-BlockSize <Int>] [-BufferCount <Int>] [-AzureBaseUrl
<System.String[]>] [-AzureCredential <String>] [-NoRecovery <Switch>] [-BuildPath <Switch>] [-WithFormat <Switch>]
[-Initialize <Switch>] [-SkipTapeHeader <Switch>] [-TimeStampFormat <String>] [-IgnoreFileChecks <Switch>]
[-OutputScriptOnly <Switch>] [-EncryptionAlgorithm <String>] [-EncryptionCertificate <String>] [-EnableException
<Switch>] [<CommonParameters>]
Backup-DbaDatabase -SqlInstance <DbaInstanceParameter> [-SqlCredential <Pscredential>] [-Database
<System.Object[]>] [-ExcludeDatabase <System.Object[]>] [-Path <System.String[]>] [-FilePath <String>]
[-ReplaceInName <Switch>] [-CopyOnly <Switch>] [-Type <String>] [-CreateFolder <Switch>] [-FileCount <Int>]
[-CompressBackup <Switch>] [-Checksum <Switch>] [-Verify <Switch>] [-MaxTransferSize <Int>] [-BlockSize <Int>]
[-BufferCount <Int>] [-AzureBaseUrl <System.String[]>] [-AzureCredential <String>] [-NoRecovery <Switch>]
[-BuildPath <Switch>] [-WithFormat <Switch>] [-Initialize <Switch>] [-SkipTapeHeader <Switch>] [-TimeStampFormat
<String>] [-IgnoreFileChecks <Switch>] [-OutputScriptOnly <Switch>] [-EncryptionAlgorithm <String>]
[-EncryptionCertificate <String>] [-EnableException <Switch>] [<CommonParameters>]
Backup-DbaDatabase [-SqlCredential <Pscredential>] [-Database <System.Object[]>] [-ExcludeDatabase
<System.Object[]>] [-Path <System.String[]>] [-FilePath <String>] [-ReplaceInName <Switch>] [-CopyOnly <Switch>]
[-Type <String>] -InputObject <System.Object[]> [-CreateFolder <Switch>] [-FileCount <Int>] [-CompressBackup
<Switch>] [-Checksum <Switch>] [-Verify <Switch>] [-MaxTransferSize <Int>] [-BlockSize <Int>] [-BufferCount <Int>]
[-AzureBaseUrl <System.String[]>] [-AzureCredential <String>] [-NoRecovery <Switch>] [-BuildPath <Switch>]
[-WithFormat <Switch>] [-Initialize <Switch>] [-SkipTapeHeader <Switch>] [-TimeStampFormat <String>]
[-IgnoreFileChecks <Switch>] [-OutputScriptOnly <Switch>] [-EncryptionAlgorithm <String>] [-EncryptionCertificate
<String>] [-EnableException <Switch>] [<CommonParameters>]
DESCRIPTION
Performs a backup of a specified type of 1 or more databases on a single SQL Server Instance. These backups may be
Full, Differential or Transaction log backups.
PARAMETERS
-AzureBaseUrl [<System.String[]>]
The URL(s) to the base container of an Azure Storage account to write backups to.
If specifying the AzureCredential parameter you can only provide 1 value as page blobs do not support multiple
URLs
If using Shared Access keys, you may specify as many URLs as you want, as long as a corresponding credential
exists on the source server.
If specified, the only other parameters than can be used are "CopyOnly", "Type", "CompressBackup", "Checksum",
"Verify", "AzureCredential", "CreateFolder".
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-AzureCredential [<String>]
The name of the credential on the SQL instance that can write to the AzureBaseUrl, only needed if using
Storage access keys
If using SAS credentials, the command will look for a credential with a name matching the AzureBaseUrl. As
page blobs are used with this option we force the number of files to 1 and ignore any value passed in for
BlockSize or MaxTransferSize
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-BlockSize [<Int>]
Specifies the block size to use. Must be one of 0.5KB, 1KB, 2KB, 4KB, 8KB, 16KB, 32KB or 64KB. This can be
specified in bytes.
Refer to https://msdn.microsoft.com/en-us/library/ms178615.aspx for more detail
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-BufferCount [<Int>]
Number of I/O buffers to use to perform the operation.
Refer to https://msdn.microsoft.com/en-us/library/ms178615.aspx for more detail
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-BuildPath [<Switch>]
By default this command will not attempt to create missing paths, this switch will change the behaviour so
that it will
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Checksum [<Switch>]
If this switch is enabled, the backup checksum will be calculated.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-CompressBackup [<Switch>]
If this switch is enabled, the function will try to perform a compressed backup if supported by the version
and edition of SQL Server. Otherwise, this function will use the server(s) default setting for compression.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-CopyOnly [<Switch>]
If this switch is enabled, CopyOnly backups will be taken. By default function performs a normal backup, these
backups interfere with the restore chain of the database. CopyOnly backups will not interfere with the restore
chain of the database.
For more details please refer to this MSDN article - https://msdn.microsoft.com/en-us/library/ms191495.aspx
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-CreateFolder [<Switch>]
If this switch is enabled, each database will be backed up into a separate folder on each of the paths
specified by Path.
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
-EncryptionAlgorithm [<String>]
Specified the Encryption Algorithm to used. Must be one of 'AES128','AES192','AES256' or 'TRIPLEDES'
Must specify one of EncryptionCertificate or EncryptionKey as well.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EncryptionCertificate [<String>]
The name of the certificate to be used to encrypt the backups. The existance of the certificate will be
checked, and will not proceed if it does not exist
Is mutually exclusive with the EncryptionKey option
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
-FileCount [<Int>]
This is the number of striped copies of the backups you wish to create. This value is overwritten if you
specify multiple Backup Directories.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-FilePath [<String>]
The name of the file to backup to. This is only accepted for single database backups.
If no name is specified then the backup files will be named DatabaseName_yyyyMMddHHmm (i.e.
"Database1_201714022131") with the appropriate extension.
If the same name is used repeatedly, SQL Server will add backups to the same file at an incrementing position.
SQL Server needs permissions to write to the specified location. Path names are based on the SQL Server (C:\\
is the C drive on the SQL Server, not the machine running the script).
Passing in NUL as the FilePath will backup to the NUL: device
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-IgnoreFileChecks [<Switch>]
This switch stops the function from checking for the validity of paths. This can be useful if SQL Server only
has read access to the backup area.
Note, that as we cannot check the path you may well end up with errors.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Initialize [<Switch>]
Initializes the media as part of the backup operation.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-InputObject [<System.Object[]>]
Internal parameter
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-MaxTransferSize [<Int>]
Sets the size of the unit of transfer. Values must be a multiple of 64kb.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-NoRecovery [<Switch>]
This is passed in to perform a tail log backup if needed
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-OutputScriptOnly [<Switch>]
Switch causes only the T-SQL script for the backup to be generated. Will not create any paths if they do not
exist
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Path [<System.String[]>]
Path in which to place the backup files. If not specified, the backups will be placed in the default backup
location for SqlInstance.
If multiple paths are specified, the backups will be striped across these locations. This will overwrite the
FileCount option.
If the path does not exist, Sql Server will attempt to create it. Folders are created by the Sql Instance, and
checks will be made for write permissions.
File Names with be suffixed with x-of-y to enable identifying striped sets, where y is the number of files in
the set and x ranges from 1 to y.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ReplaceInName [<Switch>]
If this switch is set, the following list of strings will be replaced in the FilePath and Path strings:
instancename - will be replaced with the instance Name
servername - will be replaced with the server name
dbname - will be replaced with the database name
timestamp - will be replaced with the timestamp (either the default, or the format provided)
backuptype - will be replaced with Full, Log or Differential as appropriate
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SkipTapeHeader [<Switch>]
Initializes the media as part of the backup operation.
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 [<DbaInstanceParameter>]
The SQL Server instance hosting the databases to be backed up.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-TimeStampFormat [<String>]
By default the command timestamps backups using the format yyyyMMddHHmm. Using this parameter this can be
overridden. The timestamp format should be defined using the Get-Date formats, illegal formats will cause an
error to be thrown
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Type [<String>]
The type of SQL Server backup to perform. Accepted values are "Full", "Log", "Differential", "Diff", "Database"
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Verify [<Switch>]
If this switch is enabled, the backup will be verified by running a RESTORE VERIFYONLY against the SqlInstance
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-WithFormat [<Switch>]
Formats the media as the first step of the backup operation. NOTE: This will set Initialize and SkipTapeHeader
to $true.
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: DisasterRecovery, Backup, Restore
Author: Stuart Moore (@napalmgram), stuart-moore.com
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance Server1 -Database HR, Finance
This will perform a full database backup on the databases HR and Finance on SQL Server Instance Server1 to Server1
default backup directory.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance sql2016 -Path C:\\temp -Database AdventureWorks2014 -Type Full
Backs up AdventureWorks2014 to sql2016 C:\\temp folder.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance sql2016 -AzureBaseUrl https://dbatoolsaz.blob.core.windows.net/azbackups/
-AzureCredential dbatoolscred -Type Full -CreateFolder
Performs a full backup of all databases on the sql2016 instance to their own containers under the
https://dbatoolsaz.blob.core.windows.net/azbackups/ container on Azure blog storage using the sql credential
"dbatoolscred" registered on the sql2016 instance.
-------------------------- EXAMPLE 4 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance sql2016 -AzureBaseUrl https://dbatoolsaz.blob.core.windows.net/azbackups/
-Type Full
Performs a full backup of all databases on the sql2016 instance to the
https://dbatoolsaz.blob.core.windows.net/azbackups/ container on Azure blog storage using the Shared Access
Signature sql credential "https://dbatoolsaz.blob.core.windows.net/azbackups" registered on the sql2016 instance.
-------------------------- EXAMPLE 5 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance Server1\\Prod -Database db1 -Path
\\\\filestore\\backups\\servername\\instancename\\dbname\\backuptype -Type Full -ReplaceInName
Performs a full backup of db1 into the folder \\\\filestore\\backups\\server1\\prod\\db1
-------------------------- EXAMPLE 6 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance Server1\\Prod -Path
\\\\filestore\\backups\\servername\\instancename\\dbname\\backuptype -FilePath dbname-backuptype-timestamp.trn -Type Log
-ReplaceInName
Performs a log backup for every database. For the database db1 this would results in backup files in
\\\\filestore\\backups\\server1\\prod\\db1\\Log\\db1-log-31102018.trn
-------------------------- EXAMPLE 7 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance Sql2017 -Database master -FilePath NUL
Performs a backup of master, but sends the output to the NUL device (ie; throws it away)
-------------------------- EXAMPLE 8 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance Sql2016 -Database stripetest -AzureBaseUrl
https://az.blob.core.windows.net/sql,ht ... ws.net/sql
Performs a backup of the database stripetest, striping it across the 2 Azure blob containers at
https://az.blob.core.windows.net/sql and https://dbatools.blob.core.windows.net/sql, assuming that Shared Access
Signature credentials for both containers exist on the source instance
-------------------------- EXAMPLE 9 --------------------------
PS C:\\>Backup-DbaDatabase -SqlInstance Sql2017 -Database master -EncryptionAlgorithm AES256 -EncryptionCertificate
BackupCert
Backs up the master database using the BackupCert certificate and the AES256 algorithm.
RELATED LINKS