Subversion Repositories scripts

[/] [backup_pgsql] - Rev 3

Compare with Previous | Blame | View Log

#!/bin/bash
#####################################
#
#       PostgreSQL Backup Script
#===================================
#
# Backs up the specified database to
# a file with the same name as the db
# and the data appended to the end
#
####################################

if [ $# != 1 ]; then
        echo ""
        echo "  PostgreSQL Backup Script"
        echo "  ------------------------"
        echo "Backs up Postgresql DB to file"
        echo ""
        echo "Usage:    $0 <database to backup> "
        echo ""
        exit
fi
#Define the backup directory, and target filename.
BACKUP_DIR="/tmp/"
FILENAME="$1"`eval date +%Y%m%d`

#Perform the backup.
pg_dump -f $BACKUP_DIR$FILENAME.sql -D -h localhost $1

#Change to the backup dir
cd $BACKUP_DIR

#Tar and Gzip the backup
tar -czf $BACKUP_DIR$FILENAME.tar.gz $FILENAME.sql

#Remove the plain text version.
rm -rf $FILENAME.sql

Compare with Previous | Blame | View Log