nightdump
v1.2.3
Published
Efficient steaming PostgreSQL backup and restore tool for S3-compatible storage
Maintainers
Readme
Nightdump
A simple, efficient, and robust PostgreSQL backup and restore tool for Node.js using S3-compatible storage (Cloudflare R2, AWS S3, MinIO, etc.).
Features
- Streaming Architecture: Pipes
pg_dumpoutput directly to S3 multipart upload. Zero disk space usage for the dump file on the server. - Streaming Restore: Pipes S3 download stream directly to
pg_restore. - S3/R2 Compatible: Works with any AWS SDK compatible storage.
- CLI & Programmatic Usage: Use it as a library or a command-line tool.
Installation
npm install nightdumpPre-requisites:
- Node.js 18+
pg_dumpandpg_restoremust be installed and available in the system PATH.
Configuration
Create a .env file or ensure these environment variables are set:
# Database Connection (Priority: NIGHTDUMP_DB_URL > DATABASE_URL)
DATABASE_URL=postgresql://user:password@localhost:5432/dbname
# OR if you have multiple DBs and want to be specific:
# NIGHTDUMP_DB_URL=postgresql://user:password@localhost:5432/production_db
S3_ENDPOINT=https://<accountid>.r2.cloudflarestorage.com
S3_REGION=auto
S3_BUCKET=my-backup-bucket
S3_ACCESS_KEY_ID=xxx
S3_SECRET_ACCESS_KEY=xxx
BACKUP_PREFIX=backupsUsage
CLI
Add to your package.json scripts:
"scripts": {
"backup": "nightdump backup",
"restore": "nightdump restore"
}Commands:
npx nightdump backup- Creates a new backup.npx nightdump schedule "0 3 * * *"- Starts a long-running process that backs up daily at 3am.npx nightdump restore- Restores the latest backup.npx nightdump restore <path/to/file.dump>- Restores a specific backup.npx nightdump list- Lists available backups.
Programmatic
import { backup, restore, list } from 'nightdump';
// Trigger a backup
await backup();
// List backups
const backups = await list();
console.log(backups);
// Restore the latest
await restore();License
MIT
