Skip to content

Commit 4e15987

Browse files
authored
Merge pull request #1075 from signal18/staging-refresh-restore-slave-later
Enhance staging refresh script by setting to standalone first
2 parents 8e1a146 + ef9fb4f commit 4e15987

File tree

1 file changed

+41
-40
lines changed

1 file changed

+41
-40
lines changed

share/scripts/staging_refresh.sh

+41-40
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ echo $NB_SLAVES
3535

3636
# Scenario 1 : 2 slaves, then we will stop the replication on one that will be the "staging"
3737
if [ "$NB_SLAVES" -eq 2 ]; then
38-
echo "picking first slave \n"
39-
ID=$(get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/topology/slaves/index/1/attr/id | sed 's/"//g' )
40-
PORT=$(get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/topology/slaves/index/1/attr/port)
38+
echo "Picking a slave for staging \n"
39+
ID=$(get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/topology/slaves/index/0/attr/id | sed 's/"//g' )
40+
PORT=$(get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/topology/slaves/index/0/attr/port)
4141
echo "$ID:$PORT"
4242

43-
echo "Stopping first server slave replication \n"
43+
echo "Stopping slave $ID replication \n"
4444
get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/servers/$ID/actions/stop-slave
4545

4646
loop=true
@@ -73,7 +73,7 @@ fi
7373

7474
# Scenario 2 : 1 slave, then we will stop the replication on one that will be the "staging"
7575
if [ "$NB_SLAVES" -eq 1 ]; then
76-
echo "picking last slave and standalone id \n"
76+
echo "picking a slave and standalone \n"
7777
ID=$(get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/topology/state/standalone/index/0/attr/id | sed 's/"//g')
7878
ID_SLAVE=$(get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/topology/state/slave/index/0/attr/id | sed 's/"//g')
7979

@@ -82,7 +82,40 @@ if [ "$NB_SLAVES" -eq 1 ]; then
8282
exit 1
8383
fi
8484

85-
echo "found standalone server $ID \n"
85+
# Get the last available slave
86+
echo "Switching staging from STANDALONE $ID to SLAVE $ID_SLAVE \n"
87+
echo "Stopping replication on slave $ID_SLAVE \n"
88+
89+
get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/servers/$ID_SLAVE/actions/stop-slave
90+
91+
loop=true
92+
while $loop; do
93+
SV_STATE=$(get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/servers/$ID_SLAVE/attr/state | sed 's/"//g')
94+
if [ "$SV_STATE" != "Slave" ]; then
95+
loop=false
96+
97+
echo "Server $ID_SLAVE slave threads stopped \n"
98+
fi
99+
done
100+
101+
echo "Saving replication info in replication.save \n"
102+
get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/topology/servers/$ID_SLAVE/attr/replications > replications.save
103+
104+
echo "Reset all replication information \n"
105+
get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/servers/$ID_SLAVE/actions/reset-slave-all
106+
107+
loop=true
108+
while $loop; do
109+
SV_STATE=$(get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/servers/$ID_SLAVE/attr/state | sed 's/"//g')
110+
if [ "$SV_STATE" == "StandAlone" ]; then
111+
loop=false
112+
fi
113+
done
114+
115+
echo "$ID:$PORT is now standalone \n"
116+
117+
# Restore old standalone server to slave
118+
echo "Restore old standalone server $ID to slave \n"
86119
echo "reseting master position on standalone \n"
87120
get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/servers/$ID/actions/reset-master
88121
echo "setup replication manager for reseeding \n"
@@ -117,38 +150,6 @@ if [ "$NB_SLAVES" -eq 1 ]; then
117150
get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/settings/actions/switch/autoseed/off
118151
get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/settings/actions/switch/autorejoin-logical-backup/off
119152
get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/settings/actions/switch/autorejoin-force-restore/off
153+
fi
120154

121-
###### Now set last slave as standalone
122-
123-
# Get the last available slave
124-
echo "last slave found for staging $ID_SLAVE \n"
125-
echo "Stopping replication on last slave \n"
126-
127-
get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/servers/$ID_SLAVE/actions/stop-slave
128-
129-
loop=true
130-
while $loop; do
131-
SV_STATE=$(get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/servers/$ID_SLAVE/attr/state | sed 's/"//g')
132-
if [ "$SV_STATE" != "Slave" ]; then
133-
loop=false
134-
135-
echo "Server $ID_SLAVE slave threads stopped \n"
136-
fi
137-
done
138-
139-
echo "Saving replication info in replication.save \n"
140-
get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/topology/servers/$ID_SLAVE/attr/replications > replications.save
141-
142-
echo "Reset all replication information \n"
143-
get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/servers/$ID_SLAVE/actions/reset-slave-all
144-
145-
loop=true
146-
while $loop; do
147-
SV_STATE=$(get $REPLICATION_MANAGER_URL/api/clusters/$REPLICATION_MANAGER_CLUSTER_NAME/servers/$ID_SLAVE/attr/state | sed 's/"//g')
148-
if [ "$SV_STATE" == "StandAlone" ]; then
149-
loop=false
150-
fi
151-
done
152-
153-
echo "$ID:$PORT is now standalone \n"
154-
fi
155+
echo "Staging refresh done \n"

0 commit comments

Comments
 (0)