c0c0n3 / odoo.box

All of Martel's Odoo stack on just one NixOS machine.
MIT License
3 stars 0 forks source link

Backups #18

Closed c0c0n3 closed 4 months ago

c0c0n3 commented 4 months ago

This PR implements automatic hot and cold backups with flexible schedules.

Backups run at configurable intervals and every time a backup fires, we dump the Odoo DB into a SQL file (using pg_dump) and sync the Odoo backup file store with the live file store. All the backup files get stored in a configurable backup area. Notice the syncing of the file store happens through rsync which lets us efficiently mirror the live file store as only file blocks that have changed since the last backup actually get copied over from the live file store. Also, any file deleted in the live store gets automatically deleted from the mirror copy too.

We do both hot and cold backups. The hot backups dump the DB and sync the file store while Odoo is running, whereas a cold one stops Odoo before backing up and then restarts it as soon as the backup is done. Notice that a hot backup may result in an inconsistent DB and file store when restored, whereas cold backups are safe to restore.

One last thing to mention is the Odoo sessions clean-up. Since we have to stop Odoo before making a cold backup, we take advantage of Odoo not running to get rid of any session files still on disk. Ideally Odoo should clean up after itself, but that doesn't always happen and overtime you could pile up truck loads of stale session files which would slow down directory access and in turn slow down Odoo itself.