This repository contains a set of automation scripts designed to manage a PostgreSQL database running in a Docker container. The various utilities offer features such as:
- Automatic backups
- Backup aging and cleanup
- Database restoration
- Initialization and configuration of a PostgreSQL database in a Docker container
- Logging of backup activities
The repository consists of the following key files and scripts:
db_init.sh
: Initializes and configures a PostgreSQL database within a Docker container.db_backup.sh
: Handles the backup of the PostgreSQL database.db_restore.sh
: Restores the PostgreSQL database from the most recent backup.backup-cron.js
: Schedules and automates the running ofdb_backup.sh
using a Node.js cron job.
utils.js
: Provides utility functions for logging and file cleanup.utils.json
: Configuration file for specifying utility settings.
Dockerfile
: Contains the setup for the Docker image used for the PostgreSQL database..gitignore
: Specifies files and directories to ignore in git.package.json
andyarn.lock
: Node.js package information and lock file for dependency management.
The backup script (db_backup.sh
) and the Node.js cron job (backup-cron.js
) work together to automate the database backup process. Backups are triggered every 10 seconds and saved with a timestamp.
The system automatically deletes backups that are older than 7 days to conserve storage space.
The db_restore.sh
script can quickly restore the database to the state of the most recent backup.
All backup-related activities are logged to backup.log
, making it easier to track operations and troubleshoot issues.
- Docker for containerization
- Node.js for running the cron job
- PostgreSQL database engine