1.0.7 • Published 1 year ago

auto-db-dump v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

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-dump

Usage

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

ParameterTypeDescription
dialect'postgres'The type of database (only PostgreSQL is supported).
usernamestringThe username for connecting to the database.
passwordstringThe password for the user.
databasestringThe name of the database.
hoststringThe database host.
portnumberThe database port.
dumpPathDirstringThe directory path to store the dumps.
projectNamestringThe 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

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago