SQL Server 2017: Copying SQL Server data from Linux to Windows with SSIS
SQL Server 2017 Integration Services can now run on Linux, which means that you can migrate a package developed on Windows and use ODBC as the connector.
To test this out, we created a simple package on Windows that copied data between a local and remote SQL Server instance and then ran the package on a Linux machine.
The process was simple, the only thing to bear in mind is that you need to create ODBC data sources with the same names on the Windows and Linux machines. The steps for creating our simple test package are as follows:
- In SQL Server Management Studio, connect to the SQL Server instance from which you want to copy data.
- Create a simple test table:
CREATE DATABASE ssis USE ssis CREATE TABLE Persons ( PersonID int identity, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) ); INSERT INTO Persons VALUES ('Erichsen', 'Tom', 'Skagen 21', 'Stavanger')
- Connect to the instance to which you want to copy data. Create the test table but do not populate it.
- On the machine where Visual Studio is installed create two ODBC data sources, one for each SQL Server instance. Use the 32-bit version of ODBC Data Source Administrator to do this.
- In Visual Studio, create a new Integration Services Project.
- Drag a Data Flow Task from the Toolbox to the Control Flow tab.
- Choose the Data Flow tab.
- Drag an ODBC Source from the Toolbox to the Data Flow tab, and then press Return.
ODBC Destination is in the Other Sources list.
- Select the ODBC Source, and then press Return.
- In the ODBC Source dialog box, choose New.
- In the Configure ODBC Connection Manager dialog box, choose New.
- In the Connection Manager dialog box, choose the ODBC data source that connects to the source SQL Server instance, and then use the OK button to return to the ODBC Source dialog box.
- Choose Columns.
- Drag an ODBC Destination from the Toolbox to the Data Flow tab, and then press Return.
ODBC Destination is in the Other Destinations list.
- Select the ODBC Source. Drag the blue arrow over to the ODBC Destination.
- Select the ODBC Destination, and then press Return.
- In the ODBC Destination dialog box, choose New.
- In the Configure ODBC Connection Manager dialog box, choose New.
- In the Connection Manager dialog box, choose the ODBC data source that connects to the destination SQL Server instance, and then use the OK button to return to the ODBC Source dialog box.
- In the Name of the table or the view list, choose Persons.
- Choose Mappings.
- Delete the mapping between the PersonID columns. The PersonID is populated automatically.
- Install, license and test the 64-bit Linux version of the SQL Server ODBC driver on the machine where the Linux port of SQL Server and SSIS is installed.
- On the Linux machine, create two SQL Server ODBC data source, with the same names as the data sources you created on Windows.
On Linux, you create ODBC data sources by editing a text file, normally stored in
/etc/odbc.ini
. You can adapt the sample data source,SQLSERVER_SAMPLE
, if you like, but remember to rename them. - Copy the SSIS package from the Windows machine to the Linux machine.
- To execute the package:
export PATH=/opt/ssis/bin:$PATH dtexec /F "MyPackage.dtsx"