Skip to Content
Back to Portfolio

postgres-snapshot-compressor

Author
RamonRiosJr
Repository Author

Postgres Snapshot Compressor

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.

Features

  • Zstandard Compression: Uses Facebook's zstd algorithm, which is significantly faster than gzip and produces smaller files.
  • Streamed Pipeline: Pipes pg_dump output 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).

Prerequisites

  • 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.

Usage

Manual Backup:

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

Maintained By

Coqui Cloud - IT Solutions & Custom Software

Recent Activity

Revise README for Postgres Snapshot Compressor2026-01-26
Ramon Rios
Add Postgres Snapshot Compressor for Odoo backups2026-01-26
Ramon Rios
Add MIT License to the project2026-01-26
Ramon Rios

About Ramon Rios Jr's Tech Stack

As a Senior Systems Architect and Full Stack Developer, I specialize in building scalable, enterprise-grade applications. My expertise spans across modern backend frameworks using Python, comprehensive ERP deployments with Odoo, and highly interactive frontend architectures. The open-source GitHub repositories listed above demonstrate my proficiency in API development, database optimization, system integrations, and automation. Whether crafting custom business logic or designing sleek glassmorphic user interfaces, I am committed to delivering high-performance software solutions.