Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbfecc6a

Browse files
Jan WieckJan Wieck
Jan Wieck
authored and
Jan Wieck
committed
Added pg_dumpaccounts utility script in contrib.
Derived from pg_dumpall it just dumps the pg_shadow andpg_group contents.Jan
1 parent5d547cd commitbfecc6a

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

‎contrib/pg_dumpaccounts/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#-------------------------------------------------------------------------
2+
#
3+
# Makefile --
4+
#
5+
# Makefile for contrib pg_dumpaccounts.
6+
#
7+
#-------------------------------------------------------------------------
8+
9+
PGDIR = ../..
10+
SRCDIR =$(PGDIR)/src
11+
12+
include$(SRCDIR)/Makefile.global
13+
14+
all:
15+
16+
install:
17+
$(INSTALL)$(INSTL_EXE_OPTS) pg_dumpaccounts$(BINDIR)/pg_dumpaccounts
18+
19+
clean:
20+
21+
distclean:clean

‎contrib/pg_dumpaccounts/README

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pg_dumpaccounts
2+
3+
This is a little utility script derived from pg_dumpall. It just
4+
dumps the global pg_shadow and pg_group as pg_dumpall does without
5+
dumping any of the databases. This is useful for installations
6+
that have many databases with different backup schedules, where
7+
pg_dumpall will never be run and thus, the users and groups will
8+
never be backed up.
9+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
ifecho'\\'| grep'\\\\'>/dev/null2>&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+
selectdatdba \
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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp