Skip to content

Commit a1fc51b

Browse files
committed
Use k8s 1.34 client libs
Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent 6e67e90 commit a1fc51b

7 files changed

Lines changed: 103 additions & 106 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
if [ -f /scripts/backup_data_stream_pod_ip.txt ]; then
4-
echo -n "Yes"
4+
echo -n "Yes"
55
else
6-
echo -n "No"
7-
fi
6+
echo -n "No"
7+
fi

scripts/backup-stream.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env bash
22

3-
ip=$(cat "/scripts/backup_data_stream_pod_ip.txt")
4-
echo "Start master data transferring..ip $ip"
5-
export MYSQL_PWD="$MYSQL_ROOT_PASSWORD"
6-
mariabackup --backup --stream=mbstream --user=root | socat -u STDIN TCP:$ip:3307
7-
if [ $? -eq 0 ]; then
8-
echo "Backup data for pod $ip transferred successfully."
9-
else
10-
echo "Backup data transfer for pod $ip failed."
11-
fi
12-
rm /scripts/backup_data_stream_pod_ip.txt
3+
ip=$(cat "/scripts/backup_data_stream_pod_ip.txt")
4+
echo "Start master data transferring..ip $ip"
5+
export MYSQL_PWD="$MYSQL_ROOT_PASSWORD"
6+
mariabackup --backup --stream=mbstream --user=root | socat -u STDIN TCP:$ip:3307
7+
if [ $? -eq 0 ]; then
8+
echo "Backup data for pod $ip transferred successfully."
9+
else
10+
echo "Backup data transfer for pod $ip failed."
11+
fi
12+
rm /scripts/backup_data_stream_pod_ip.txt

scripts/copy-data.sh

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@ TOTAL_DIR_TO_COPY="$TOTAL_DIR_TO_COPY"
55
DATA_DIR="$DATA_DIR"
66

77
if [ -z "$ROOT_DIR" ] || [ -z "$TOTAL_DIR_TO_COPY" ]; then
8-
echo "ROOT_DIR and TOTAL_DIR_TO_COPY must be set."
9-
exit 1
8+
echo "ROOT_DIR and TOTAL_DIR_TO_COPY must be set."
9+
exit 1
1010
fi
1111
Size1=$(du -s "$ROOT_DIR" | cut -f1)
1212
echo "DATA DIRECTORY SIZE: ", $Size1
13-
for (( i = 1; i <= $TOTAL_DIR_TO_COPY; i++ ));do
14-
if [[ -d "$ROOT_DIR$i" ]];then
15-
Size2=$(du -s "$ROOT_DIR$i" | cut -f1)
16-
echo $Size1, " ", $Size2
17-
if [[ "$Size1" == "$Size2" ]];then
18-
continue
13+
for ((i = 1; i <= $TOTAL_DIR_TO_COPY; i++)); do
14+
if [[ -d "$ROOT_DIR$i" ]]; then
15+
Size2=$(du -s "$ROOT_DIR$i" | cut -f1)
16+
echo $Size1, " ", $Size2
17+
if [[ "$Size1" == "$Size2" ]]; then
18+
continue
19+
fi
20+
fi
21+
# not deleting any data
22+
# because the sole purpose of this script is to copy the data
23+
# rm -rf "$ROOT_DIR$i"/*
24+
rm "$ROOT_DIR/mysql.sock"
25+
cp -rvL "$ROOT_DIR/"* "$ROOT_DIR$i"/
26+
if [[ $? -ne 0 ]]; then
27+
echo "Error occurred while copying to $ROOT_DIR$i"
28+
exit 1
1929
fi
20-
fi
21-
# not deleting any data
22-
# because the sole purpose of this script is to copy the data
23-
# rm -rf "$ROOT_DIR$i"/*
24-
rm "$ROOT_DIR/mysql.sock"
25-
cp -rvL "$ROOT_DIR/"* "$ROOT_DIR$i"/
26-
if [[ $? -ne 0 ]]; then
27-
echo "Error occurred while copying to $ROOT_DIR$i"
28-
exit 1
29-
fi
3030
done
3131

32-
exit 0
32+
exit 0

scripts/ensure-restore.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#!/usr/bin/env bash
22

33
if [[ "$PITR_RESTORE" == "true" ]]; then
4-
if [[ "$HOSTNAME" != *"-0" ]]; then
5-
if [[ -f /var/lib/mysql/gvwstate.dat ]]; then
6-
rm /var/lib/mysql/gvwstate.dat
4+
if [[ "$HOSTNAME" != *"-0" ]]; then
5+
if [[ -f /var/lib/mysql/gvwstate.dat ]]; then
6+
rm /var/lib/mysql/gvwstate.dat
7+
fi
78
fi
8-
fi
99
fi
1010

