Skip to content

Export

Exports database schema and data and produces ./db-export and db-dump.tar.gz.

Examples

# Minimal (server, database)
sqlpack export --server localhost,1433 --database MyApp

# With credentials and options
DB_ROW_LIMIT=10000 \
DB_SCHEMA_ONLY_TABLES="AuditLog,TempData" \
DB_EXPORT_DIR="./exports" \
DB_ARCHIVE_NAME="myapp-dev-dump.tar.gz" \
sqlpack export --server localhost,1499 --database MyApp --username sa --password MyPassword

Common Scenarios

# Use environment variables (recommended for CI)
export DB_SERVER="prod.server.com,1433"
export DB_NAME="MyApp"
export DB_USERNAME="backup_user"
export DB_PASSWORD="******"
sqlpack export

# Trusted connection (omit username/password)
sqlpack export --server "corp-sql01,1433" --database MyApp

# Custom port and archive name
DB_EXPORT_DIR=./db-export \
DB_ARCHIVE_NAME=myapp-2024-09-16.tar.gz \
sqlpack export --server "localhost,1499" --database MyApp

# Limit data volume for dev dumps
DB_ROW_LIMIT=50000 sqlpack export --server "localhost,1499" --database MyApp

# Exclude heavy tables from data export (schema-only)
DB_SCHEMA_ONLY_TABLES="AuditLog,LargeFactTable,SessionLog" \
sqlpack export --server "localhost,1499" --database MyApp

# Trust self-signed certificates when needed
DB_TRUST_SERVER_CERTIFICATE=true \
sqlpack export --server "staging.company.net,1433" --database MyApp

# Increase logging for troubleshooting (propagates to PowerShell)
BASH_LOG=debug sqlpack export --server localhost,1433 --database MyApp

Verifying Outputs

# List generated files
ls -1 ./db-export

# Inspect table list (Database.Schema.Table)
sed -n '1,20p' ./db-export/tables.txt

# Show the schema import order
cat ./db-export/schemas.txt

# Confirm archive exists
ls -lh ./db-dump.tar.gz

Notes

  • Default export directory: ./db-export
  • Default archive name: db-dump.tar.gz in current directory
  • PowerShell exporter uses dbatools under the hood (see CI)

Tip: Run sqlpack doctor first or use sqlpack install-tools --execute to bootstrap sqlcmd/bcp, PowerShell, and dbatools.

Logging

Exports are quiet at the default error level. Choose a level based on your context:

# Show progress and key steps during export (interactive runs)
BASH_LOG=info sqlpack export --server localhost,1433 --database MyApp

# See detailed, real-time schema export and data steps
BASH_LOG=trace sqlpack export --server localhost,1433 --database MyApp

Note: info prints many success/progress lines and can bury errors in long outputs. For CI/long runs, prefer the default error level so failures stand out.