Subversion Repositories scripts

[/] [backup_pgsql] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1 nick
#!/bin/bash
2
#####################################
3
#
4
#       PostgreSQL Backup Script
5
#===================================
6
#
7
# Backs up the specified database to
8
# a file with the same name as the db
9
# and the data appended to the end
10
#
11
####################################
12
 
13
if [ $# != 1 ]; then
14
        echo ""
15 2 nick
        echo "  PostgreSQL Backup Script"
16
        echo "  ------------------------"
17 1 nick
        echo "Backs up Postgresql DB to file"
18
        echo ""
19
        echo "Usage:    $0 <database to backup> "
20
        echo ""
21
        exit
22
fi
23
#Define the backup directory, and target filename.
24 3 nick
BACKUP_DIR="/tmp/"
25 1 nick
FILENAME="$1"`eval date +%Y%m%d`
26
 
27
#Perform the backup.
28
pg_dump -f $BACKUP_DIR$FILENAME.sql -D -h localhost $1
29
 
30 2 nick
#Change to the backup dir
31 1 nick
cd $BACKUP_DIR
32
 
33 2 nick
#Tar and Gzip the backup
34 1 nick
tar -czf $BACKUP_DIR$FILENAME.tar.gz $FILENAME.sql
35
 
36 2 nick
#Remove the plain text version.
37 1 nick
rm -rf $FILENAME.sql