1.0.7 • Published 1 year ago
auto-db-dump v1.0.7
AutoDatabaseDumpModule
Description
AutoDatabaseDumpModule is a NestJS module for automatically creating dumps of a PostgreSQL database at a specified interval. The database dump is saved to a specified directory, and old files are automatically deleted after a certain retention period.
Installation
npm install auto-database-dumpUsage
Importing the module in AppModule
import { Module } from '@nestjs/common';
import { AutoDatabaseDumpModule } from '@your-org/auto-database-dump';
@Module({
imports: [
AutoDatabaseDumpModule.forRoot({
dialect: 'postgres',
username: 'your_username',
password: 'your_password',
database: 'your_database',
host: 'localhost',
port: 5432,
dumpPathDir: '/path/to/dumps',
projectName: 'my_project',
}),
],
})
export class AppModule {}Parameter Description
| Parameter | Type | Description |
|---|---|---|
| dialect | 'postgres' | The type of database (only PostgreSQL is supported). |
| username | string | The username for connecting to the database. |
| password | string | The password for the user. |
| database | string | The name of the database. |
| host | string | The database host. |
| port | number | The database port. |
| dumpPathDir | string | The directory path to store the dumps. |
| projectName | string | The project name used in the dump file names. |
How It Works
- The module creates a dump of the database every day at 2:00 AM (configured via @Cron(‘0 2 * * *’)).
- The dump file is saved in the directory {dumpPathDir}/{projectName}/dump_YYYY-MM-DD_HH:mm:ss.sql.
- Old dumps older than 30 days are automatically deleted.
Logging
- ✅ Successful dump creation: Database dump created: /path/to/dump.sql
- ❌ Error creating dump: Error creating dump:
- 🗑️ Old dump deletion: Old dump deleted: dump_YYYY-MM-DD_HH:mm:ss.sql
License
MIT