2
2
trap "rm -f /tmp/$$" 0 1 2 3 15
3
3
4
4
if [ "$#" -eq 0 ]
5
- then echo "Usage: $0 [-f inputfile] database" 1>&2
5
+ then echo "Usage: $0 [-f inputfile] old_data_dir database" 1>&2
6
6
exit 1
7
7
fi
8
8
@@ -16,12 +16,13 @@ then INPUT="$2"
16
16
else INPUT=""
17
17
fi
18
18
19
- if [ "$#" -ne 1 ]
20
- then echo "Usage: $0 [-f input_file] database" 1>&2
19
+ if [ "$#" -ne 2 ]
20
+ then echo "Usage: $0 [-f input_file] old_data_dir database" 1>&2
21
21
exit 1
22
22
fi
23
23
24
- DATABASE="$1"
24
+ OLDDIR="$1"
25
+ DATABASE="$2"
25
26
26
27
# check things
27
28
@@ -30,8 +31,13 @@ then echo "$0 must be run from the top of the postgres directory tree." 1>&2
30
31
exit 1
31
32
fi
32
33
33
- if [ ! -d "./data.upgrade" ]
34
- then echo "You must rename your old /data directory to /data.upgrade and run initdb." 1>&2
34
+ if [ ! -d "./$OLDDIR" ]
35
+ then echo "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
+ then echo "There is not database $DATABASE in ./$OLDDIR/data/base." 1>&2
35
41
exit 1
36
42
fi
37
43
48
54
# do I need to create a database?
49
55
50
56
if [ "$DATABASE" != "template1" ]
51
- then destroydb "$DATABASE"
57
+ then echo "Dropping and recreating database $DATABASE." 1>&2
58
+ destroydb "$DATABASE" >/dev/null 2>&1
52
59
createdb "$DATABASE"
53
60
fi
54
61
55
- # remove COPY statements, preserve pgdump_oid setting from pg_dumpall
62
+ # remove any COPY statements, preserve pgdump_oid setting from pg_dumpall
56
63
57
64
cat $INPUT | awk ' {
58
65
if (toupper($0) ~ /^COPY / &&
@@ -71,9 +78,9 @@ for DIR in data/base/*
71
78
do
72
79
BASEDIR="`basename $DIR`"
73
80
if [ -d "$DIR" -a \
74
- -d "data.upgrade /$DIR" -a \
81
+ -d "$OLDDIR /$DIR" -a \
75
82
\( "$DATABASE" = "$BASEDIR" -o "$DATABASE" = "template1" \) ]
76
- then for FILE in data.upgrade /$DIR/*
83
+ then for FILE in $OLDDIR /$DIR/*
77
84
do
78
85
BASEFILE="`basename $FILE`"
79
86
if [ `expr "$BASEFILE" : "pg_"` -ne 3 -a \
84
91
fi
85
92
done
86
93
87
- echo "You may removed the data.upgrade directory with 'rm -r data.upgrade '."
94
+ echo "You may removed the $OLDDIR directory with 'rm -r $OLDDIR '."
0 commit comments