A comprehensive cross-platform solution for exporting SQL Server databases and importing them into developer environments.
SQLPack provides a unified command-line interface for database operations:
- sqlpack export: Export complete database schema and data
- sqlpack import: Import database from archive into local environments
- sqlpack export-data: Advanced data export using BCP with native format files
- sqlpack doctor: Validate required tools and environment
- sqlpack install-tools: Print or execute dependency install commands (macOS/Debian)
The tool combines PowerShell and Bash scripts for maximum cross-platform compatibility.
- Online Docs (GitHub Pages): https://lionsad.github.io/sqlpack/
- Local preview:
pip install mkdocs mkdocs-material && mkdocs serve - First-time setup for GitHub Pages: merge to main, then in GitHub → Settings → Pages set Source to "Deploy from a branch" with Branch
gh-pagesand Folder/ (root).
# Install SQLPack
sudo make install
# Validate your environment
sqlpack install-tools # Preview install commands for missing deps
sqlpack install-tools --execute # Run the commands
sqlpack doctor
# Export a database
sqlpack export --server localhost,1433 --database MyApp
# Import to development environment
sqlpack import --archive db-dump.tar.gz --database MyAppDev
# Get help for any command
sqlpack help
sqlpack export --helpSee installation steps in docs/install.md.
Ensure these tools are installed and on PATH:
- sqlcmd and bcp (mssql-tools18)
- PowerShell 7+ (
pwsh) - dbatools PowerShell module (see https://docs.dbatools.io/)
- tar utility (macOS/Linux)
Default output directory for exports is ./db-export.
db-export/
├── schemas.txt # Ordered list of schema files for import
├── schema-tables.sql # Database tables
├── schema-constraints.sql # Foreign keys and constraints
├── schema-procedures.sql # Stored procedures
├── schema-functions.sql # User defined functions
├── schema-views.sql # Views
├── tables.txt # List of all tables (Database.Schema.Table format)
├── data/ # Directory containing table data
│ ├── dbo.Users.dat # Native format data files
│ ├── dbo.Users.fmt # BCP format files
│ └── ...
db-dump.tar.gz # Compressed archive of files above (created in CWD)
- PowerShell Core (pwsh) or Windows PowerShell
- dbatools PowerShell module:
Install-Module dbatools -Scope CurrentUser - SQL Server with bcp utility
- Access to source database
- sqlcmd (SQL Server command line tools)
- tar utility (usually pre-installed on Linux/macOS)
- Azure SQL Edge or SQL Server running locally
# Install to /usr/local (requires sudo)
sudo make install
# Install to custom location (e.g., ~/.local)
PREFIX=$HOME/.local make install
# Make sure ~/.local/bin is in your PATH
export PATH="$HOME/.local/bin:$PATH"# Run directly from source
./sqlpack help# Remove from system
sudo make uninstall
# Remove from custom location
PREFIX=$HOME/.local make uninstall# Export using environment variables
export DB_SERVER="prod.server.com"
export DB_NAME="MyApplication"
export DB_USERNAME="backup_user"
export DB_PASSWORD="secret123"
sqlpack export
# Export with command-line options
sqlpack export --server prod.server.com --database MyApplication# Export with row limits and schema-only tables
DB_ROW_LIMIT=10000 \
DB_SCHEMA_ONLY_TABLES="AuditLog,TempData" \
DB_EXPORT_DIR="./exports" \
DB_ARCHIVE_NAME="myapp-dev-dump.tar.gz" \
DB_TRUST_SERVER_CERTIFICATE=true \
sqlpack export --server localhost,1499 --database MyApp --username sa --password MyPasswordname: Database Export
on:
schedule:
- cron: '0 2 * * *' # Daily at 2 AM
workflow_dispatch:
jobs:
export:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install PowerShell
run: |
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-$(lsb_release -rs)-prod $(lsb_release -cs) main"
sudo apt-get update
sudo apt-get install -y powershell
- name: Install dbatools
run: pwsh -c "Install-Module dbatools -Force -Scope CurrentUser"
- name: Export Database
env:
DB_SERVER: ${{ secrets.DB_SERVER }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
# BASH_LOG: info # uncomment for progress-level logs in CI
# BASH_LOG: trace # uncomment to stream all commands and outputs
run: ./sqlpack export
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: database-dump
path: db-dump.tar.gz# Import to local SQL Server
sqlpack import --archive db-dump.tar.gz --database MyAppDev
# Import with custom server/auth
sqlpack import \
--archive db-dump.tar.gz \
--database MyAppDev \
--server "localhost,1499" \
--username sa \
--password MyPassword# 1. Download the database dump from CI
curl -o db-dump.tar.gz "https://your-ci-system/artifacts/db-dump.tar.gz"
# 2. Start Azure SQL Edge (if not running)
docker run -e "ACCEPT_EULA=1" -e "MSSQL_SA_PASSWORD=YourPassword123" \
-p 1499:1433 -d mcr.microsoft.com/azure-sql-edge
# 3. Import the database
sqlpack import --archive db-dump.tar.gz --database MyAppDev --server "localhost,1499" --username sa --password "YourPassword123"
# 4. Connect and develop
sqlcmd -S "localhost,1499" -U sa -P "YourPassword123" -d MyAppDevAll scripts support configurable logging levels for better debugging and monitoring.
Use the BASH_LOG environment variable to control output verbosity:
# Default - only show errors
sqlpack export
# Show informational messages
BASH_LOG=info sqlpack export
# Show debug information (parameter parsing, decisions)
BASH_LOG=debug sqlpack export-data
# Show all command executions (useful for troubleshooting)
BASH_LOG=trace sqlpack import
# Add timestamps to log messages
BASH_LOG_TIMESTAMP=true BASH_LOG=debug sqlpack exportNotes on visibility and CI:
error(default) keeps console output minimal so failures stand out. Prefer for CI or long unattended runs.infoshows progress/success lines and can bury errors in long outputs; use interactively with care.tracestreams all sub-commands and their output for full context; otherwise, detailed tool output is captured to log files and summarized on failure.
Log Levels (in order of verbosity):
error- Only errors (default)warn- Warnings and errorsinfo- Informational messages, warnings, and errorsdebug- Debug info plus all above levelstrace- Command execution details plus all above levels
Log Files:
- Import operations write detailed logs to
./logs/directory - Individual schema import logs:
./logs/import_<filename>.log - SQL command logs:
./logs/import-sqlcmd.log
Use the PS_LOG_LEVEL environment variable or command-line switches:
# Default - informational level
pwsh ./commands/export.ps1 -SqlInstance "server" -Database "db"
# Verbose output
pwsh ./commands/export.ps1 -SqlInstance "server" -Database "db" -Verbose
# Debug output
pwsh ./commands/export.ps1 -SqlInstance "server" -Database "db" -Debug
# Environment variable approach
$env:PS_LOG_LEVEL = "Debug"
pwsh ./commands/export.ps1 -SqlInstance "server" -Database "db"
# Add timestamps
$env:PS_LOG_TIMESTAMP = "true"
pwsh ./commands/export.ps1 -SqlInstance "server" -Database "db" -VerbosePowerShell Log Levels:
Error- Only errorsWarning- Warnings and errorsInformation- Standard output (default)Verbose- Detailed progress informationDebug- Internal debugging details
| Parameter | Required | Description |
|---|---|---|
-SqlInstance |
Yes | SQL Server instance (e.g., "localhost,1499") |
-Database |
Yes | Database name to export |
-Username |
No | SQL Server username (uses Windows auth if omitted) |
-Password |
No | SQL Server password |
-OutputPath |
No | Output directory (default: "./db-export") |
-TarFileName |
No | Archive filename (default: "db-dump.tar.gz") |
-SchemaOnlyTables |
No | Array of tables to export schema only (no data) |
-DataRowLimit |
No | Maximum rows per table (default: unlimited) |
-TrustServerCertificate |
No | Trust server certificate (bypass SSL validation) |
| Parameter | Required | Description |
|---|---|---|
-a, --archive |
Yes | Path to db-dump.tar.gz file |
-d, --database |
Yes | Target database name |
-s, --server |
No | SQL Server instance (default: "localhost,1499") |
-u, --username |
No | SQL Server username (uses trusted connection if omitted) |
-p, --password |
No | SQL Server password |
-f, --force |
No | Force recreate database if exists |
--skip-data |
No | Import schema only, skip data |
-w, --work-dir |
No | Working directory for extraction (default: "./db-import-work") |
--trust-server-certificate |
No | Trust server certificate (bypass SSL validation) |
| Variable | Description |
|---|---|
DB_SERVER |
SQL Server instance |
DB_NAME |
Database name (required) |
DB_USERNAME |
SQL Server username |
DB_PASSWORD |
SQL Server password |
DB_EXPORT_DIR |
Export directory |
DB_ARCHIVE_NAME |
Archive filename |
DB_ROW_LIMIT |
Maximum rows per table |
DB_TRUST_SERVER_CERTIFICATE |
Trust server certificate (true/false) |
- Use
DataRowLimitfor large tables in development environments - For large or nonessential tables, prefer
SchemaOnlyTablesto export only schema (no data) - Run exports during off-peak hours
- Consider network bandwidth between CI and database server
- Azure SQL Edge performs well on ARM64 (Apple Silicon)
- Use SSD storage for better I/O performance
- Allocate sufficient memory to container/service
- Consider importing schema first, then data in parallel
dbatools module not found
Install-Module dbatools -Scope CurrentUser -Forcebcp command not found
- Install SQL Server command line tools
- Ensure bcp is in system PATH
Connection timeout
- Check firewall settings
- Verify SQL Server is accepting remote connections
- Test connection with sqlcmd first
Database already exists
# Use force flag to recreate
sqlpack import --archive db-dump.tar.gz --database MyAppDev --forcePermission denied
- Ensure user has CREATE DATABASE permissions
- For Azure SQL Edge, use 'sa' account or create user with sufficient rights
Data import failures
- Check data file encoding (should be UTF-8)
- Verify table structure matches exported schema
- Check for constraint violations in data
- Use environment variables for passwords in CI/CD
- Limit database user permissions to minimum required
- Consider encrypting database dumps for sensitive data
- Rotate database credentials regularly
- Use secure networks for database connections
MIT License - see LICENSE file for details.
Development sponsored by Tag1 Consulting, Inc.
- Run from source:
./sqlpack help - Lint Bash scripts:
make lint(uses shellcheck if available) - Run tests:
make test(runs Bats tests intests/if installed) - Increase logging during local runs:
BASH_LOG=trace ./sqlpack import ...orPS_LOG_LEVEL=trace pwsh ./commands/export.ps1 ...