Convert a SQL Server Backup (.BAK) File into CSV for a Specified Table in Python

Cloudmersive
2 min readFeb 1, 2022

In the previous article about the Cloudmersive Data Integration API, we walked through an iteration that can list all tables stored in a SQL Server backup file. In this article, we’ll go over a cousin of this iteration which converts SQL Server backup file into CSV for a specified table. This is perfect for retrieving data quickly & in a desirable format without needing to add any extra steps in-between. Let’s take a look at how you can connect in Python.

To begin connecting with this API, start by copying the below command to install the Python SDK:

pip install cloudmersive-dataintegration-api-client

After that, you can start the callback function with the below code:

from __future__ import print_function
import time
import cloudmersive_dataintegration_api_client
from cloudmersive_dataintegration_api_client.rest import ApiException
from pprint import pprint

Next, add the below snippet in to capture & authenticate your Cloudmersive API key (attainable by creating a free account on the Cloudmersive website):

# Configure API key authorization: Apikey
configuration = cloudmersive_dataintegration_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'

Finally, complete the callback function with the last code snippet below:

# create an instance of the API class
api_instance = cloudmersive_dataintegration_api_client.BackupConvertApi(cloudmersive_dataintegration_api_client.ApiClient(configuration))
table_name = 'table_name_example' # str | Name of the table to return (optional)
input_file = '/path/to/inputfile' # file | Input file to perform the operation on (optional)
try:
# Converts a SQL Server Backup (.BAK) file into CSV for a specified table
api_response = api_instance.dataintegration_backup_convert_mssql_bak_to_csv_post(table_name=table_name, input_file=input_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling BackupConvertApi->dataintegration_backup_convert_mssql_bak_to_csv_post: %s\n" % e)

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.