summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorBruce Momjian1998-08-30 05:06:54 +0000
committerBruce Momjian1998-08-30 05:06:54 +0000
commitc870be659029313eca1416f9bf40a85bf1f239f7 (patch)
tree46d3dcfd5f7694e7132a659faf7115de2b9d7881 /src/bin
parent7d7adf24e7b743e0fd7e6a7262475db964b5e865 (diff)
New pg_upgrade command.
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/pg_dump/Makefile.in3
-rwxr-xr-xsrc/bin/pg_dump/pg_upgrade87
2 files changed, 89 insertions, 1 deletions
diff --git a/src/bin/pg_dump/Makefile.in b/src/bin/pg_dump/Makefile.in
index 7aaa9a2f714..ca154026003 100644
--- a/src/bin/pg_dump/Makefile.in
+++ b/src/bin/pg_dump/Makefile.in
@@ -7,7 +7,7 @@
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/Makefile.in,v 1.9 1998/04/06 16:50:46 momjian Exp $
+# $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/Makefile.in,v 1.10 1998/08/30 05:06:53 momjian Exp $
#
#-------------------------------------------------------------------------
@@ -41,6 +41,7 @@ submake:
install: pg_dump
$(INSTALL) $(INSTL_EXE_OPTS) pg_dump $(BINDIR)/pg_dump
$(INSTALL) $(INSTL_EXE_OPTS) pg_dumpall $(BINDIR)/pg_dumpall
+ $(INSTALL) $(INSTL_EXE_OPTS) pg_upgrade $(BINDIR)/pg_upgrade
depend dep:
$(CC) -MM $(CFLAGS) *.c >depend
diff --git a/src/bin/pg_dump/pg_upgrade b/src/bin/pg_dump/pg_upgrade
new file mode 100755
index 00000000000..d65af38f680
--- /dev/null
+++ b/src/bin/pg_dump/pg_upgrade
@@ -0,0 +1,87 @@
+:
+trap "rm -f /tmp/$$" 0 1 2 3 15
+
+if [ "$#" -eq 0 ]
+then echo "Usage: $0 [-f inputfile] database" 1>&2
+ exit 1
+fi
+
+if [ "X$1" = "X-f" ]
+then INPUT="$2"
+ shift 2
+ if [ ! -f "$INPUT" ]
+ then echo "$INPUT does not exist" 1>&2
+ exit 1
+ fi
+else INPUT=""
+fi
+
+if [ "$#" -ne 1 ]
+then echo "Usage: $0 [-f input_file] database" 1>&2
+ exit 1
+fi
+
+DATABASE="$1"
+
+# check things
+
+if [ ! -f "./lib/global1.bki.source" ]
+then echo "$0 must be run from the top of the postgres directory tree." 1>&2
+ exit 1
+fi
+
+if [ ! -d "./data.upgrade" ]
+then echo "You must rename your old /data directory to /data.upgrade and run initdb." 1>&2
+ exit 1
+fi
+
+if [ ! -d "./data" ]
+then echo "You must run initdb to create the template1 database." 1>&2
+ exit 1
+fi
+
+if [ ! -d "./data/base/template1" ]
+then echo "$0 must be run as the postgres superuser." 1>&2
+ exit 1
+fi
+
+# do I need to create a database?
+
+if [ "$DATABASE" != "template1" ]
+then destroydb "$DATABASE"
+ createdb "$DATABASE"
+fi
+
+# remove COPY statements, preserve pgdump_oid setting from pg_dumpall
+
+cat $INPUT | awk ' {
+ if (toupper($0) ~ /^COPY / &&
+ toupper($0) !~ /^COPY[ ]*PGDUMP_OID/ )
+ while (getline $0 > 0 && $0 != "\\.")
+ ;
+ else print $0;
+ }' >/tmp/$$
+
+#create empty tables/indexes
+
+psql "$DATABASE" <"/tmp/$$"
+set -x
+
+for DIR in data/base/*
+do
+ BASEDIR="`basename $DIR`"
+ if [ -d "$DIR" -a \
+ -d "data.upgrade/$DIR" -a \
+ \( "$DATABASE" = "$BASEDIR" -o "$DATABASE" = "template1" \) ]
+ then for FILE in data.upgrade/$DIR/*
+ do
+ BASEFILE="`basename $FILE`"
+ if [ `expr "$BASEFILE" : "pg_"` -ne 3 -a \
+ "$BASEFILE" != "PG_VERSION" ]
+ then mv $FILE $DIR
+ fi
+ done
+ fi
+done
+
+echo "You may removed the data.upgrade directory with 'rm -r data.upgrade'."