Skip to content

Commit ada2c8c

Browse files
committed
Recover mysql-upgrade dir/link handlig wrongly removed in f7caa04
The preinst is supposed to save possible mysql datadir link and the postinst is supposed to recover it. Also unify namig of the variables that reference the data and log directories.
1 parent d190985 commit ada2c8c

File tree

3 files changed

+60
-18
lines changed

3 files changed

+60
-18
lines changed

debian/mariadb-server-10.0.lintian-overrides

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# OK, embedded has same source
22
mariadb-server-10.0: embedded-library usr/bin/mysqlbinlog: libmysqlclient
33
# ash's buildin has no "-e" so use /bin/echo
4-
mariadb-server-10.0: command-with-path-in-maintainer-script postinst:156 /bin/echo
5-
mariadb-server-10.0: command-with-path-in-maintainer-script postinst:166 /bin/echo
6-
mariadb-server-10.0: command-with-path-in-maintainer-script postinst:179 /bin/echo
4+
mariadb-server-10.0: command-with-path-in-maintainer-script postinst:199 /bin/echo
5+
mariadb-server-10.0: command-with-path-in-maintainer-script postinst:209 /bin/echo
6+
mariadb-server-10.0: command-with-path-in-maintainer-script postinst:222 /bin/echo
77
# OK, path /usr/sbin/invoke-rc.d is only used in check, executes are run without the path
88
mariadb-server-10.0: command-with-path-in-maintainer-script postinst:17 /usr/sbin/invoke-rc.d
99
mariadb-server-10.0: command-with-path-in-maintainer-script postrm:15 /usr/sbin/invoke-rc.d

debian/mariadb-server-10.0.postinst

+43
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,49 @@ case "$1" in
7373
mysql_cfgdir=/etc/mysql
7474
mysql_upgradedir=/var/lib/mysql-upgrade
7575

