A C++ utility designed to execute high-speed, compressed backups of PostgreSQL databases. This tool replaces standard cron shell scripts with a compiled binary that handles timestamping and leverages zstd (Zstandard) for superior compression ratios and speed—critical for large Odoo datasets.
- Zstandard Compression: Uses Facebook's
zstdalgorithm, which is significantly faster thangzipand produces smaller files. - Streamed Pipeline: Pipes
pg_dumpoutput directly to the compressor without creating intermediate temporary files, saving disk I/O. - Multithreading: Configured to use multiple CPU cores during compression (Default: 4 threads).
- Automated Naming: Generates precise timestamped filenames (e.g.,
odoo_snapshot_2025-08-21_12-00-00.sql.zst).
- OS: Ubuntu 20.04 / 22.04 LTS
- Dependencies:
sudo apt update sudo apt install zstd postgresql-client
- Compilation Bash
g++ -std=c++17 pg_compressor.cpp -o pg_backup
Configuration
Edit the constants at the top of pg_compressor.cpp to match your environment: C++
const std::string DB_NAME = "odoo_prod"; const std::string DB_USER = "odoo"; const std::string BACKUP_DIR = "/var/backups/odoo/";
Note: Ensure the user running the tool has write permissions to BACKUP_DIR.
Bash
./pg_backup
Automated (Cron): Add this to your crontab to run daily at 2 AM: Bash
0 2 * * * /path/to/pg_backup >> /var/log/odoo_backup.log 2>&1
Restore Instructions
To restore a backup created by this tool: Bash
zstd -d -c odoo_snapshot_DATE.sql.zst | psql -U odoo -d odoo_prod