Automating PostgreSQL Backups to MinIO with Notification Integration
@nerdyslacker
Backups are an essential part of maintaining database reliability and integrity. Automating this process ensures consistent backups without manual intervention. In this post, we'll explore a script that automates PostgreSQL backups, uploads them to a MinIO server, and integrates with Uptime Kuma to notify about the success or failure of the backup process.
The solution consists of two scripts:
- Backup Script: Automates PostgreSQL backups and uploads the backup files to MinIO.
- Wrapper Script: Executes the backup script and sends notifications to Uptime Kuma.
Together, these scripts form a robust, automated system for managing backups while keeping you informed.
PostgreSQL Backup and Upload to MinIO
Features
- Database Backup: Uses
pg_dump
to create a compressed database dump. - MinIO Upload: Transfers the dump to a specified MinIO bucket using the
mc
(MinIO client) command. - Cleanup: Removes the local backup file after a successful upload.
- Pruning Old Backups: Retains only the latest three backups by pruning older files.
Notification Integration with Uptime Kuma
This script wraps around the backup script to add status monitoring and notification capabilities. It uses Uptime Kuma to send notifications about the backup's success or failure.
How to Use These Scripts
-
Prepare the Environment:
- Install the necessary dependencies:
pg_dump
for PostgreSQL backups.mc
(MinIO Client) for managing MinIO storage.curl
for sending notifications to Uptime Kuma.
- Install the necessary dependencies:
-
Set Environment Variables: Export the required variables before running the scripts:
-
Schedule Backups: Automate the process by scheduling the wrapper script using cron: