-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexpand.sh
More file actions
executable file
·181 lines (169 loc) · 3.5 KB
/
expand.sh
File metadata and controls
executable file
·181 lines (169 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash
set -e
PWD=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
parallel=$1
if [[ "$parallel" == "" ]]; then
echo "Please provide how much parallelism."
echo "Example:"
echo "./expand.sh 10"
exit 1
fi
if [ "$MASTER_DATA_DIRECTORY" == "" ]; then
echo "MASTER_DATA_DIRECTORY is not set!"
exit 1
fi
if [ "$PGDATABASE" == "" ]; then
PGDATABASE="gpadmin"
fi
read -r -p "Is this a new expansion? (Yes or No)" response
case $response in
[yY][eE][sS]|[yY])
echo "Removing any logs from previous expansion."
echo "rm -f $PWD/log/end_expand_*"
rm -f $PWD/log/end_expand_*
echo "rm -f $PWD/gpexpand_inputfile*"
rm -f $PWD/gpexpand_inputfile*
;;
*)
echo "Continue..."
;;
esac
check_faultstrategy()
{
gp_fault_strategy=$(psql -t -A -c "select fault_strategy from gp_fault_strategy")
if [ "$gp_fault_strategy" == "n" ]; then
echo "Mirroring disabled."
echo "Continue..."
else
echo "Mirroring enabled! Please run remove_mirroring.sh and then a full backup before expanding!"
exit 1
fi
}
backupdb()
{
end="$PWD""/log/end_expand_backup.log"
if [ ! -f "$end" ]; then
gpcrondump -x $PGDATABASE -a -c -g -G -C
touch "$end"
else
echo "Database already backed up."
fi
}
checkbackup()
{
if [ -d $MASTER_DATA_DIRECTORY/db_dumps/ ]; then
echo "The latest backup will be used if you wish to shrink the database. Here are the backup directories:"
for i in $(ls $MASTER_DATA_DIRECTORY/db_dumps/); do
echo $i
done
else
echo "No backups found!"
read -r -p "Do you want to execute a backup now? (Yes or No)" response
case $response in
[yY][eE][sS]|[yY])
echo "Executing backup..."
backupdb
;;
*)
echo "Can not continue without a valid backup."
exit 1
;;
esac
fi
}
stopdb()
{
counter=$(ps -ef | grep postgres | grep "\-D" | wc -l)
if [ "$counter" -gt "0" ]; then
gpstop -a -M fast
else
echo "Database already stopped."
fi
}
startdb()
{
counter=$(ps -ef | grep postgres | grep "\-D" | wc -l)
if [ "$counter" -eq "0" ]; then
gpstart -a
else
echo "Database already started."
fi
}
createifile()
{
gpexpand -D $PGDATABASE
}
getifilename()
{
ifile=""
count=$(ls $PWD/gpexpand_inputfile_* 2> /dev/null | wc -l)
if [ "$count" -eq "1" ]; then
ifile=$(ls $PWD/gpexpand_inputfile_*)
fi
}
expandcluster()
{
end="$PWD""/log/end_expand_cluster.log"
if [ ! -f "$end" ]; then
cat $ifile
echo ""
read -r -p "Does the expansion file look correct? (Yes or No)" response
case $response in
[yY][eE][sS]|[yY])
echo "Continue..."
;;
*)
rm -f $ifile
exit 1
;;
esac
#this expands the cluster
echo "gpexpand -i $ifile -D $PGDATABASE"
gpexpand -i $ifile -D $PGDATABASE
touch "$end"
else
echo "Database already expanded."
fi
}
redistribute()
{
end="$PWD""/log/end_expand_redistribute.log"
if [ ! -f "$end" ]; then
#redistribute the data with n parallel processes
echo "gpexpand -D $PGDATABASE -n $parallel"
gpexpand -D $PGDATABASE -n $parallel
touch "$end"
else
echo "Database already redistributed."
fi
}
analyze()
{
end="$PWD""/log/end_expand_analyze.log"
if [ ! -f "$end" ]; then
#analyze the database
echo "analyzedb -d $PGDATABASE -a -p $parallel"
analyzedb -d $PGDATABASE -a -p $parallel
touch "$end"
else
echo "Database already analyzed."
fi
}
startdb
check_faultstrategy
checkbackup
getifilename
if [ "$ifile" == "" ]; then
createifile
fi
getifilename
if [ "$ifile" == "" ]; then
echo "Expand file not created!"
exit 1
else
echo "ifile: $ifile"
fi
expandcluster
redistribute
analyze
echo "Expansion complete!"