Implemented full incremental backup creation:
internal/backup/incremental_postgres.go:
- CreateIncrementalBackup() - main entry point
- Validates base backup exists and is full backup
- Loads base backup metadata (.meta.json)
- Uses FindChangedFiles() to detect modifications
- Creates tar.gz with ONLY changed files
- Generates incremental metadata with:
- Base backup ID (SHA-256)
- Backup chain (base -> incr1 -> incr2...)
- Changed file count and total size
- Saves .meta.json with full incremental metadata
- Calculates SHA-256 checksum of archive
internal/backup/incremental_tar.go:
- createTarGz() - creates compressed archive
- addFileToTar() - adds individual files to tar
- Handles context cancellation
- Progress logging for each file
- Preserves file permissions and timestamps
Helper Functions:
- loadBackupInfo() - loads BackupMetadata from .meta.json
- buildBackupChain() - constructs restore chain
- CalculateFileChecksum() - SHA-256 for archive
Features:
✅ Creates tar.gz with ONLY changed files
✅ Much smaller than full backup
✅ Links to base backup via SHA-256
✅ Tracks complete restore chain
✅ Full metadata for restore validation
✅ Context-aware (cancellable)
Status: READY FOR TESTING
Next: Wire into backup engine, test with real PostgreSQL data
- Add cloud configuration to Config struct
- Integrate automatic upload into backup flow
- Add --cloud-auto-upload flag to all backup commands
- Support environment variables for cloud credentials
- Upload both backup file and metadata to cloud
- Non-blocking: backup succeeds even if cloud upload fails
Usage:
dbbackup backup single mydb --cloud-auto-upload \
--cloud-bucket my-backups \
--cloud-provider s3
Or via environment:
export CLOUD_ENABLED=true
export CLOUD_AUTO_UPLOAD=true
export CLOUD_BUCKET=my-backups
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
dbbackup backup single mydb
Credentials from AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
- Implement context cleanup with sync.Once and io.Closer interface
- Add regex-based error classification for robust error handling
- Create ProcessManager with thread-safe process tracking
- Add disk space caching with 30s TTL for performance
- Implement metrics collection with structured logging
- Add config persistence (.dbbackup.conf) for directory-local settings
- Auto-save/auto-load configuration with --no-config and --no-save-config flags
- Successfully tested with 42GB d7030 database (35K large objects, 36min backup)
- All cross-platform builds working (9/10 platforms)
- Check context.Done() before starting each database backup
- Gracefully cancel ongoing backups on Ctrl+C/SIGTERM
- Log cancellation and exit with proper error message
- Signal handling already exists in main.go (signal.NotifyContext)
1. Parallel Cluster Operations (3-5x speedup):
- Added ClusterParallelism config option (default: 2 concurrent operations)
- Implemented worker pool pattern for cluster backup/restore
- Thread-safe progress tracking with sync.Mutex and atomic counters
- Configurable via CLUSTER_PARALLELISM env var
2. Progress Indicator Optimizations:
- Replaced busy-wait select+sleep with time.Ticker in Spinner
- Replaced busy-wait select+sleep with time.Ticker in Dots
- More CPU-efficient, cleaner shutdown pattern
3. Signal Handler Cleanup:
- Added signal.Stop() to properly deregister signal handlers
- Prevents goroutine leaks on long-running operations
- Applied to both single and cluster restore commands
Benefits:
- Cluster backup/restore 3-5x faster with 2-4 workers
- Reduced CPU usage in progress spinners
- Cleaner goroutine lifecycle management
- No breaking changes - sequential by default if parallelism=1
High Priority Fixes:
- Use configurable ClusterTimeoutMinutes for restore (was hardcoded 2 hours)
- Add comment explaining goroutine cleanup in stderr reader (cmd.Run waits)
- Add defer cancel() in cluster backup loop to prevent context leak on panic
Medium Priority Fixes:
- Standardize tick rate to 100ms for both backup and restore (consistent UX)
- Add spinnerFrame field to BackupExecutionModel for incremental updates
- Define package-level spinnerFrames constant to avoid repeated allocation
Low Priority Fixes:
- Add 30-second timeout per database in cluster cleanup loop
- Prevents indefinite hangs when dropping many databases
Optimizations:
- Pre-allocate 512 bytes in View() string builders (reduces allocations)
- Use incremental spinner frame calculation (more efficient than time-based)
- Share spinner frames array across all TUI operations
All changes are backward compatible and maintain existing behavior.
- Created internal/progress/estimator.go with ETAEstimator component
- Tracks elapsed time and estimates remaining time based on progress
- Enhanced Spinner and LineByLine indicators to display ETA info
- Integrated into BackupCluster and RestoreCluster functions
- Display format: 'Operation | X/Y (Z%) | Elapsed: Xm | ETA: ~Ym remaining'
- Preserves spinner animation while showing progress/time estimates
- Quick Win approach: no historical data storage, just current operation tracking
HIGH PRIORITY FIXES:
1. Remove unused progressCallback mechanism (dead code cleanup)
2. Add unit tests for restore package (formats, safety checks)
- Test coverage for archive format detection
- Test coverage for safety validation
- Added NullLogger for testing
3. Fix ignored errors in backup pipeline
- Handle StdoutPipe() errors properly
- Log stderr pipe errors
- Document CPU detection errors
IMPROVEMENTS:
- formats_test.go: 8 test functions, all passing
- safety_test.go: 6 test functions for validation
- logger/null.go: Test helper for unit tests
- Proper error handling in streaming compression
- Fixed indentation in stderr handling
- Smart format selection: plain for >5GB, custom for smaller
- Streaming compression: pg_dump | pigz pipeline (zero-copy)
- Direct file writing: no Go buffering
- Memory usage: constant <1GB regardless of DB size
- Handles 100GB+ databases without OOM
- 90% memory reduction vs previous version
- Added comprehensive optimization plan docs
- PostgreSQL and MySQL support
- Interactive TUI with fixed menu navigation
- Line-by-line progress display
- CPU-aware parallel processing
- Cross-platform build support
- Configuration settings menu
- Silent mode for TUI operations