Re: Shell Script help for backup

From: ratlhead(at)ratlhead(dot)com (ratlhead)
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Shell Script help for backup
Date: 2002-07-22 22:35:01
Message-ID: fd9c5ab3.0207221435.59e89f99@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

This is how I ended up solving my problem. Not sure if any of this
will help you, but here's the scripts I use. This is what it does...

-Uses PG environmental variables to connect to the PG server
-Dumps the specified database
-Checks the backup folder for any backups older than a week and
deletes those
-Checks to be sure the backup was successful by checking for a 0k file
for that day
-Sends email saying if backup was successful or failed
-If successful, checks the day and if it's Saturday, uploads most
current backup to specified ftp site
-.netrc file required for FTP connection

##### pg_backup.sh #####
#!/bin/bash
DATE=`date +%Y-%m-%d`
PGUSER=<my user>
PGPASSWORD=<my pass>
export PGUSER PGPASSWORD
/path/pg_dump <db name> | gzip > /path/pg_backup.$DATE.gzip
find /path/pg_backup/* -mtime 7 -exec rm -f {} \;
if test -s /path/pg_backup/pg_backup.$DATE.gzip
then
echo "The PostGreSQL backup for today was successful!" | mailx -s
"PostGreSQ
L backup successful" <email address>
/path/day_pg.sh
else
echo "The PostGreSQL backup for today failed!" | mail -s
"PostGreSQL backup
failed" <email address>
fi

##### day_pg.sh #####
DAY=`date +%a`
if [ $DAY = "Sat" ]
then
/path/upload_pg.sh
fi

##### upload_pg #####
DATE=`date +%Y-%m-%d`
ftp <host> << EOF
cd path
put /path/pg_backup.$DATE.gzip pg_backup.$DATE.gzip
quit
EOF

##### .netrc #####
machine <host> login <username> password <password>

-Mike Graben
ratlhead(at)ratlhead(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message srinu kulkarni 2002-07-22 22:35:02 How to increase the speed of database access when using libpq++
Previous Message Josh Berkus 2002-07-22 20:53:20 Re: Editor for pgsql