The SqlPackage Export action exports a connected database to a BACPAC file (.bacpac). By default, data for all tables will be included in the .bacpac file. Optionally, you can specify only a subset of tables for which to export data. The Export action is part of the database portability functionality of SqlPackage. For an export to be transactionally consistent, you must ensure either that no write activity is occurring during the export, or that you're exporting from a transactionally consistent copy of your database.
Note
While Microsoft Entra ID is the new name for Azure Active Directory (Azure AD), to prevent disrupting existing environments, Azure AD still remains in some hardcoded elements such as UI fields, connection providers, error codes, and cmdlets. In this article, the two names are interchangeable.
Note
SqlPackage export performs best for databases under 200GB. For larger databases, you may want to optimize the operation using properties available in this article and tips in Troubleshooting with SqlPackage or alternatively achieve database portability through data in parquet files.
Command-line syntaxSqlPackage initiates the actions specified using the parameters, properties, and SQLCMD variables specified on the command line.
SqlPackage /Action:Export {parameters} {properties}
Required parameters
The Export action requires a TargetFile
parameter to specify the name and location of the .bacpac file to be created. This location must be writable by the user running the command and the containing folder must exist.
The Export action also requires a database source to be specified, either through a combination of:
SourceServerName
and SourceDatabaseName
parameters, orSourceConnectionString
parameter.# example export from Azure SQL Database using SQL authentication and a connection string
SqlPackage /Action:Export /TargetFile:"C:\AdventureWorksLT.bacpac" \
/SourceConnectionString:"Server=tcp:{yourserver}.database.windows.net,1433;Initial Catalog=AdventureWorksLT;Persist Security Info=False;User ID=sqladmin;Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
# example export using short form parameter names, skips schema validation
SqlPackage /a:Export /ssn:"{yourserver}.database.windows.net,1433" /sdn:"AdventureWorksLT" /su:"sqladmin" \
/sp:"{your_password}" /tf:"C:\AdventureWorksLT.bacpac" /p:VerifyExtraction=False
# example export using Microsoft Entra managed identity
SqlPackage /Action:Export /TargetFile:"C:\AdventureWorksLT.bacpac" \
/SourceConnectionString:"Server=tcp:{yourserver}.database.windows.net,1433;Initial Catalog=AdventureWorksLT;Authentication=Active Directory Managed Identity;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
# example export connecting using Microsoft Entra username and password
SqlPackage /Action:Export /TargetFile:"C:\AdventureWorksLT.bacpac" \
/SourceConnectionString:"Server=tcp:{yourserver}.database.windows.net,1433;Initial Catalog=AdventureWorksLT;Authentication=Active Directory Password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;User ID={yourusername};Password={yourpassword}"
# example export connecting using Microsoft Entra universal authentication
SqlPackage /Action:Export /TargetFile:"C:\AdventureWorksLT.bacpac" /UniversalAuthentication:True \
/SourceConnectionString:"Server=tcp:{yourserver}.database.windows.net,1433;Initial Catalog=AdventureWorksLT;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
Parameters for the Export action Parameter Short Form Value Description /AccessToken: /at: {string} Specifies the token-based authentication access token to use when connect to the target database. /Action: /a: Export Specifies the action to be performed. /AzureCloudConfig: /acc: {string} Specifies the custom endpoints for connecting to Microsoft Entra ID in the format: AzureActiveDirectoryAuthority={value};DatabaseServicePrincipalName={value}" . /Diagnostics: /d: {True|False} Specifies whether diagnostic logging is output to the console. Defaults to False. /DiagnosticsFile: /df: {string} Specifies a file to store diagnostic logs. /DiagnosticsLevel: /dl {None|Off|Critical|Error|Warning|Information|Verbose} Specifies the levels of trace messages filtered diagnostics file /MaxParallelism: /mp: {int} Specifies the degree of parallelism for concurrent operations running against a database. The default value is 8. /OverwriteFiles: /of: {True|False} Specifies if SqlPackage should overwrite existing files. Specifying false causes SqlPackage to abort action if an existing file is encountered. Default value is True. /Properties: /p: {PropertyName}={Value} Specifies a name value pair for an action-specific property;{PropertyName}={Value}. /Quiet: /q: {True|False} Specifies whether detailed feedback is suppressed. Defaults to False. /SourceConnectionString: /scs: {string} Specifies a valid SQL Server/Azure connection string to the source database. If this parameter is specified, it shall be used exclusively of all other source parameters. /SourceDatabaseName: /sdn: {string} Defines the name of the source database. /SourceEncryptConnection: /sec: {Optional|Mandatory|Strict|True|False} Specifies if SQL encryption should be used for the source database connection. Default value is True. /SourceHostNameInCertificate: /shnic: {string} Specifies value that is used to validate the source SQL Server TLS/SSL certificate when the communication layer is encrypted by using TLS. /SourcePassword: /sp: {string} For SQL Server Auth scenarios, defines the password to use to access the source database. /SourceServerName: /ssn: {string} Defines the name of the server hosting the source database. /SourceTimeout: /st: {int} Specifies the timeout for establishing a connection to the source database in seconds. /SourceTrustServerCertificate: /stsc: {True|False} Specifies whether to use TLS to encrypt the source database connection and bypass walking the certificate chain to validate trust. Default value is False. /SourceUser: /su: {string} For SQL Server Auth scenarios, defines the SQL Server user to use to access the source database. /TargetFile: /tf: {string} Specifies a target file (that is, a .dacpac file) to be used as the target of action instead of a database. If this parameter is used, no other target parameter shall be valid. This parameter shall be invalid for actions that only support database targets. /TenantId: /tid: {string} Represents the Microsoft Entra tenant ID or domain name. This option is required to support guest or imported Microsoft Entra users as well as Microsoft accounts such as outlook.com, hotmail.com, or live.com. If this parameter is omitted, the default tenant ID for Microsoft Entra ID will be used, assuming that the authenticated user is a native user for this tenant. However, in this case any guest or imported users and/or Microsoft accounts hosted in this Microsoft Entra ID are not supported and the operation will fail.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4