1111
RECOVERY_DONE_FILE="/tmp/recovery.done"
1212
if [[ "$PITR_RESTORE" == "true" ]]; then
1313
while true; do
14-
sleep 2
15-
echo "Point In Time Recovery In Progress. Waiting for $RECOVERY_DONE_FILE file"
16-
if [[ -e "$RECOVERY_DONE_FILE" ]]; then
17-
echo "$RECOVERY_DONE_FILE found."
18-
break
19-
fi
14+
sleep 2
15+
echo "Point In Time Recovery In Progress. Waiting for $RECOVERY_DONE_FILE file"
16+
if [[ -e "$RECOVERY_DONE_FILE" ]]; then
17+
echo "$RECOVERY_DONE_FILE found."
18+
break
19+
fi
2020
done
2121
fi

scripts/on-start.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ hosts=$(cat "/scripts/peer-list")
2626
log "INFO" "hosts are {$hosts}"
2727

2828
if [[ $DISTRIBUTED == "true" ]]; then
29-
while [ ! -f "/etc/podip/podip" ];do
30-
sleep 1
31-
echo "nsmIP not available!!!"
32-
done
33-
34-
while [ ! -s /etc/podip/podip ]; do
35-
sleep 1
36-
echo "nsm ip not available"
37-
done
38-
39-
export POD_IP=$(cat /etc/podip/podip)
40-
log "INFO" "pod ip is-> $POD_IP"
29+
while [ ! -f "/etc/podip/podip" ]; do
30+
sleep 1
31+
echo "nsmIP not available!!!"
32+
done
33+
34+
while [ ! -s /etc/podip/podip ]; do
35+
sleep 1
36+
echo "nsm ip not available"
37+
done
38+
39+
export POD_IP=$(cat /etc/podip/podip)
40+
log "INFO" "pod ip is-> $POD_IP"
4141
fi
4242

4343
# write on galera configuration file

scripts/std-replication-run.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,3 @@ while [ true ]; do
3434
./scripts/std-replication-on-start.sh $@
3535
sleep 1
3636
done
37-

