Skip site navigation (1) Skip section navigation (2)

Re: pg_restore test procedures (a bit OT)

From: "Phillip Smith" <phillip(dot)smith(at)weatherbeeta(dot)com(dot)au>
To: "'Glyn Astill'" <glynastill(at)yahoo(dot)co(dot)uk>,<pgsql-admin(at)postgresql(dot)org>
Subject: Re: pg_restore test procedures (a bit OT)
Date: 2008-05-19 00:05:03
Message-ID: 003401c8b944$03e827c0$9b0014ac@wbaus090 (view raw or whole thread)
Lists: pgsql-admin
> I was just wondering if anyone has any clever way of testing their backups
taken with pg_dump on a daily basis?
I have a daily bash script to backup of one of my databases to file, then
file to tape, which I test restore once per week. I've changed some of my
variables to hard-coded strings to make it shorter and easier to understand
at a quick read. Yes I know it's kinda fschked but it's working atm. I'll
tidy it up eventually....

if [ "$DAY" = "Mon" ] ; then
	echo "Test restoring database..." >> $LOG_FILE

	if [ 1 -eq 1 ] ; then
		# Debugging
		$ECHO "Restoring from:           ${BACKUP_PATH}"
		$ECHO "Restoring to Directory:   ${TMPDNAME}"
		$ECHO "Restore Database:         ${DBNAME}${DATESTRING}"
		$ECHO "Restore Source File:      ${TMPFILE}"

	echo -n "Extracting database dump from tape... "
	tar xf /dev/st0 --directory /tmp
	if [ $? -ne 0 ] ; then
		echo "FAIL"
		echo "   Failed to Restore from /dev/st0 to /tmp/" >>

	if [ ${SHOW_ERR} != true ] ; then
		### Note: $DATESTRING = yymmdd (eg. 080519)
		echo "Creating new database ${DBNAME}${DATESTRING}" >>
		/usr/local/bin/psql --command "CREATE DATABASE
		if [ $? -eq 0 ] ; then
			echo "Restoring /tmp/psqldump.sql.502 to
			/usr/local/bin/psql ${DBNAME}${DATESTRING} <
			echo "Failed to Create Database!" >> $LOG_FILE

> su - $PGUSER -c "pg_restore -h localhost -U postgres --disable-triggers -c
-d $database $backup_dir/$server-$database-data.gz" >> $logfile
> or 
> su - $PGUSER -c "pg_restore -h localhost -U postgres --disable-triggers -c
-d $database $backup_dir/$server-$database-data.gz >> $logfile"

Perhaps something like this: (it's Monday morning, so I might be suggesting
something stupid)
LOG=`su - $PGUSER -c "pg_restore -h localhost -U postgres --disable-triggers
-c -d $database $backup_dir/$server-$database-data.gz"`
echo $LOG >> $logfile

THINK BEFORE YOU PRINT - Save paper if you don't really need to print this

*******************Confidentiality and Privilege Notice*******************

The material contained in this message is privileged and confidential to
the addressee.  If you are not the addressee indicated in this message or
responsible for delivery of the message to such person, you may not copy
or deliver this message to anyone, and you should destroy it and kindly
notify the sender by reply email.

Information in this message that does not relate to the official business
of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta.
Weatherbeeta, its employees, contractors or associates shall not be liable
for direct, indirect or consequential loss arising from transmission of this
message or any attachments

In response to

pgsql-admin by date

Next:From: Glyn AstillDate: 2008-05-19 11:03:28
Subject: Re: pg_restore test procedures (a bit OT)
Previous:From: Joshua D. DrakeDate: 2008-05-16 21:25:30
Subject: Re: Global / cluster-wide functions

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group