Skip to main content

Interactive Odoo backup tool for databases and filestore

Project description

🗄️ Odoo Backup Tool

PyPI version Python License: MIT Downloads

Interactive command-line tool for creating complete backups of Odoo databases and filestore. Supports both interactive and automated modes, perfect for development, staging, and production environments.

✨ Features

  • 🎯 Interactive Mode: User-friendly prompts for easy backup creation
  • 🤖 Automation Ready: Non-interactive mode for cron jobs and scripts
  • 📊 Complete Backups: Includes both PostgreSQL database and filestore
  • 🗜️ Compression: Creates compressed ZIP archives with timestamps
  • Cron Integration: Built-in cron job setup helper
  • 🎨 Beautiful Interface: Rich terminal output with progress indicators
  • 🔧 Flexible Configuration: Customizable connection settings
  • 🔍 Smart Detection: Automatically detects Odoo filestore from database and filesystem
  • 🤖 Auto Cron Setup: Automatically adds cron jobs to your system
  • 🧹 Automatic Cleanup: Remove old backups with configurable retention period

🚀 Quick Start

Installation

# Install from PyPI
pip install obx

# Or run directly with uvx (recommended - no installation needed)
uvx obx

Basic Usage

# Interactive mode (guided setup)
uvx obx
# or if installed: obx / odoo-backup

# Non-interactive mode (automation)
uvx obx --host localhost --port 5432 --user odoo --database mydb --non-interactive
# or if installed: obx / odoo-backup --host localhost --port 5432 --user odoo --database mydb --non-interactive

📋 Requirements

  • Python 3.8+
  • PostgreSQL client tools (pg_dump)
  • Access to Odoo database and filestore

💡 Usage Examples

Interactive Mode

Start the tool and follow the prompts:

uvx obx
# or if installed: obx / odoo-backup

The tool will guide you through:

  1. Database connection settings
  2. Database selection from available options
  3. Automatic filestore detection (completely transparent)
  4. Output directory selection
  5. Backup retention policy (cleanup old backups)
  6. Backup confirmation
  7. Optional cron job setup for automated daily backups

Smart filestore detection is fully automatic:

  1. Database Query: Reads filestore path directly from ir_config_parameter table
  2. Odoo Config Integration: Reads actual data_dir from Odoo configuration
  3. Config File Parsing: Searches for odoo.conf files and parses data_dir setting
  4. Standard Locations: Falls back to common Odoo installation paths

No manual filestore configuration needed - the tool finds it automatically!

Automated Backups

For production environments and automated backups:

# Basic automated backup
uvx obx \
  --database production_db \
  --non-interactive

# With custom settings and cleanup
uvx obx \
  --host localhost \
  --port 5432 \
  --user odoo \
  --password mypassword \
  --database production_db \
  --output-path /backups \
  --cleanup-days 30 \
  --non-interactive

Note: Filestore path is automatically detected - no need to specify it!

Cron Job Setup

Interactive Setup (Recommended)

After completing a backup, the tool will ask if you want to set up automated backups:

uvx obx
# ... performs backup ...
# 📅 Automated Backups
# Would you like to set up automatic daily backups with cron? [y/N]: y

The tool will then guide you through:

  • Common cron schedule options (daily, weekly, monthly)
  • Generate the complete cron command
  • Automatically add to your crontab (or provide manual instructions)
  • Handle existing cron jobs (replace/add/cancel options)

Manual Setup

# Setup cron interactively
uvx obx --cron

# This will guide you through configuration and generate a cron line like:
# 0 2 * * * uvx obx --host localhost --port 5432 --user odoo --database mydb --cleanup-days 7 --non-interactive

The tool can automatically add this to your crontab, or you can add it manually:

crontab -e

Automatic Cron Management

The tool includes intelligent cron management:

  • Smart Detection: Detects existing uvx obx cron jobs
  • Replace Option: Update existing jobs with new schedules
  • Add Option: Add additional backup jobs for different databases
  • Duplicate Prevention: Avoids creating duplicate entries
  • One-Click Setup: Automatically modifies your crontab

Example flow:

⚠ Found existing obx cron job(s):
  1. 0 2 * * * uvx obx --database olddb --non-interactive

Choose action [replace/add/cancel] (replace): replace
✅ Cron job updated successfully in your crontab!

To verify:
Run: crontab -l

⚙️ Configuration Options

Option Description Default
--host PostgreSQL server host localhost
--port PostgreSQL server port 5432
--user PostgreSQL username odoo
--password PostgreSQL password (prompted)
--database Database name to backup (interactive selection)
--output-path Backup output directory ./backups
--cleanup-days Remove backups older than N days 7 (if enabled)
--cron Setup cron job for automated backups false
--non-interactive Run without prompts false

Note: Filestore path is automatically detected from database configuration and filesystem - no manual configuration needed!

📁 Backup Structure

Each backup creates a timestamped ZIP file containing:

mydb_20240322_143052.zip
├── mydb.sql              # PostgreSQL database dump
└── filestore.zip         # Compressed filestore directory

🛠️ Development

Local Development Setup

# Clone the repository
git clone https://github.com/sotoplatero/odoo-backup-tool.git
cd odoo-backup-tool

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install in development mode
pip install -e .

# Run the tool
python -m odoo_backup.cli

Running Tests

# Install test dependencies
pip install pytest pytest-cov

# Run tests
pytest

# Run with coverage
pytest --cov=odoo_backup

Building and Publishing

# Install build tools
pip install build twine

# Build the package
python -m build

# Upload to PyPI
twine upload dist/*

🔧 Troubleshooting

Common Issues

pg_dump: command not found

  • Install PostgreSQL client tools
  • On Ubuntu/Debian: sudo apt-get install postgresql-client
  • On CentOS/RHEL: sudo yum install postgresql
  • On macOS: brew install postgresql

Permission denied accessing filestore

  • Ensure the user has read permissions to the filestore directory
  • Run with appropriate user privileges or adjust file permissions

Database connection errors

  • Verify PostgreSQL server is running
  • Check connection parameters (host, port, username)
  • Ensure the user has access to the target database

Environment Variables

You can set default values using environment variables:

export PGHOST=localhost
export PGPORT=5432
export PGUSER=odoo
export PGPASSWORD=mypassword

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙋‍♂️ Support

🌟 Acknowledgments

  • Built with Click for CLI interface
  • Styled with Rich for beautiful terminal output
  • PostgreSQL integration via psycopg2

Made with ❤️ for the Odoo community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

obx-0.4.2.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

obx-0.4.2-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file obx-0.4.2.tar.gz.

File metadata

  • Download URL: obx-0.4.2.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for obx-0.4.2.tar.gz
Algorithm Hash digest
SHA256 7d67f80b41f3eb5375d43a86f8eeebc387593f9dd2ffae0cb14439091c978739
MD5 81c1f9c3d33802d1c3db8b51d8873c4e
BLAKE2b-256 abb29e09ac617372549cd6bf5e2ea4946ca21a92121aaf4136a0fe10f979c1f4

See more details on using hashes here.

File details

Details for the file obx-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: obx-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for obx-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e79f8cfb01c97c1df4f8a0a72ac23d2066d2f22902192c465acc421a7437a10a
MD5 dfd1aff44fde974693639164a526766b
BLAKE2b-256 d3dd8d8f64d1aa4b4658959a816d9be60aabfe828c4c636e917ee8bb3cd8b846

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page