|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# pg_dumpaccounts |
| 4 | +# dumps the pg_shadow and pg_group tables, which belong to the |
| 5 | +# whole installation rather than any one individual database. |
| 6 | +# |
| 7 | +# $Header: /cvsroot/pgsql/contrib/pg_dumpaccounts/Attic/pg_dumpaccounts,v 1.1.2.1 2000/11/02 18:09:49 wieck Exp $ |
| 8 | +# |
| 9 | +# to adapt to System V vs. BSD 'echo' |
| 10 | +if echo '\\' | grep '\\\\' >/dev/null 2>&1 |
| 11 | +then |
| 12 | + BS='\' # BSD |
| 13 | +else |
| 14 | + BS='\\' # System V |
| 15 | +fi |
| 16 | +# |
| 17 | +# Dump everyone but the postgres user |
| 18 | +# initdb creates him |
| 19 | +# |
| 20 | +# get the postgres user id |
| 21 | +# |
| 22 | +POSTGRES_SUPER_USER_ID="`echo \" \ |
| 23 | + select datdba \ |
| 24 | + from pg_database \ |
| 25 | + where datname = 'template1'; \" | \ |
| 26 | + psql -A -q -t template1`" |
| 27 | +echo "${BS}connect template1" |
| 28 | +# |
| 29 | +# delete all users in case they run this twice |
| 30 | +# |
| 31 | +# we don't use POSTGRES_SUPER_USER_ID because the postgres super user id |
| 32 | +# could be different on the two installations |
| 33 | +# |
| 34 | +echo "select datdba into table tmp_pg_shadow \ |
| 35 | + from pg_database where datname = 'template1';" |
| 36 | +echo "delete from pg_shadow where usesysid <> tmp_pg_shadow.datdba;" |
| 37 | +echo "drop table tmp_pg_shadow;" |
| 38 | +# |
| 39 | +# load all the non-postgres users |
| 40 | +# XXX this breaks badly if the layout of pg_shadow ever changes. |
| 41 | +# It'd be better to convert the data into CREATE USER commands. |
| 42 | +# |
| 43 | +echo "copy pg_shadow from stdin;" |
| 44 | +psql -q template1 <<END |
| 45 | +select pg_shadow.* |
| 46 | +into table tmp_pg_shadow |
| 47 | +from pg_shadow |
| 48 | +where usesysid <> $POSTGRES_SUPER_USER_ID; |
| 49 | +copy tmp_pg_shadow to stdout; |
| 50 | +drop table tmp_pg_shadow; |
| 51 | +END |
| 52 | +echo "${BS}." |
| 53 | +# |
| 54 | +# copy the pg_group table too |
| 55 | +# XXX this breaks badly if the layout of pg_group ever changes. |
| 56 | +# It'd be better to convert the data into CREATE GROUP commands. |
| 57 | +# |
| 58 | +echo "delete from pg_group;" |
| 59 | +echo "copy pg_group from stdin;" |
| 60 | +psql -q template1 <<END |
| 61 | +copy pg_group to stdout; |
| 62 | +END |
| 63 | +echo "${BS}." |
| 64 | +
|
| 65 | +exit 0 |
0 commit comments