Re: [GENERAL] Emptying a database.

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: Andy Lewis <alewis(at)mpsi(dot)net>
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] Emptying a database.
Date: 1998-10-13 14:31:59
Message-ID: l03110702b24912e0762b@[194.90.105.243]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

At 15:49 +0200 on 13/10/98, Andy Lewis wrote:

> You wouldn't want to share your backup and restore scripts would you?

Well, they are not that brilliant. Their main merit is that the names of
all the tables and sequences are gathered together at the top of the file
so it's easy to add and drop tables and sequences, or adapt the script to
another database. The tables are dumped to separate files, named
<tablename>.dmp, located in the current working directory.

Run the script with the name of the database as command-line argument.

Backup:
=======

#!/bin/csh
#
set tables=(auth cat_link categories clct_cat collections links priv
session session_reserve)
set seqs=(category_no clct_no link_no sess_no)
#
if ( $#argv != 1 ) then
echo "usage: $0 dbname"
exit 1
endif
#
# dump tables
#
foreach table ( $tables )
echo "Now dumping table: $table"
pg_dump -f $table.dmp -a -t $table $1
end
#
# dump sequences
#
foreach seq ( $seqs )
echo "Now dumping sequence: $seq"
echo "DROP SEQUENCE $seq;" > $seq.dmp
pg_dump -a -t $seq $1 | sed '/\\connect/d' >> $seq.dmp
end

Restore:
========

#!/bin/csh
#
set tables=(auth cat_link categories clct_cat collections links priv
session session_reserve)
set seqs=(category_no clct_no link_no sess_no)
#
if ( $#argv != 1 ) then
echo "usage: $0 dbname"
exit 1
endif
#
# restore tables
#
foreach table ( $tables )
echo "Now restoring $table"
psql $1 < $table.dmp
end
#
# restore sequences
#
foreach seq ( $seqs )
echo "Now restoring sequence $seq"
psql $1 < $seq.dmp ;
end

(Sorry, the first shell languague I learned is csh, so that's what I use).

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Constantin Teodorescu 1998-10-13 14:47:07 Compiling errors on RedHat 5.1
Previous Message Herouth Maoz 1998-10-13 13:51:45 Re: [GENERAL] Making NULLs visible.