List All Tables Stored in a SQL Server Backup (.BAK) File in Python

Cloudmersive
2 min readFeb 1, 2022

Querying database backup files is a pain, but thankfully there’s an API for that. The Cloudmersive Data Integration API has a few iterations capable of easily and directly querying database backup files & converting those files into different formats. In this article, we’ll walk through how you can connect to an iteration of this API which will list all tables stored in a SQL Server Backup (.BAK) file. You can accomplish this in 13+ common programming languages — today, we’ll do it in Python.

To get started, first copy & paste the Python SDK installation command along with the below code snippet to start the callback function:

pip install cloudmersive-dataintegration-api-clientfrom __future__ import print_function
import time
import cloudmersive_dataintegration_api_client
from cloudmersive_dataintegration_api_client.rest import ApiException
from pprint import pprint

After that, you can add in the API key authorization code snippet below. If you don’t have an API key already, you can get one by making 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'

For the last step, copy the below code to complete the callback function and you’re all set to go:

# create an instance of the API class
api_instance = cloudmersive_dataintegration_api_client.BackupConvertApi(cloudmersive_dataintegration_api_client.ApiClient(configuration))
input_file = '/path/to/inputfile' # file | Input file to perform the operation on (optional)
try:
# Lists all tables stored in a SQL Server Backup (.BAK) file
api_response = api_instance.dataintegration_backup_convert_mssql_bak_get_tables_post(input_file=input_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling BackupConvertApi->dataintegration_backup_convert_mssql_bak_get_tables_post: %s\n" % e)

--

--

Cloudmersive

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