#!/bin/sh

# Database backup script
# Backup use postgres pg_dump command:
# pg_dump -U <user> -Fc <db> > <DB_DUMP_FILE>
# To restore, use postgres pg_restore command:
# pg_restore -d postgres <DB_DUMP_FILE> HOST_IP=`/sbin/ifconfig | sed -n 's/.*inet addr:\([0-9.]\+\)\s.*/\1/p' | head -n1`
POSTGRES_HOME=/opt/postgres
BACKUP_DIR=/backup/$HOST_IP
BACKUP_FILENAME_PREFIX="db_backup_"
CURRENT_TIME=`date +'%Y-%m-%d_%H%M%S'`
KEEP_DAYS= mkdir -p $BACKUP_DIR BACKUP_FILE=$BACKUP_DIR/$BACKUP_FILENAME_PREFIX$CURRENT_TIME.dump echo "`date` starting database backup: $BACKUP_FILE" #full database backup
$POSTGRES_HOME/bin/pg_dump -U postgres -Fc postgres > $BACKUP_FILE echo "`date` database backup completed: $BACKUP_FILE" #delete files older than $KEEP_DAYS
find $BACKUP_DIR -mtime +$KEEP_DAYS -exec rm {} \;
05-28 09:11