forked from websavers/mariadb-upgrade-script
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmariadb-upgrade.sh
More file actions
executable file
·652 lines (570 loc) · 21.1 KB
/
mariadb-upgrade.sh
File metadata and controls
executable file
·652 lines (570 loc) · 21.1 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
#!/bin/bash
set -o pipefail
RED='\033[0;31m'
NC='\033[0m' # No Color
LOG="/var/log/mariadb-upgrade.log"
MYSQL_CREDS_FILE=""
cleanup() {
[[ -n "$MYSQL_CREDS_FILE" ]] && rm -f "$MYSQL_CREDS_FILE" 2>/dev/null
# Lock on fd 9 is released automatically when the process exits
}
trap cleanup EXIT
# Verify running as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root." >&2
exit 1
fi
# Prevent concurrent execution
exec 9>/var/lock/mariadb-upgrade.lock
if ! flock -n 9; then
echo "Another instance of this script is already running. Exiting."
exit 1
fi
# Create secure credentials file for MySQL operations (avoids password in ps output)
MYSQL_CREDS_FILE=$(mktemp /tmp/mariadb-upgrade-creds.XXXXXX)
chmod 600 "$MYSQL_CREDS_FILE"
printf '[client]\nuser=admin\npassword=%s\n' "$(cat /etc/psa/.psa.shadow)" > "$MYSQL_CREDS_FILE"
echo "Beginning upgrade procedure." | tee -a $LOG
read -p "Do you wish to back up all existing databases? (y/n) " -n 1 -r
echo # new line
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
echo "Proceeding with backup to /root/all_databases_pre_maria_upgrade.sql.gz ... This may take 5 minutes or so depending on size of databases." | tee -a $LOG
install -m 600 /dev/null /root/all_databases_pre_maria_upgrade.sql.gz
DUMP_ERR=$(mktemp /tmp/mariadb-upgrade-dump-err.XXXXXX)
if mysqldump --defaults-extra-file="$MYSQL_CREDS_FILE" --all-databases --routines --triggers --max_allowed_packet=1G 2>"$DUMP_ERR" | gzip >/root/all_databases_pre_maria_upgrade.sql.gz; then
echo "- Backups successfully created" | tee -a $LOG
if ! gzip -t /root/all_databases_pre_maria_upgrade.sql.gz 2>/dev/null; then
echo -e "${RED}Warning: Backup file may be corrupted${NC}" | tee -a $LOG
fi
else
echo -e "${RED}Error creating backup:" | tee -a $LOG
echo -e "$(cat "$DUMP_ERR") ${NC}" | tee -a $LOG
rm -f "$DUMP_ERR"
exit 1
fi
rm -f "$DUMP_ERR"
else
echo "A risk taker, I see. Carrying on with upgrade procedures without backup..." | tee -a $LOG
fi
echo ""
echo "Which MariaDB LTS version would you like to upgrade to?"
echo "1) MariaDB 10.11 LTS (supported until February 2028)"
echo "2) MariaDB 11.4 LTS (supported until May 2029)"
echo "3) MariaDB 11.8 LTS (supported until June 2030)"
read -p "Enter your choice (1, 2, or 3): " -n 1 -r
echo # new line
if [[ $REPLY = "1" ]]; then
TARGET_VERSION="10.11"
elif [[ $REPLY = "2" ]]; then
TARGET_VERSION="11.4"
elif [[ $REPLY = "3" ]]; then
TARGET_VERSION="11.8"
else
echo "Invalid choice. Exiting."
exit 1
fi
read -p "Are you sure you wish to proceed with the upgrade to MariaDB $TARGET_VERSION? (y/n) " -n 1 -r
echo # new line
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
# shellcheck disable=SC2128
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
do_mariadb_upgrade() {
MDB_VER=$1
mariadb_rpm=""
#MAJOR_VER=$(rpm --eval '%{rhel}')
# Gets us ID and VERSION_ID vars
# shellcheck disable=SC1091
source /etc/os-release
MAJOR_VER="${VERSION_ID:0:1}" #ex: 7 or 8 rather than 7.4 or 8.4
if [[ "$ID" = "almalinux" ]]; then
ID=rhel;
fi
echo "Beginning upgrade to MariaDB $MDB_VER..." | tee -a $LOG
DATE=$(date)
case "$MDB_VER" in
"10.0")
BASEURL="https://archive.mariadb.org/mariadb-10.0.38/yum/centos7-amd64/"
;;
"10.1")
BASEURL="https://archive.mariadb.org/mariadb-10.1.48/yum/centos7-amd64/"
;;
"10.2")
BASEURL="https://archive.mariadb.org/mariadb-10.2.44/yum/centos7-amd64/"
;;
*)
BASEURL="https://yum.mariadb.org/$MDB_VER/$ID$MAJOR_VER-amd64"
;;
esac
echo "# MariaDB $MDB_VER CentOS repository list - created $DATE
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = $BASEURL
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1" >/etc/yum.repos.d/mariadb.repo
echo "- Clearing mariadb repo cache" | tee -a $LOG
if erroutput=$(yum clean all --disablerepo="*" --enablerepo=mariadb 2>&1); then
echo "- mariadb repo cache cleared" | tee -a $LOG
else
echo -e "${RED}Failed to clear mariadb repo cache" | tee -a $LOG
echo -e "$erroutput ${NC}" | tee -a $LOG
exit 1
fi
echo "- Setting innodb_fast_shutdown=0 for clean shutdown" | tee -a $LOG
mysql --defaults-extra-file="$MYSQL_CREDS_FILE" -e "SET GLOBAL innodb_fast_shutdown=0;" 2>/dev/null || true
echo "- Stopping current db server" | tee -a $LOG
if systemctl | grep -i "mariadb.service"; then
systemctl stop mariadb
elif systemctl | grep -i "mysql.service"; then
systemctl stop mysql
fi
echo "- Removing packages" | tee -a $LOG
if rpm -qa | grep "MariaDB-server" > /dev/null 2>&1; then
if erroutput=$(rpm --quiet -e --nodeps MariaDB-server 2>&1); then
echo "- MariaDB-server package erased" | tee -a $LOG
else
echo -e "${RED}$erroutput ${NC}" | tee -a $LOG
fi
else
if erroutput=$(rpm --quiet -e --nodeps mariadb-server 2>&1); then
echo "- MariaDB-server package erased" | tee -a $LOG
else
echo -e "${RED}$erroutput ${NC}" | tee -a $LOG
fi
fi
installed_packages=$(rpm -qa)
for i in mysql-common mysql-libs mysql-devel mariadb-backup mariadb-gssapi-server; do
if echo "$installed_packages" | grep "$i" > /dev/null 2>&1; then
mariadb_rpm="$mariadb_rpm $i"
fi
done
if [ -n "$mariadb_rpm" ]; then
if erroutput=$(rpm --quiet -e --nodeps "$mariadb_rpm" 2>&1); then
echo "- MariaDB packages erased" | tee -a $LOG
else
echo -e "${RED}$erroutput ${NC}" | tee -a $LOG
fi
fi
echo "- Updating and installing packages" | tee -a $LOG
if erroutput=$(yum -y -q update MariaDB-* 2>&1); then
echo "- MariaDB packages updated" | tee -a $LOG
else
echo -e "${RED}Failed to update MariaDB packages:" | tee -a $LOG
echo -e "$erroutput ${NC}" | tee -a $LOG
exit 1
fi
if erroutput=$(yum -y -q install MariaDB-server MariaDB MariaDB-gssapi-server 2>&1); then
echo "- MariaDB-server $MDB_VER successfully installed" | tee -a $LOG
else
echo -e "${RED}Failed to installed MariaDB $MDB_VER" | tee -a $LOG
echo -e "$erroutput ${NC}" | tee -a $LOG
exit 1
fi
if [ "$MDB_VER" = "10.6" ]; then
bind_address_fix
fi
echo "- Starting MariaDB $MDB_VER" | tee -a $LOG
if [ "$MDB_VER" = "10.0" ]; then
systemctl restart mysql
else
systemctl restart mariadb
fi
if [ "$MDB_VER" = "10.0" ]; then
if ! systemctl is-active --quiet mysql; then
echo -e "${RED}MariaDB $MDB_VER failed to start${NC}" | tee -a $LOG
exit 1
fi
else
if ! systemctl is-active --quiet mariadb; then
echo -e "${RED}MariaDB $MDB_VER failed to start${NC}" | tee -a $LOG
exit 1
fi
fi
echo "- Running mysql_upgrade" | tee -a $LOG
if erroutput=$(mysql_upgrade --defaults-extra-file="$MYSQL_CREDS_FILE" 2>&1); then
echo "- MySQL/MariaDB upgrade to $MDB_VER was Successful" | tee -a $LOG
else
echo -e "${RED}Failed to upgrade to MySQL/MariaDB $MDB_VER" | tee -a $LOG
echo -e "$erroutput ${NC}" | tee -a $LOG
exit 1
fi
}
bind_address_fix() {
CONFIG_FILE="/etc/my.cnf"
echo "Fixing bind-address.." | tee -a $LOG
grep -q "bind-address = ::ffff:127.0.0.1" "$CONFIG_FILE" && sed -i 's/bind-address = ::ffff:127.0.0.1//' "$CONFIG_FILE"
if ! grep -q "bind-address = " "$CONFIG_FILE"; then
echo "bind-address = 127.0.0.1" >> "$CONFIG_FILE"
fi
}
MySQL_VERS_INFO=$(mysql --version)
if [[ $MySQL_VERS_INFO =~ Distrib\ ([0-9]+)\.([0-9]+)\. ]]; then
CURRENT_MAJOR="${BASH_REMATCH[1]}"
CURRENT_MINOR="${BASH_REMATCH[2]}"
TARGET_MAJOR="${TARGET_VERSION%%.*}"
TARGET_MINOR="${TARGET_VERSION#*.}"
if (( TARGET_MAJOR < CURRENT_MAJOR || (TARGET_MAJOR == CURRENT_MAJOR && TARGET_MINOR < CURRENT_MINOR) )); then
echo -e "${RED}Cannot downgrade from MariaDB ${CURRENT_MAJOR}.${CURRENT_MINOR} to ${TARGET_VERSION}.${NC}" | tee -a $LOG
exit 1
fi
fi
#Consistency in repo naming, if one already exists
if [ -f "/etc/yum.repos.d/MariaDB.repo" ]; then
mv /etc/yum.repos.d/MariaDB.repo /etc/yum.repos.d/mariadb.repo
fi
systemctl stop sw-cp-server
case $MySQL_VERS_INFO in
*"Distrib 5.5."*)
echo "MySQL / MariaDB 5.5 detected. Proceeding with upgrade to $TARGET_VERSION"
rpm -e --nodeps mysql-server
mv -f /etc/my.cnf /etc/my.cnf.bak
do_mariadb_upgrade '10.0'
do_mariadb_upgrade '10.5'
do_mariadb_upgrade '10.6'
do_mariadb_upgrade '10.11'
if [ "$TARGET_VERSION" = "11.4" ] || [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.4'
fi
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 5.6."*)
echo "MySQL or Percona 5.6 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
# shellcheck disable=SC2143
if [[ $(rpm -qa | grep Percona-Server-server) ]]; then
# Removing Percona server and disabling repo
if erroutput=$(rpm -e --nodeps Percona-Server-server-56 2>&1); then
echo "- Percona-Package erased" | tee -a $LOG
else
echo -e "${RED}Failed to erase Percona-Package" | tee -a $LOG
echo -e "$erroutput ${NC}" | tee -a $LOG
fi
if erroutput=$(rpm -e --nodeps Percona-Server-shared-56 2>&1); then
echo "- Percona-Package erased" | tee -a $LOG
else
echo -e "${RED}Failed to erase Percona-Package" | tee -a $LOG
echo -e "$erroutput ${NC}" | tee -a $LOG
fi
if erroutput=$(rpm -e --nodeps Percona-Server-client-56 2>&1); then
echo "- Percona-Package erased" | tee -a $LOG
else
echo -e "${RED}Failed to erase Percona-Package" | tee -a $LOG
echo -e "$erroutput ${NC}" | tee -a $LOG
fi
if erroutput=$(rpm -e --nodeps Percona-Server-shared-51 2>&1); then
echo "- Percona-Package erased" | tee -a $LOG
else
echo -e "${RED}Failed to erase Percona-Package" | tee -a $LOG
echo -e "$erroutput ${NC}" | tee -a $LOG
fi
sed -i 's/^enabled = 1/enabled = 0/' /etc/yum.repos.d/percona-original-release.repo
else
# Removing MySQL 5.6 server
if erroutput=$(rpm -e --nodeps mysql-server 2>&1); then
echo "- removed mysql-server 5.6" | tee -a $LOG
else
echo -e "${RED}Failed to removed MySQL-server 5.6" | tee -a $LOG
echo -e "$erroutput ${NC}" | tee -a $LOG
exit 1
fi
fi
mv -f /etc/my.cnf /etc/my.cnf.bak
do_mariadb_upgrade '10.0'
do_mariadb_upgrade '10.1'
do_mariadb_upgrade '10.2'
do_mariadb_upgrade '10.5'
do_mariadb_upgrade '10.6'
do_mariadb_upgrade '10.11'
if [ "$TARGET_VERSION" = "11.4" ] || [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.4'
fi
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 10.0."*)
echo "MariaDB 10.0 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
mv -f /etc/my.cnf /etc/my.cnf.bak
do_mariadb_upgrade '10.1'
do_mariadb_upgrade '10.2'
do_mariadb_upgrade '10.5'
do_mariadb_upgrade '10.6'
do_mariadb_upgrade '10.11'
if [ "$TARGET_VERSION" = "11.4" ] || [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.4'
fi
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 10.1."*)
echo "MariaDB 10.1 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '10.2'
do_mariadb_upgrade '10.5'
do_mariadb_upgrade '10.6'
do_mariadb_upgrade '10.11'
if [ "$TARGET_VERSION" = "11.4" ] || [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.4'
fi
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 10.2."*)
echo "MariaDB 10.2 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '10.5'
do_mariadb_upgrade '10.6'
do_mariadb_upgrade '10.11'
if [ "$TARGET_VERSION" = "11.4" ] || [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.4'
fi
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 10.3."*)
echo "MariaDB 10.3 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '10.5'
do_mariadb_upgrade '10.6'
do_mariadb_upgrade '10.11'
if [ "$TARGET_VERSION" = "11.4" ] || [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.4'
fi
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 10.4."*)
echo "MariaDB 10.4 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '10.5'
do_mariadb_upgrade '10.6'
do_mariadb_upgrade '10.11'
if [ "$TARGET_VERSION" = "11.4" ] || [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.4'
fi
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 10.5."*)
echo "MariaDB 10.5 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '10.6'
do_mariadb_upgrade '10.11'
if [ "$TARGET_VERSION" = "11.4" ] || [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.4'
fi
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 10.6."*)
echo "MariaDB 10.6 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '10.11'
if [ "$TARGET_VERSION" = "11.4" ] || [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.4'
fi
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 10.7."*)
echo "MariaDB 10.7 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '10.11'
if [ "$TARGET_VERSION" = "11.4" ] || [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.4'
fi
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 10.8."*)
echo "MariaDB 10.8 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '10.11'
if [ "$TARGET_VERSION" = "11.4" ] || [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.4'
fi
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 10.9."*)
echo "MariaDB 10.9 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '10.11'
if [ "$TARGET_VERSION" = "11.4" ] || [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.4'
fi
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 10.10."*)
echo "MariaDB 10.10 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '10.11'
if [ "$TARGET_VERSION" = "11.4" ] || [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.4'
fi
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 10.11."*)
if [ "$TARGET_VERSION" = "10.11" ]; then
echo "Already at 10.11. Exiting." | tee -a $LOG
exit 1
fi
echo "MariaDB 10.11 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
if [ "$TARGET_VERSION" = "11.4" ] || [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.4'
fi
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 11.0."*)
echo "MariaDB 11.0 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '11.4'
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 11.1."*)
echo "MariaDB 11.1 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '11.4'
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 11.2."*)
echo "MariaDB 11.2 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '11.4'
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 11.3."*)
echo "MariaDB 11.3 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '11.4'
if [ "$TARGET_VERSION" = "11.8" ]; then
do_mariadb_upgrade '11.8'
fi
;;
*"Distrib 11.4."*)
if [ "$TARGET_VERSION" = "11.8" ]; then
echo "MariaDB 11.4 detected. Proceeding with upgrade to 11.8" | tee -a $LOG
do_mariadb_upgrade '11.8'
else
echo "Already at 11.4. Exiting." | tee -a $LOG
exit 1
fi
;;
*"Distrib 11.5."*)
echo "MariaDB 11.5 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '11.8'
;;
*"Distrib 11.6."*)
echo "MariaDB 11.6 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '11.8'
;;
*"Distrib 11.7."*)
echo "MariaDB 11.7 detected. Proceeding with upgrade to $TARGET_VERSION" | tee -a $LOG
do_mariadb_upgrade '11.8'
;;
*"Distrib 11.8."*)
echo "Already at 11.8. Exiting." | tee -a $LOG
exit 1
;;
*"Distrib 5.7."* | *"Distrib 8.0."*)
echo -e "${RED}MySQL $MySQL_VERS_INFO detected. This script only supports MariaDB upgrades, not MySQL 5.7/8.0.${NC}" | tee -a $LOG
exit 1
;;
*)
echo "Error. Unknown initial MySQL version. Aborting." | tee -a $LOG
exit 1
;;
esac
######
# At completion of all upgrades
######
# Increase MySQL/MariaDB Packet Size and open file limit. Set log file to default logrotate location
if [ -f "/etc/my.cnf.d/server.cnf" ]; then
sed -i 's/^\[mysqld\]/&\nlog-error=\/var\/lib\/mysql\/mysqld.log/' /etc/my.cnf.d/server.cnf
sed -i 's/^\[mysqld\]/&\nmax_allowed_packet=256M/' /etc/my.cnf.d/server.cnf
sed -i 's/^\[mysqld\]/&\nopen_files_limit=8192/' /etc/my.cnf.d/server.cnf
sed -i 's/^\[mariadb\]/&\nevent_scheduler=ON/' /etc/my.cnf.d/server.cnf
echo "- server.cnf configuration applied" | tee -a $LOG
else
echo -e "${RED}Warning: /etc/my.cnf.d/server.cnf not found, skipping config${NC}" | tee -a $LOG
fi
if [ -f "/var/log/mysqld.log" ]; then
mv /var/log/mysqld.log /var/log/mysqld.log.bak
elif [ -L "/var/log/mysqld.log" ]; then
rm -f /var/log/mysqld.log
fi
ln -sf /var/lib/mysql/mysqld.log /var/log/mysqld.log
echo "Ensuring systemd doesn't mix up mysql and mariadb" | tee -a $LOG
systemctl stop mysql > /dev/null 2>&1 || true
systemctl stop mariadb > /dev/null 2>&1 || true
chkconfig --del mysql > /dev/null 2>&1 || true
systemctl disable mysql > /dev/null 2>&1 || true
systemctl disable mariadb > /dev/null 2>&1 || true
systemctl enable mariadb.service > /dev/null 2>&1 || true
if ! systemctl start mariadb.service > /dev/null 2>&1; then
echo -e "${RED}Warning: MariaDB failed to start after final configuration${NC}" | tee -a $LOG
fi
echo "Fixing Plesk bug MDEV-27834" | tee -a $LOG
# BUGFIX MDEV-27834: https://support.plesk.com/hc/en-us/articles/4419625529362-Plesk-Installer-fails-when-MariaDB-10-5-or-10-6-is-installed
mdb_ver=$(rpm -q MariaDB-shared | awk -F- '{print $3}')
if echo "$mdb_ver" | grep -q 10.3.34; then
#rpm -Uhv --oldpackage --justdb http://yum.mariadb.org/10.3/rhel8-amd64/rpms/MariaDB-shared-10.3.32-1.el8.x86_64.rpm
if erroutput=$(yum -y -q downgrade MariaDB-shared-10.3.32 2>&1); then
echo "- Bug fix: downgrade successful" | tee -a $LOG
else
echo -e "${RED}Bug fix: downgrade failed" | tee -a $LOG
echo -e "$erroutput ${NC}" | tee -a $LOG
exit 1
fi
echo "exclude=MariaDB-shared-10.3.34" >>/etc/yum.repos.d/mariadb.repo
elif echo "$mdb_ver" | grep -q 10.4.24; then
#rpm -Uhv --oldpackage --justdb http://yum.mariadb.org/10.4/rhel8-amd64/rpms/MariaDB-shared-10.4.22-1.el8.x86_64.rpm
if erroutput=$(yum -y -q downgrade MariaDB-shared-10.4.22 2>&1); then
echo "- Bug fix: downgrade successful" | tee -a $LOG
else
echo -e "${RED}Bug fix: downgrade failed" | tee -a $LOG
echo -e "$erroutput ${NC}" | tee -a $LOG
exit 1
fi
echo "exclude=MariaDB-shared-10.4.24" >>/etc/yum.repos.d/mariadb.repo
elif echo "$mdb_ver" | grep -q 10.5.15; then
#rpm -Uhv --oldpackage --justdb http://yum.mariadb.org/10.5/rhel8-amd64/rpms/MariaDB-shared-10.5.13-1.el8.x86_64.rpm
if erroutput=$(yum -y -q downgrade MariaDB-shared-10.5.13 2>&1); then
echo "- Bug fix: downgrade successful" | tee -a $LOG
else
echo -e "${RED}Bug fix: downgrade failed" | tee -a $LOG
echo -e "$erroutput ${NC}" | tee -a $LOG
exit 1
fi
echo "exclude=MariaDB-shared-10.5.15" >>/etc/yum.repos.d/mariadb.repo
fi
# If you needed the above to install Plesk updates, now run `plesk installer update`
# END BUGFIX
echo "Informing Plesk of Changes" | tee -a $LOG
#plesk bin service_node --update local
if erroutput=$(plesk sbin packagemng -sdf 2>&1); then
echo "- Plesk informed of changes" | tee -a $LOG
else
echo -e "${RED}Failed to inform plesk of the changes" | tee -a $LOG
echo -e "$erroutput ${NC}" | tee -a $LOG
fi
restorecon -v /var/lib/mysql/*
systemctl restart sw-cp-server
systemctl daemon-reload
# Allow commands like mysqladmin processlist without un/pw
# Needed for logrotate
plesk db "install plugin unix_socket soname 'auth_socket';" >/dev/null 2>&1
plesk db "CREATE USER 'root'@'localhost' IDENTIFIED VIA unix_socket;" >/dev/null 2>&1
plesk db "GRANT RELOAD ON *.* TO 'root'@'localhost';" >/dev/null 2>&1
echo "" | tee -a $LOG
echo "Upgrade to MariaDB $TARGET_VERSION completed successfully." | tee -a $LOG