odoo/ext/scripts/odoo-backup.sh

34 lines
689 B
Bash
Executable File

#!/bin/sh
#dump the OpenERP DB (postgreSQL)
#author: Camadeus GmbH
hostname=`/bin/hostname`
dbnames=`psql -d postgres -c "SELECT datname FROM pg_database WHERE NOT datistemplate AND datname <> 'postgres'" --tuples-only`
# Dump DBs
for db in $dbnames
do
echo "creating backup for db: " $db
date=`date +"%Y%m%d_%H%M%N"`
filename="/var/pgdump/${hostname}_${db}_${date}.sql"
pg_dump -E UTF-8 -F p -b -f $filename $db
chmod 600 $filename
gzip $filename
done
##########################################
## Housekeeping
##########################################
for file in `find /var/pgdump/ -mtime +30 -type f -name '*.sql.gz'`
do
echo "deleting: " $file
rm $file
done
exit 0