A simple, reliable CLI to back up and restore relational databases. It guides you through an interactive prompt, runs the appropriate native tools, compresses dumps on the fly, and stores them locally under ~/BACKUP/.
- Interactive CLI: Guided prompts for connection details and operation selection
- PostgreSQL & MySQL: Uses
pg_dump/psqlandmysqldump/mysql - Compressed backups: Streams to
.sql.gzto save space - Safe defaults: Standard naming and local
~/BACKUPdestination - Version checks: Validates client vs server version compatibility
- Supported: PostgreSQL, MySQL (full database backup/restore)
- Planned: SQLite, MongoDB
- Node.js 18+
- CLI tools on PATH:
- PostgreSQL:
pg_dump,psql - MySQL:
mysqldump,mysql
- PostgreSQL:
On macOS with Homebrew:
brew install postgresql mysql-client(then ensure their bin directories are on PATH).
git clone https://github.com/gazzaar/safe-keep.git
cd safe-keep
npm installnpm start
# or
npx tsx src/cli.tsYou will be prompted to choose between Backup or Restore, then provide database connection details.
-
Backup:
- Choose "Backup"
- Pick a database type (PostgreSQL/MySQL)
- Provide connection details
- The tool creates a compressed dump at
~/BACKUP/<dbName>-<dbType>-YYYY-MM-DD.sql.gz
-
Restore:
- Choose "Restore"
- Provide connection details for the target server
- Select an existing
*.sql.gzunder~/BACKUPthat matches the DB type - The tool creates the database (if needed) and streams the decompressed SQL into it
<dbName>-<dbType>-YYYY-MM-DD.sql.gz
Examples:
inventory-pg-2025-01-31.sql.gzcrm-MySql-2025-01-31.sql.gz
Backups are stored under ~/BACKUP/ by default. The directory is created if it does not exist.
src/
cli.ts # Interactive entrypoint
types.ts # Shared types
databases/
handleDBType.ts # Routes to DB-specific connectors
postgresql/pgConnect.ts # PG connect + version checks + op orchestration
mysql/mysqlConnect.ts # MySQL connect + version checks + op orchestration
util/
backupStreams.ts # Streaming dump + gzip to file
restoreStreams.ts # Streaming gunzip from file to client
getFileOptions.ts # Backup path + filename helpers
formatFileSize.ts # Human-readable sizes for UI
extractDBType.ts # Parse db type from backup filename
getVersions.ts # Version parsing + compatibility checks
- Passwords are provided at runtime via prompt. For PostgreSQL,
PGPASSWORDis set in the child process environment; for MySQL,--passwordis passed to the client. - Backups are plain SQL inside Gzip archives. No encryption is currently applied.
-
Cloud storage integrations
- S3-compatible (AWS S3, MinIO), GCS, Azure Blob
- Pluggable storage drivers with a simple interface
- Configurable retention and lifecycle policies
-
Encryption
- At-rest encryption using AES-256 (Node
cryptoorage/gpg) - Optional KMS-backed key management (AWS KMS, GCP KMS)
- Integrity checks (hash/signature) per artifact
- At-rest encryption using AES-256 (Node
-
Specific backup/restore operations
- Subset selection: tables, schemas, routines
- Include/exclude patterns
- Pre/post hooks (e.g., lock tables, set roles)
- Incremental or logical replication-based strategies (where supported)
-
Other
- SQLite & MongoDB support
- Non-interactive mode via flags/env (CI-friendly)
- Rich progress + logging levels
- Scheduling examples (cron/systemd) and recipes
Issues and PRs are welcome. Please run the project locally and keep changes small and focused.
MIT. See LICENSE.

