Package Exports
- database-backup
- database-backup/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (database-backup) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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