Config Init Command¶
The config init
command initializes DBSnapper by creating a configuration file and working directory structure. This is typically the first command new users run to set up their DBSnapper environment with sensible defaults and automatically discovered database tools.
Overview¶
The config init command bootstraps a complete DBSnapper installation by: - Creating a YAML configuration file with default settings - Generating a secure encryption key for sensitive data - Setting up the working directory structure - Auto-discovering database client tools on your system - Providing a foundation for adding targets and storage profiles
Syntax¶
Arguments¶
No arguments required - all configuration is automatic with sensible defaults.
Options¶
How It Works¶
- Configuration File Creation: Creates a YAML configuration file at the specified or default location
- Working Directory Setup: Creates the working directory for storing snapshots and temporary files
- Secret Key Generation: Generates a secure 32-character secret key for encrypting sensitive data
- Database Tool Discovery: Automatically discovers and configures PostgreSQL and MySQL client tools
- Default Settings: Applies sensible defaults for Docker images, CPU usage, and feature flags
- Validation: Validates discovered tools and reports their status
Configuration File Location¶
The configuration file location follows this priority order:
--config
flag: Explicitly specified file pathDBSNAPPER_CONFIG
environment variable: Environment-specified path- Development directory: If running from the DBSnapper repository, uses
dbsnapper.yml
in repo root - Default location:
~/.config/dbsnapper/dbsnapper.yml
Examples¶
# Use default location (~/.config/dbsnapper/dbsnapper.yml)
dbsnapper config init
# Specify custom location with flag
dbsnapper config init --config /path/to/custom/config.yml
# Specify custom location with environment variable
DBSNAPPER_CONFIG=/path/to/custom/config.yml dbsnapper config init
Generated Configuration Structure¶
The config init command creates a complete configuration file with these sections:
Authentication and Security¶
authtoken: "" # DBSnapper Cloud API token
secret_key: 37493065d18a05a4df222decea24e956 # Generated encryption key
Database Tools (Auto-Discovered)¶
database_tools:
auto_detect: true # Enable automatic tool discovery
postgresql:
pg_dump: /Applications/Postgres.app/Contents/Versions/17/bin/pg_dump
pg_restore: /Applications/Postgres.app/Contents/Versions/17/bin/pg_restore
psql: /Applications/Postgres.app/Contents/Versions/17/bin/psql
mysql:
mysql: /opt/homebrew/opt/mysql-client/bin/mysql
mysqldump: /opt/homebrew/opt/mysql-client/bin/mysqldump
Default Settings¶
defaults:
working_directory: /Users/username/.dbsnapper # Snapshot storage location
cpus: 2 # CPU cores for operations
shared_target_dst_db_url: "" # Default destination for shared targets
Docker Configuration¶
Feature Flags and Overrides¶
debug: false # Debug logging disabled
feature_flags:
development_utilities: false # Development tools disabled by default
override:
dst_db_url: "" # Global destination database override
nocloud: false # Cloud mode enabled by default
san_query: "" # Global sanitization query override
Working Directory Structure¶
The initialized working directory (~/.dbsnapper
by default) contains:
~/.dbsnapper/
├── snapshots/ # Created automatically when first snapshot is built
└── temp/ # Created automatically for temporary operations
Snapshot Files: When you create snapshots, they're stored as:
- {timestamp}_{target_name}.zip
- Original snapshots
- {timestamp}_{target_name}.san.zip
- Sanitized snapshots
Database Tool Discovery¶
The init command automatically discovers database client tools in these locations:
PostgreSQL Tools¶
- Postgres.app:
/Applications/Postgres.app/Contents/Versions/*/bin/
- Homebrew:
/opt/homebrew/bin/
,/usr/local/bin/
- System paths:
/usr/bin/
,/usr/local/bin/
- Custom installations: Checks PATH environment variable
MySQL Tools¶
- Homebrew:
/opt/homebrew/opt/mysql-client/bin/
,/opt/homebrew/bin/
- System installations:
/usr/bin/
,/usr/local/bin/
,/usr/local/mysql/bin/
- Custom installations: Checks PATH environment variable
Tool Validation¶
Each discovered tool is validated by: - Checking executable permissions - Verifying the tool responds to version queries - Ensuring compatibility with DBSnapper requirements
Configuration File Format Evolution¶
DBSnapper v3.0 introduces an improved configuration format while maintaining backwards compatibility:
New Format (Recommended)¶
Legacy Format (Still Supported)¶
Priority Rules¶
- If both formats exist,
defaults.working_directory
takes precedence - Legacy format is automatically upgraded on next configuration update
- No manual migration required
Example Usage¶
Basic Initialization¶
Output:
DBSnapper v2.7.0-dev - Configuration Initialization
──────────────────────────────────────────────────────
→ Config file location: /Users/username/.config/dbsnapper/dbsnapper.yml
→ Working directory: /Users/username/.dbsnapper
→ Configuration Initialization
✓ Configuration file initialized: /Users/username/.config/dbsnapper/dbsnapper.yml
✓ Working directory created: /Users/username/.dbsnapper
Custom Location Initialization¶
# Initialize with custom configuration location
dbsnapper config init --config /project/dbsnapper.yml
Development Setup¶
# Initialize for development (from DBSnapper repo directory)
cd /path/to/dbsnapper-repo
dbsnapper config init # Creates dbsnapper.yml in repo root
Post-Initialization Steps¶
After running config init
, you can:
1. Verify Installation¶
2. Add Database Targets¶
Edit your configuration file to add targets:
targets:
my-database:
name: "My Database"
snapshot:
src_url: "postgresql://user:pass@localhost:5432/mydb"
dst_url: "postgresql://user:pass@localhost:5432/mydb_snap"
3. Configure Cloud Integration (Optional)¶
4. Add Storage Profiles (Optional)¶
Configuration File Management¶
Manual Editing¶
The generated configuration file is standard YAML and can be edited manually:
# Edit with your preferred editor
nano ~/.config/dbsnapper/dbsnapper.yml
vim ~/.config/dbsnapper/dbsnapper.yml
Validation¶
Tool Re-discovery¶
Use Cases¶
New User Setup¶
# Complete new installation
dbsnapper config init
dbsnapper config check
# Add targets via manual configuration or DBSnapper Cloud
Project-Specific Configuration¶
# Setup per-project configuration
cd /path/to/project
dbsnapper config init --config ./dbsnapper.yml
# Configure project-specific targets and settings
Development Environment¶
# Setup development environment
cd /path/to/dbsnapper-repo
dbsnapper config init
# Enables development features and uses repo-local config
CI/CD Pipeline Setup¶
# Automated pipeline initialization
DBSNAPPER_CONFIG=/ci/config/dbsnapper.yml dbsnapper config init
# Configure targets via environment variables or mounted config
Multiple Environment Management¶
# Separate configurations for different environments
dbsnapper config init --config ~/.config/dbsnapper/dev.yml
dbsnapper config init --config ~/.config/dbsnapper/staging.yml
dbsnapper config init --config ~/.config/dbsnapper/prod.yml
Security Considerations¶
Secret Key Protection¶
- The generated
secret_key
encrypts sensitive data in the configuration - Keep secure: Don't commit to version control
- Backup safely: Store in secure password manager
- Rotate regularly: Generate new keys periodically
Configuration File Security¶
# Set appropriate file permissions
chmod 600 ~/.config/dbsnapper/dbsnapper.yml
# Verify permissions
ls -la ~/.config/dbsnapper/dbsnapper.yml
# Should show: -rw------- (read/write for owner only)
Environment Variables¶
# Use environment variables for sensitive data in CI/CD
export DBSNAPPER_AUTHTOKEN="your_token_here"
export DBSNAPPER_SECRET_KEY="your_secret_key_here"
Troubleshooting¶
Common Issues¶
Permission Denied
- Check write permissions to configuration directory - Try with appropriate permissions:sudo dbsnapper config init
- Use custom location with write access
Database Tools Not Found
- Install required database client tools - Check PATH environment variable - Rundbsnapper config discover --save
after installation
Configuration File Already Exists
- The init command won't overwrite existing configurations - Delete existing file if you want to reinitialize:rm ~/.config/dbsnapper/dbsnapper.yml
- Use different location: dbsnapper config init --config /path/to/new/config.yml
Working Directory Creation Failed
- Check disk space availability - Verify write permissions to parent directory - Try different working directory location in configurationInvalid Configuration Path
- Ensure parent directories exist - Use absolute paths when possible - Check path syntax and permissionsRecovery Steps¶
- Check Permissions: Ensure write access to configuration and working directories
- Verify Tools: Install required PostgreSQL and MySQL client tools
- Clear State: Remove existing configuration files if reinitializing
- Use Custom Paths: Try different configuration or working directory locations
- Check Dependencies: Ensure all required system dependencies are installed
First Command
config init
is typically the first command new users run. It sets up everything needed to start using DBSnapper with sensible defaults.
Existing Configuration
The init command will not overwrite existing configuration files. Delete the existing file first if you want to reinitialize.
Auto-Discovery
Database tools are automatically discovered during initialization. Run dbsnapper config discover --save
after installing new database clients.
Related Commands¶
config check
- Validate configuration and dependenciesconfig discover
- Re-discover database toolsconfig validate
- Validate configuration file syntaxauth token
- Add cloud authentication
See Also¶
- Configuration - Complete configuration reference
- Database Engines - Supported databases and setup
- Installation - DBSnapper installation guide
- Quick Start - Getting started tutorial