| title | Export and import a database on Linux with sqlpackage - SQL Server vNext CTP1 | Microsoft Docs |
|---|---|
| description | |
| author | sanagama |
| ms.author | sanagama |
| manager | jhubbard |
| ms.date | 11/14/2016 |
| ms.topic | article |
| ms.prod | sql-linux |
| ms.technology | database-engine |
| ms.assetid | e239793b-e630-4110-81cc-19b1ef8bb8b0 |
Restore a SQL Server database from Windows to Linux is the recommended method to migrate a database to SQL Server on Linux.
The sqlpackage command line utility can be used to perform a number of operations on databases such as:
- export a database (database schema and user data) to a .bacpac file
- import a database (database schema and/or user data) from a .bacpac file
- create a database snapshot (.dacpac) file for a database
- incrementally update a database schema to match the schema of a source .dacpac file
- create a Transact-SQL incremental update script that updates the schema of a target database to match the schema of a source database
You can use the sqlpackage command line utility with Microsoft SQL Server running on-premises or in the cloud, on Linux, Windows or Docker and from Azure SQL Database. The sqlpackage command line utility is particularly useful when you wish to import a database from Azure SQL Database to SQL Server on Linux or vice-versa.
The sqlpackage command line utility is in the following location after you install SQL Server on Linux. Running sqlpackage with no command line parameters displays help about the available parameters:
/opt/mssql/bin/sqlpackageYou can specify command line parameters for a number of actions along with action specific parameters and properties as follows:
/opt/mssql/bin/sqlpackage {parameters}{properties}{SQLCMD Variables}
/opt/mssql/bin/sqlpackage /Action:Extract /SourceServerName:tcp:<your_server> /SourceDatabaseName:<your_database> /TargetFile:</path/to/your/file.dacpac> /SourceUser:<username> /SourcePassword:<password>Command line parameters can be specified using their short forms:
/opt/mssql/bin/sqlpackage /a:Export /ssn:tcp:<your_server> /sdn:<your_database> /tf:</path/to/your/file.bacpac> /su:<username> /sp:<password>Use the following command to export database schema and user data to a .BACPAC file:
/opt/mssql/bin/sqlpackage /a:Export /ssn:tcp:<your_server> /sdn:<your_database> /su:<username> /sp:<password> /tf:</path/to/your/file.bacpac> Use the following command to import database schema and user data from a .BACPAC file:
/opt/mssql/bin/sqlpackage /a:Import /tsn:tcp:<your_server> /tdn:<your_database> /tu:<username> /tp:<password> /sf:</path/to/your/file.bacpac>