You are on page 1of 1

# Backup script starts here.

#!/bin/bash
# Location of the backup logfile.
logfile="/home/1440/ERP/backup/logfile.log"
# Location to place backups.
backup_dir="/home/1440/ERP/backup"
touch $logfile
timeslot=`date +%d%m%y%H%M%S`
databases=`psql -U postgres -q -c "\l" | awk '{ print $1}' | grep -vE '^\||^-|
^List|^Name|template[0|1]|^\(''
for i in $databases; do
timeinfo=`date '+%T %x'`
echo "Backup and Vacuum started at $timeinfo for time slot $timeslot on data
base: $i " >>
$logfile
/usr/bin/vacuumdb -z -U postgres $i >/dev/null 2>&1
/usr/bin/pg_dump $i -U postgres | gzip > "$backup_dir/openerp-$i-$timeslot-d
atabase.gz"
timeinfo=`date '+%T %x'`
echo "Backup and Vacuum complete at $timeinfo for time slot $timeslot on dat
abase: $i " >> $logfile
done
#------------------------------------------------# delete files more than 10 days old
find $backup_dir/openerp* -mtime +10 -exec rm {} \;