76+
# If the following symlink exists, it is a preserved copy the old data dir
77+
# created by the preinst script during a upgrade that would have otherwise
78+
# been replaced by an empty mysql dir. This should restore it.
79+
for dir in DATADIR LOGDIR; do
80+
81+
if [ "$dir" = "DATADIR" ]; then
82+
targetdir=$mysql_datadir
83+
else
84+
targetdir=$mysql_logdir
85+
fi
86+
87+
savelink="$mysql_upgradedir/$dir.link"
88+
if [ -L "$savelink" ]; then
89+
# If the targetdir was a symlink before we upgraded it is supposed
90+
# to be either still be present or not existing anymore now.
91+
if [ -L "$targetdir" ]; then
92+
rm "$savelink"
93+
elif [ ! -d "$targetdir" ]; then
94+
mv "$savelink" "$targetdir"
95+
else
96+
# this should never even happen, but just in case...
97+
mysql_tmp=`mktemp -d -t mysql-symlink-restore-XXXXXX`
98+
echo "this is very strange! see $mysql_tmp/README..." >&2
99+
mv "$targetdir" "$mysql_tmp"
100+
cat << EOF > "$mysql_tmp/README"
101+
102+
Ff you're reading this, it's most likely because you had replaced /var/lib/mysql
103+
with a symlink, then upgraded to a new version of mysql, and then dpkg
104+
removed your symlink (see #182747 and others). The mysql packages noticed
105+
that this happened, and as a workaround have restored it. However, because
106+
/var/lib/mysql seems to have been re-created in the meantime, and because
107+
e don't want to rm -rf something we don't know as much about, we are going
108+
to leave this unexpected directory here. If your database looks normal,
109+
and this is not a symlink to your database, you should be able to blow
110+
this all away.
111+
112+
EOF
113+
fi
114+
fi
115+
rmdir $mysql_upgradedir 2>/dev/null || true
116+
117+
done
118+
76119
# Ensure the existence and right permissions for the database and
77120
# log files.
78121
if [ ! -d "$mysql_statedir" -a ! -L "$mysql_statedir" ]; then mkdir "$mysql_statedir"; fi

debian/mariadb-server-10.0.preinst

+14-15
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ ${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 }
1414

1515
export PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin
1616
MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
17-
DATADIR=/var/lib/mysql
18-
LOGDIR=/var/log/mysql
19-
UPGRADEDIR=/var/lib/mysql-upgrade
17+
mysql_datadir=/var/lib/mysql
18+
mysql_upgradedir=/var/lib/mysql-upgrade
2019

2120
# Try to stop the server in a sane way. If it does not success let the admin
2221
# do it himself. No database directories should be removed while the server
@@ -50,7 +49,7 @@ this_version=10.0
5049

5150
# Show upgrade warning if old data exists
5251
# Designed for scenarios where users upgrade form MySQL 5.5 or 5.6 or MariaDB 5.5
53-
for i in `ls $DATADIR/debian-*.flag 2>/dev/null`; do
52+
for i in `ls $mysql_datadir/debian-*.flag 2>/dev/null`; do
5453
found_version=`echo $i | sed 's/.*debian-\([0-9\.]\+\).flag/\1/'`
5554
if dpkg --compare-versions "$this_version" '>>' "$found_version"; then
5655
db_fset mariadb-server/oneway_migration seen false || true
@@ -69,7 +68,7 @@ done
6968

7069
# Safe the user from stupidities.
7170
show_downgrade_warning=0
72-
for i in `ls $DATADIR/debian-*.flag 2>/dev/null`; do
71+
for i in `ls $mysql_datadir/debian-*.flag 2>/dev/null`; do
7372
found_version=`echo $i | sed 's/.*debian-\([0-9\.]\+\).flag/\1/'`
7473
if dpkg --compare-versions "$this_version" '<<' "$found_version"; then
7574
show_downgrade_warning=1
@@ -82,11 +81,11 @@ if [ "$show_downgrade_warning" = 1 ]; then
8281
db_go
8382
db_get mariadb-server-$this_version/really_downgrade || true
8483
if [ "$RET" = "true" ]; then
85-
rm -f $DATADIR/debian-*.flag
84+
rm -f $mysql_datadir/debian-*.flag
8685
else
8786
echo "Aborting downgrade from (at least) $found_version to $this_version." 1>&2
8887
echo "If are sure you want to downgrade to $this_version, remove the file" 1>&2
89-
echo "$DATADIR/debian-*.flag and try installing again." 1>&2
88+
echo "$mysql_datadir/debian-*.flag and try installing again." 1>&2
9089
db_stop
9190
exit 1
9291
fi
@@ -140,19 +139,19 @@ set -e
140139
for dir in DATADIR LOGDIR; do
141140
checkdir=`eval echo "$"$dir`
142141
if [ -L "$checkdir" ]; then
143-
mkdir -p "$UPGRADEDIR"
144-
cp -dT "$checkdir" "$UPGRADEDIR/$dir.link"
142+
mkdir -p "$mysql_upgradedir"
143+
cp -dT "$checkdir" "$mysql_upgradedir/$dir.link"
145144
fi
146145
done
147146

148147
# creating mysql home directory
149-
if [ ! -d $DATADIR -a ! -L $DATADIR ]; then
150-
mkdir $DATADIR
148+
if [ ! -d $mysql_datadir -a ! -L $mysql_datadir ]; then
149+
mkdir $mysql_datadir
151150
fi
152151

153152
# checking disc space
154-
if LC_ALL=C BLOCKSIZE= df --portability $DATADIR/. | tail -n 1 | awk '{ exit ($4>1000) }'; then
155-
echo "ERROR: There's not enough space in $DATADIR/" 1>&2
153+
if LC_ALL=C BLOCKSIZE= df --portability $mysql_datadir/. | tail -n 1 | awk '{ exit ($4>1000) }'; then
154+
echo "ERROR: There's not enough space in $mysql_datadir/" 1>&2
156155
db_stop
157156
exit 1
158157
fi
@@ -165,8 +164,8 @@ fi
165164
# The "set +e" is necessary as e.g. a ".journal" of a ext3 partition is
166165
# not chgrp'able (#318435).
167166
set +e
168-
chown mysql:mysql $DATADIR
169-
find $DATADIR -follow -not -group mysql -print0 2>/dev/null \
167+
chown mysql:mysql $mysql_datadir
168+
find $mysql_datadir -follow -not -group mysql -print0 2>/dev/null \
170169
| xargs -0 --no-run-if-empty chgrp mysql
171170
set -e
172171

0 commit comments

Comments
 (0)