Here is a shell script for automating backup for Odoo 16:
#!/bin/bash # Define variables BACKUP_DIR=~/odoo_backups ODOO_DATABASE=db1 ADMIN_PASSWORD=superadmin_passwd # Create a backup directory if it doesn't exist mkdir -p ${BACKUP_DIR} # Create a backup of the Odoo database curl -X POST \ -F "master_pwd=${ADMIN_PASSWORD}" \ -F "name=${ODOO_DATABASE}" \ -F "backup_format=zip" \ -o ${BACKUP_DIR}/${ODOO_DATABASE}.$(date +%F).zip \ http://localhost:8069/web/database/backup # Delete old backups (older than 7 days) find ${BACKUP_DIR} -type f -mtime +7 -name "${ODOO_DATABASE}.*.zip" -delete
This script will create a backup of the Odoo database in ZIP format and store it in the BACKUP_DIR directory. The backup file will be named with the current date in the format YYYY-MM-DD. The script will also delete any backups that are older than 7 days.
To schedule this script to run automatically, you can use a cron job. For example, to run the script every day at midnight, you would add the following line to your crontab:
0 0 * * * /path/to/backup_odoo.sh
This will run the script every day at midnight and create a backup of the Odoo database. You can change the time that the script runs by changing the 0 0 part of the crontab entry.