n8n series · Odoo · PostgreSQL · S3 · Telegram
Automatic Odoo backups with n8n, S3 and Telegram alerts
An Odoo backup has two parts: the PostgreSQL database and the filestore, the folder with attachments, images and PDFs. If you only save the database, every attached invoice and document will be missing after a restore.
This flow fits the Odoo 18 on AWS EC2 setup and n8n installed as in the n8n on EC2 guide.
Quick answer
Schedule Trigger (3:30) → SSH node running pg_dump + filestore tar + aws s3 cp on the Odoo server → Code that reads the result → Telegram with the summary or the error.
1. Why the SSH node
Since n8n 2.0 the Execute Command node is disabled by default, and it would run inside the n8n container anyway. The SSH node runs the script on the Odoo server with a restricted user.
Minimal IAM policy for the instance role (upload only):
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["s3:PutObject"],
"Resource": "arn:aws:s3:::mi-bucket-backups/odoo/*"
}]
}2. The backup script
Schedule Trigger (cron 30 3 * * *) → SSH (Execute Command) → Code → Telegram
Install this script as root at /usr/local/sbin/backup-odoo, mode 0750. Give the backup SSH user sudo access only to this exact script without arguments; never grant generic sudo access to tar. Run sudo -n /usr/local/sbin/backup-odoo from n8n. Adapt service, database, bucket and paths. This example stops all Odoo writers during the DB and filestore copy, so schedule maintenance downtime. Also back up configuration and custom addons separately with encryption.
#!/usr/bin/env bash
# Root-owned script: /usr/local/sbin/backup-odoo, mode 0750.
# Run with: sudo -n /usr/local/sbin/backup-odoo
set -euo pipefail
umask 077
exec 9>/run/lock/backup-odoo.lock
flock -n 9 || { echo "Backup already running" >&2; exit 1; }
FECHA=$(date -u +%Y-%m-%d-%H%M%S)
DIR=/opt/odoo/backups
install -d -m 0700 "$DIR"
# Stop every Odoo writer (including cron/workers) before copying DB + filestore.
# Adapt this service name and paths to your installation. Maintenance downtime required.
systemctl is-active --quiet odoo18
trap 'systemctl start odoo18' EXIT
systemctl stop odoo18
sudo -u odoo pg_dump -Fc -d produccion > "$DIR/odoo-db-$FECHA.dump"
tar -czf "$DIR/odoo-filestore-$FECHA.tar.gz" -C /opt/odoo/data/filestore produccion
systemctl start odoo18
trap - EXIT
# Keep configuration and custom addons in a separately encrypted backup as well.
# Instance IAM role: upload only. No long-lived AWS key in this script.
aws s3 cp "$DIR/odoo-db-$FECHA.dump" s3://mi-bucket-backups/odoo/ --only-show-errors
aws s3 cp "$DIR/odoo-filestore-$FECHA.tar.gz" s3://mi-bucket-backups/odoo/ --only-show-errors
find "$DIR" -maxdepth 1 -type f -name 'odoo-*' -mtime +3 -delete
printf '{"fecha":"%s","db":"%s","filestore":"%s"}\n' "$FECHA" "$(du -h "$DIR/odoo-db-$FECHA.dump" | cut -f1)" "$(du -h "$DIR/odoo-filestore-$FECHA.tar.gz" | cut -f1)"3. Alert when something fails
Set Settings → On Error: Continue (using error output) on the SSH node and connect both the regular and error outputs to the Code node. Use an external missed-backup monitor as well: a stopped n8n instance cannot send alerts.
// Code: interpreta la salida del nodo SSH y prepara el aviso
const r = $input.first().json;
const ok = r.code === 0;
let info = {};
try { info = JSON.parse((r.stdout ?? '').trim().split('\n').pop()); } catch {}
return [{
json: {
ok,
texto: ok
? `✅ Copia de Odoo ${info.fecha}: base de datos ${info.db}, filestore ${info.filestore}. Subida a S3.`
: `❌ Ha fallado la copia de Odoo (código ${r.code}).\n${String(r.stderr ?? '').slice(-800)}`,
},
}];4. Test the restore
# Isolated test server only. Replace BACKUP_TIMESTAMP with an existing backup.
# Stop its Odoo service first; disable outgoing mail, cron and production integrations.
# Use a separate read-only S3 restore role: the upload-only role cannot download.
sudo systemctl stop odoo18
aws s3 cp s3://mi-bucket-backups/odoo/odoo-db-BACKUP_TIMESTAMP.dump .
aws s3 cp s3://mi-bucket-backups/odoo/odoo-filestore-BACKUP_TIMESTAMP.tar.gz .
sudo -u odoo createdb pruebas
sudo -u odoo pg_restore --exit-on-error -d pruebas --no-owner < odoo-db-BACKUP_TIMESTAMP.dump
sudo mkdir -p /opt/odoo/data/filestore/pruebas
sudo tar -xzf odoo-filestore-BACKUP_TIMESTAMP.tar.gz -C /opt/odoo/data/filestore/pruebas --strip-components=1
sudo chown -R odoo:odoo /opt/odoo/data/filestore/pruebasFrequently asked questions
Is the Odoo database manager enough?
It lets you download backups by hand, but it should be disabled in production (list_db = False) and is not suitable for reliable automation.
What about EBS snapshots?
They complement this by restoring the whole server, but they do not make it easy to restore one day’s database elsewhere. Use both.