summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Wieck2000-11-02 18:09:49 +0000
committerJan Wieck2000-11-02 18:09:49 +0000
commitbfecc6a5248a50dce5846b3e9781172da0a4634b (patch)
tree0ac3202314eb753f80c5e0e0c19f320282119ad4
parent5d547cd236cc8b674bc356f91178994b0169ca23 (diff)
Added pg_dumpaccounts utility script in contrib.
Derived from pg_dumpall it just dumps the pg_shadow and pg_group contents. Jan
-rw-r--r--contrib/pg_dumpaccounts/Makefile21
-rw-r--r--contrib/pg_dumpaccounts/README9
-rw-r--r--contrib/pg_dumpaccounts/pg_dumpaccounts65
3 files changed, 95 insertions, 0 deletions
diff --git a/contrib/pg_dumpaccounts/Makefile b/contrib/pg_dumpaccounts/Makefile
new file mode 100644
index 00000000000..264ba3a4a94
--- /dev/null
+++ b/contrib/pg_dumpaccounts/Makefile
@@ -0,0 +1,21 @@
+#-------------------------------------------------------------------------
+#
+# Makefile --
+#
+# Makefile for contrib pg_dumpaccounts.
+#
+#-------------------------------------------------------------------------
+
+PGDIR = ../..
+SRCDIR = $(PGDIR)/src
+
+include $(SRCDIR)/Makefile.global
+
+all:
+
+install:
+ $(INSTALL) $(INSTL_EXE_OPTS) pg_dumpaccounts $(BINDIR)/pg_dumpaccounts
+
+clean:
+
+distclean: clean
diff --git a/contrib/pg_dumpaccounts/README b/contrib/pg_dumpaccounts/README
new file mode 100644
index 00000000000..348129934f8
--- /dev/null
+++ b/contrib/pg_dumpaccounts/README
@@ -0,0 +1,9 @@
+pg_dumpaccounts
+
+This is a little utility script derived from pg_dumpall. It just
+dumps the global pg_shadow and pg_group as pg_dumpall does without
+dumping any of the databases. This is useful for installations
+that have many databases with different backup schedules, where
+pg_dumpall will never be run and thus, the users and groups will
+never be backed up.
+
diff --git a/contrib/pg_dumpaccounts/pg_dumpaccounts b/contrib/pg_dumpaccounts/pg_dumpaccounts
new file mode 100644
index 00000000000..8bae0a4f12f
--- /dev/null
+++ b/contrib/pg_dumpaccounts/pg_dumpaccounts
@@ -0,0 +1,65 @@
+#!/bin/sh
+#
+# pg_dumpaccounts
+# dumps the pg_shadow and pg_group tables, which belong to the
+# whole installation rather than any one individual database.
+#
+# $Header: /cvsroot/pgsql/contrib/pg_dumpaccounts/Attic/pg_dumpaccounts,v 1.1.2.1 2000/11/02 18:09:49 wieck Exp $
+#
+# to adapt to System V vs. BSD 'echo'
+if echo '\\' | grep '\\\\' >/dev/null 2>&1
+then
+ BS='\' # BSD
+else
+ BS='\\' # System V
+fi
+#
+# Dump everyone but the postgres user
+# initdb creates him
+#
+# get the postgres user id
+#
+POSTGRES_SUPER_USER_ID="`echo \" \
+ select datdba \
+ from pg_database \
+ where datname = 'template1'; \" | \
+ psql -A -q -t template1`"
+echo "${BS}connect template1"
+#
+# delete all users in case they run this twice
+#
+# we don't use POSTGRES_SUPER_USER_ID because the postgres super user id
+# could be different on the two installations
+#
+echo "select datdba into table tmp_pg_shadow \
+ from pg_database where datname = 'template1';"
+echo "delete from pg_shadow where usesysid <> tmp_pg_shadow.datdba;"
+echo "drop table tmp_pg_shadow;"
+#
+# load all the non-postgres users
+# XXX this breaks badly if the layout of pg_shadow ever changes.
+# It'd be better to convert the data into CREATE USER commands.
+#
+echo "copy pg_shadow from stdin;"
+psql -q template1 <<END
+select pg_shadow.*
+into table tmp_pg_shadow
+from pg_shadow
+where usesysid <> $POSTGRES_SUPER_USER_ID;
+copy tmp_pg_shadow to stdout;
+drop table tmp_pg_shadow;
+END
+echo "${BS}."
+#
+# copy the pg_group table too
+# XXX this breaks badly if the layout of pg_group ever changes.
+# It'd be better to convert the data into CREATE GROUP commands.
+#
+echo "delete from pg_group;"
+echo "copy pg_group from stdin;"
+psql -q template1 <<END
+copy pg_group to stdout;
+END
+echo "${BS}."
+
+exit 0