Skip to main content

A CLI tool to upload database query results to Azure storage.

Project description

DB2Azure CLI

db2az is a powerful command-line interface (CLI) designed to transfer data from on-premises SQL Server (MSSQL), PostgreSQL, and MySQL databases to Azure Blob Storage. This CLI supports both interactive and non-interactive modes, allowing for seamless and flexible data migration workflows.

Features

  • Database Support: MSSQL, PostgreSQL, and MySQL.
  • Azure Integration: Uploads data to Azure Blob Storage in JSON or CSV formats.
  • Interactive Mode: User-friendly prompts to guide through the configuration.
  • Non-Interactive Mode: Direct execution with command-line options for automation.
  • Logging: Detailed logs for troubleshooting and monitoring.
  • Error Handling: Provides descriptive error messages for quick resolution.

Installation

Ensure Python is installed on your system. Then run the following command in your terminal:

pip install db2azure db2azure-cli

Usage

The CLI supports two modes:

Interactive Mode

Run the db2az CLI without any command-line options to enter interactive mode. You will be prompted to:

  1. Select the database type (MSSQL, PostgreSQL, or MySQL).
  2. Provide the source configuration file path (with database connection and query).
  3. Provide the destination configuration file path (with Azure Blob Storage settings).
  4. Choose the file format (JSON or CSV).

Non-Interactive Mode

In non-interactive mode, provide all necessary options via the command line:

> db2az [OPTIONS]

Options

Option Description
-ms Use MSSQL database
-my Use MySQL database
-pg Use PostgreSQL database
-sf Source config file path (server config)
-df Destination config file path (Azure config)
-csv File format as CSV
-json File format as JSON
-log Directory to save log files

Example:

db2az -ms -sf source_config.json -df azure_config.json -csv -log logs/

Configuration

Source Configuration File

The source configuration file should include the database connection parameters and query, e.g.:

{
  "connection_params": {
    "host": "localhost",
    "port": "5432",
    "dbname": "SampleDB",
    "user": "username",
    "password": "password"
  },
  "query": "SELECT * FROM public.users"
}

Destination Configuration File

The destination configuration file should include Azure Blob Storage settings, e.g.:

{
  "container_name": "my-container",
  "folder_path": "my-folder",
  "file_name": "data.json",
  "azure_blob_url": "https://<account_name>.blob.core.windows.net",
  "sas_token": "<your_sas_token>"
}

Logging

If the -log option is specified, logs will be saved in the specified directory. Logs include information about the execution process, errors, and upload status.

Error Handling

The CLI provides detailed error messages in case of failures. Example:

{
  "status": "error",
  "message": "Connection failed: Invalid credentials"
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

We welcome contributions! Feel free to open an issue or submit a pull request for improvements or bug fixes.

Acknowledgements

  • pyodbc: For SQL Server connections.
  • psycopg: For PostgreSQL connections.
  • pymysql: For MySQL connections.
  • azure-storage-blob: For Azure Blob Storage integration.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

db2azure_cli-1.0.5.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

db2azure_cli-1.0.5-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file db2azure_cli-1.0.5.tar.gz.

File metadata

  • Download URL: db2azure_cli-1.0.5.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for db2azure_cli-1.0.5.tar.gz
Algorithm Hash digest
SHA256 023bfd01477a0e9efeab60a3856f5995a7b7650d591f1258fa764735d538a05b
MD5 cc9ced3c043efd140cbee4b0c45c4183
BLAKE2b-256 4e1eaf8dab24177f095f4f6ca5281140e88b53d2580782f22eb4aaef401ceb05

See more details on using hashes here.

File details

Details for the file db2azure_cli-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: db2azure_cli-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for db2azure_cli-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 170cc662dc6a093b230628988edbc9d624dd7d9bf449b0bf84138a04188078d5
MD5 2aac60e26fee7e34c115c1b629e886a5
BLAKE2b-256 039a285dedfabde595c81105c9794c51b6067261ab1f5991f43ef50570900832

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page