database-backup
v0.0.5
Published
A NestJS dynamic module for backing up PostgreSQL databases using pg_dump.
Maintainers
Readme
📦 database-backup
A NestJS dynamic module for backing up PostgreSQL databases using the native pg_dump utility.
This package allows you to easily integrate PostgreSQL backup functionality into your NestJS applications.
Installation
npm install database-backup⚠️ Make sure you have
pg_dumpinstalled and available in your system’s PATH. It is included by default with PostgreSQL installations.
📖 Usage
1. Import the Module
In your AppModule (or any feature module):
import { Module } from '@nestjs/common';
import { BackupModule } from 'database-backup';
@Module({
imports: [
BackupModule.register({
host: 'localhost',
port: 5432,
databaseUsername: 'postgres',
databasePassword: 'your_password',
// Optional: pgDumpPath: '/path/to/pg_dump'
}),
],
})
export class AppModule {}2. Use the Service
Inject the BackupService anywhere you need to trigger a backup:
import { Injectable } from '@nestjs/common';
import { BackupService } from 'database-backup';
@Injectable()
export class AppService {
constructor(private readonly backupService: BackupService) {}
async runBackup() {
await this.backupService.backupSingleDatabase('my_database');
}
}⚙️ Configuration Options
| Option | Type | Required | Description |
| ------------------ | ------ | -------- | --------------------------------------------------------- |
| host | string | ✅ | Database host (e.g., localhost) |
| port | number | ✅ | Database port (default: 5432) |
| databaseUsername | string | ✅ | PostgreSQL username |
| databasePassword | string | ✅ | PostgreSQL password |
| pgDumpPath | string | ❌ | Optional path to pg_dump binary (if not in system PATH) |
📂 Backup Output
Backups are saved in the current working directory as:
<database-name>-backup.sqlExample:
my_database-backup.sql🔑 Peer Dependencies
This package requires the following peer dependencies:
@nestjs/core(v11+)@nestjs/common(v11+)
Ensure they are installed in your NestJS project.
📝 License
MIT © 2025 \Shaheel Abbasi
