Odoo 9 Linux bash backup script

github

Bash backup odoo script is available on GitHub for Odoo 8 and 11.

This bash script will help you to backup Odoo database, set a password on the backup file and remove files older than 7 days. You’ll need curl and 7zip linux package to make it work. This example is backing up od11-01 and od11-02 databases. It’s not really optimized with the double compression.
BACKUP_DIR=/opt/backup
ODOO_DATABASES="od11-01 od11-02"
ADMIN_PASSWORD="ODOO_DATABASE_MANAGER_PASSORD"
FILE_PASSWORD="ZIP_FILE_PASSWORD"
TIMESTAMP=`date +%Y-%m-%d_%H-%M-%S`

for DB in ${ODOO_DATABASES}
do
# create a backup
curl -X POST \
    -F "master_pwd=${ADMIN_PASSWORD}" \
    -F "name=${DB}" \
    -F "backup_format=zip" \
    -o ${BACKUP_DIR}/${DB}/${DB}.${TIMESTAMP}.zip \
    http://localhost:8069/web/database/backup

7z a -p${FILE_PASSWORD} -y ${BACKUP_DIR}/${DB}/${DB}.${TIMESTAMP}.zip.7z ${BACKUP_DIR}/${DB}/${DB}.${TIMESTAMP}.zip

7z t -p${FILE_PASSWORD} -y ${BACKUP_DIR}/${DB}/${DB}.${TIMESTAMP}.zip.7z

rm -rf ${BACKUP_DIR}/${DB}/${DB}.${TIMESTAMP}.zip

find ${BACKUP_DIR}/${DB} -type f -mtime +7 -name "${DB}.*.zip*" -delete
done
POST HTML variables in this example is working for Odoo 9 version, for older or newer version of Odoo, those variables might be different. To get the right variables for your Odoo version, reach the database manager and get your field’s name from the code source of the backup form page.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.