Re: Automated Backup

From: <btober(at)seaworthysys(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Automated Backup
Date: 2003-09-19 08:37:30
Message-ID: 64812.66.212.203.144.1063960650.squirrel@$HOSTNAME
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

>
>> Is there a way to automate the backup databases using pg_dump (like
>> in SQL server)?
>

Ha! Why would you want to do ANYTHING "like in SQL server"! ;)

You can do you back-ups very nicely using cron and a bash script:

bash-2.05a$ crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.22116 installed on Fri Jun 13 10:41:06 2003)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
11 02 * * 1-6 /usr/local/bin/dump paid postgres(at)btober(dot)com

Slightly edited, but illustrates the point:

bash-2.05a$ cat /usr/local/bin/dump
#!/bin/bash
# Script to dump a PostgreSQL database, producing
# compressed tar file containing with pg_dump output.
# Author: Berend M. Tober <btober-at-computer-dot-org>
# Date: August 25, 2003

if [ "${1}" = "" ]
then
echo "Must specify database name"
exit 0
fi

# setup variables

NAIL=/usr/local/bin/nail
PG_DUMP=/usr/bin/pg_dump
TAR=/bin/tar

DBNAME=${1}
UNAME=postgres
TARGET_EMAIL=${2}

OUTPUT_FILE=${DBNAME}.`date +%Y%m%d`

# create dump file

${PG_DUMP} -Fc -U ${UNAME} ${DBNAME} > ~/${OUTPUT_FILE}.dump

# create compressed archive of dump (and other) files

${TAR} -czf ~/${OUTPUT_FILE}.tar.gz ${OUTPUT_FILE}.dump

# above line uses tar rather than just gzip
# because in reality other files are included in
# my backup archive but which have been omitted
# in this mailing list post for simplicity.

# optionally mail the back-up archive offsite
if [ "${2}" != "" ]
then
echo|${NAIL} -r ${UNAME} -a ~/${OUTPUT_FILE}.tar.gz -s
${OUTPUT_FILE}.tar.gz ${2}
fi

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Paul Thomas 2003-09-19 09:38:57 Re: virus warning
Previous Message Richard Huxton 2003-09-19 08:34:14 Re: virus warning