22trap "rm -f /tmp/$$" 0 1 2 3 15
33
44if [ "$#" -eq 0 ]
5- thenecho "Usage: $0 [-f inputfile] database" 1>&2
5+ thenecho "Usage: $0 [-f inputfile]old_data_dir database" 1>&2
66exit 1
77fi
88
@@ -16,12 +16,13 @@ thenINPUT="$2"
1616elseINPUT=""
1717fi
1818
19- if [ "$#" -ne1 ]
20- thenecho "Usage: $0 [-f input_file] database" 1>&2
19+ if [ "$#" -ne2 ]
20+ thenecho "Usage: $0 [-f input_file]old_data_dir database" 1>&2
2121exit 1
2222fi
2323
24- DATABASE="$1"
24+ OLDDIR="$1"
25+ DATABASE="$2"
2526
2627# check things
2728
@@ -30,8 +31,13 @@ thenecho "$0 must be run from the top of the postgres directory tree." 1>&2
3031exit 1
3132fi
3233
33- if [ ! -d "./data.upgrade" ]
34- thenecho "You must rename your old /data directory to /data.upgrade and run initdb." 1>&2
34+ if [ ! -d "./$OLDDIR" ]
35+ thenecho "You must rename your old /data directory to /$OLDDIR and run initdb." 1>&2
36+ exit 1
37+ fi
38+
39+ if [ ! -d "./$OLDDIR/data/base/$DATABASE" ]
40+ thenecho "There is not database $DATABASE in ./$OLDDIR/data/base." 1>&2
3541exit 1
3642fi
3743
4854# do I need to create a database?
4955
5056if [ "$DATABASE" != "template1" ]
51- thendestroydb "$DATABASE"
57+ thenecho "Dropping and recreating database $DATABASE." 1>&2
58+ destroydb "$DATABASE" >/dev/null 2>&1
5259createdb "$DATABASE"
5360fi
5461
55- # remove COPY statements, preserve pgdump_oid setting from pg_dumpall
62+ # removeany COPY statements, preserve pgdump_oid setting from pg_dumpall
5663
5764cat $INPUT | awk '{
5865if (toupper($0) ~ /^COPY / &&
@@ -71,9 +78,9 @@ for DIR in data/base/*
7178do
7279BASEDIR="`basename $DIR`"
7380if [ -d "$DIR" -a \
74- -d "data.upgrade /$DIR" -a \
81+ -d "$OLDDIR /$DIR" -a \
7582\( "$DATABASE" = "$BASEDIR" -o "$DATABASE" = "template1" \) ]
76- thenfor FILE indata.upgrade /$DIR/*
83+ thenfor FILE in$OLDDIR /$DIR/*
7784do
7885BASEFILE="`basename $FILE`"
7986if [ `expr "$BASEFILE" : "pg_"` -ne 3 -a \
8491fi
8592done
8693
87- echo "You may removed thedata.upgrade directory with 'rm -rdata.upgrade '."
94+ echo "You may removed the$OLDDIR directory with 'rm -r$OLDDIR '."