scripts/std-replication-setup.sh

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ function wait_for_mysqld_running() {
6262

6363
joining_for_first_time=1
6464

65-
function alter_user(){
66-
local mysql="$mysql_header --host=$localhost"
67-
local ssl_require=""
68-
local user="$1"
69-
if [[ "${REQUIRE_SSL:-}" == "TRUE" ]]; then
65+
function alter_user() {
66+
local mysql="$mysql_header --host=$localhost"
67+
local ssl_require=""
68+
local user="$1"
69+
if [[ "${REQUIRE_SSL:-}" == "TRUE" ]]; then
7070
ssl_require="REQUIRE SSL"
71-
else
71+
else
7272
ssl_require="REQUIRE NONE"
73-
fi
74-
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;ALTER USER '$user'@'%' $ssl_require;"
73+
fi
74+
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;ALTER USER '$user'@'%' $ssl_require;"
7575
}
7676

7777
function create_replication_user() {
@@ -137,7 +137,6 @@ function create_maxscale_user() {
137137
# fi
138138
#}
139139

140-
141140
function create_monitor_user() {
142141
log "INFO" "Checking whether monitor user exist or not......"
143142
local mysql="$mysql_header --host=$localhost"
@@ -151,12 +150,12 @@ function create_monitor_user() {
151150
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;CREATE USER 'monitor_user'@'%' IDENTIFIED BY '$MYSQL_ROOT_PASSWORD';"
152151
#mariadb 10.6+ change SUPER-> READ_ONLY ADMIN, REPLICATION CLIENT> SLAVE MONITOR
153152
if [[ "$(echo -e "1:10.7\n$MARIADB_VERSION" | sort -V | tail -n1)" == "$MARIADB_VERSION" ]]; then
154-
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT READ_ONLY ADMIN, RELOAD on *.* to 'monitor_user'@'%';"
155-
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT SLAVE MONITOR ON *.* TO 'monitor_user'@'%';"
156-
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT BINLOG ADMIN, REPLICATION MASTER ADMIN, REPLICATION SLAVE ADMIN ON *.* TO 'monitor_user'@'%';"
153+
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT READ_ONLY ADMIN, RELOAD on *.* to 'monitor_user'@'%';"
154+
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT SLAVE MONITOR ON *.* TO 'monitor_user'@'%';"
155+
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT BINLOG ADMIN, REPLICATION MASTER ADMIN, REPLICATION SLAVE ADMIN ON *.* TO 'monitor_user'@'%';"
157156
else
158-
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT SUPER, RELOAD on *.* to 'monitor_user'@'%';"
159-
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT REPLICATION CLIENT on *.* to 'monitor_user'@'%';"
157+
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT SUPER, RELOAD on *.* to 'monitor_user'@'%';"
158+
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;GRANT REPLICATION CLIENT on *.* to 'monitor_user'@'%';"
160159
fi
161160

162161
retry 120 ${mysql} -N -e "SET SQL_LOG_BIN=0;FLUSH PRIVILEGES;"
@@ -199,7 +198,7 @@ function join_to_master_by_slave_pos() {
199198
retry 20 ${mysql} -N -e "STOP SLAVE;"
200199
retry 20 ${mysql} -N -e "RESET SLAVE ALL;"
201200
if [ $joining_for_first_time -eq 1 ]; then
202-
retry 20 ${mysql} -N -e "SET GLOBAL gtid_slave_pos = '$gtid';"
201+
retry 20 ${mysql} -N -e "SET GLOBAL gtid_slave_pos = '$gtid';"
203202
fi
204203
if [[ "${REQUIRE_SSL:-}" == "TRUE" ]]; then
205204
ssl_options=", MASTER_SSL=1, MASTER_SSL_CA='/etc/mysql/certs/server/ca.crt'"
@@ -231,30 +230,30 @@ function start_mysqld_in_background() {
231230

232231
backup_restored=0
233232
if [ -f "/scripts/receive_backup.txt" ]; then
234-
echo "Waiting for the master to start streaming backup data..."
235-
echo "$POD_IP">/scripts/backup_receive_started.txt
236-
while true; do
237-
socat -u TCP-LISTEN:3307 STDOUT | mbstream -x -C /var/lib/mysql
238-
if [ $? -eq 0 ]; then
239-
log "INFO" "Data restore successful."
240-
break
241-
else
242-
log "INFO" "Data restore failed."
243-
rm -rf /var/lib/mysql
244-
fi
245-
done
246-
mariabackup --prepare --target-dir=/var/lib/mysql
247-
rm /scripts/backup_receive_started.txt
248-
backup_restored=1
249-
rm /scripts/receive_backup.txt
233+
echo "Waiting for the master to start streaming backup data..."
234+
echo "$POD_IP" >/scripts/backup_receive_started.txt
235+
while true; do
236+
socat -u TCP-LISTEN:3307 STDOUT | mbstream -x -C /var/lib/mysql
237+
if [ $? -eq 0 ]; then
238+
log "INFO" "Data restore successful."
239+
break
240+
else
241+
log "INFO" "Data restore failed."
242+
rm -rf /var/lib/mysql
243+
fi
244+
done
245+
mariabackup --prepare --target-dir=/var/lib/mysql
246+
rm /scripts/backup_receive_started.txt
247+
backup_restored=1
248+
rm /scripts/receive_backup.txt
250249
fi
251250

252251
start_mysqld_in_background
253252

254253
if [[ "${REQUIRE_SSL:-}" == "TRUE" ]]; then
255-
export mysql_header="mariadb -u ${USER} --port=3306 --ssl-ca=/etc/mysql/certs/server/ca.crt --ssl-cert=/etc/mysql/certs/server/tls.crt --ssl-key=/etc/mysql/certs/server/tls.key"
254+
export mysql_header="mariadb -u ${USER} --port=3306 --ssl-ca=/etc/mysql/certs/server/ca.crt --ssl-cert=/etc/mysql/certs/server/tls.crt --ssl-key=/etc/mysql/certs/server/tls.key"
256255
else
257-
export mysql_header="mariadb -u ${USER} --port=3306"
256+
export mysql_header="mariadb -u ${USER} --port=3306"
258257
fi
259258

260259
export MYSQL_PWD=${PASSWORD}
@@ -299,27 +298,26 @@ while true; do
299298
fi
300299

301300
if [[ $desired_func == "join_to_master" ]]; then
302-
# wait for the script copied by coordinator
303-
while [ ! -f "/scripts/master.txt" ]; do
304-
log "WARNING" "master detector file isn't present yet!"
305-
sleep 1
306-
done
307-
master=$(cat /scripts/master.txt)
308-
rm -rf /scripts/master.txt
309-
if [[ $backup_restored -eq 0 ]]; then
310-
join_to_master_by_current_pos
311-
else
312-
while [ ! -f "/scripts/gtid.txt" ]; do
313-
log "WARNING" "gtid detector file isn't present yet!"
301+
# wait for the script copied by coordinator
302+
while [ ! -f "/scripts/master.txt" ]; do
303+
log "WARNING" "master detector file isn't present yet!"
314304
sleep 1
315305
done
316-
gtid=$(cat /scripts/gtid.txt)
317-
echo "master replica's current gtid position is $gtid"
318-
rm -rf /scripts/gtid.txt
319-
join_to_master_by_slave_pos
320-
fi
306+
master=$(cat /scripts/master.txt)
307+
rm -rf /scripts/master.txt
308+
if [[ $backup_restored -eq 0 ]]; then
309+
join_to_master_by_current_pos
310+
else
311+
while [ ! -f "/scripts/gtid.txt" ]; do
312+
log "WARNING" "gtid detector file isn't present yet!"
313+
sleep 1
314+
done
315+
gtid=$(cat /scripts/gtid.txt)
316+
echo "master replica's current gtid position is $gtid"
317+
rm -rf /scripts/gtid.txt
318+
join_to_master_by_slave_pos
319+
fi
321320
fi
322321
log "INFO" "waiting for mysql process id = $pid"
323322
wait $pid
324323
done
325-

0 commit comments

Comments
 (0)