Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Recover mysql-upgrade dir/link handlig wrongly removed in f7caa04
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ottok committed Jul 21, 2015
1 parent d190985 commit ada2c8c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 18 deletions.
6 changes: 3 additions & 3 deletions debian/mariadb-server-10.0.lintian-overrides
@@ -1,9 +1,9 @@
# OK, embedded has same source
mariadb-server-10.0: embedded-library usr/bin/mysqlbinlog: libmysqlclient
# ash's buildin has no "-e" so use /bin/echo
mariadb-server-10.0: command-with-path-in-maintainer-script postinst:156 /bin/echo
mariadb-server-10.0: command-with-path-in-maintainer-script postinst:166 /bin/echo
mariadb-server-10.0: command-with-path-in-maintainer-script postinst:179 /bin/echo
mariadb-server-10.0: command-with-path-in-maintainer-script postinst:199 /bin/echo
mariadb-server-10.0: command-with-path-in-maintainer-script postinst:209 /bin/echo
mariadb-server-10.0: command-with-path-in-maintainer-script postinst:222 /bin/echo
# OK, path /usr/sbin/invoke-rc.d is only used in check, executes are run without the path
mariadb-server-10.0: command-with-path-in-maintainer-script postinst:17 /usr/sbin/invoke-rc.d
mariadb-server-10.0: command-with-path-in-maintainer-script postrm:15 /usr/sbin/invoke-rc.d
Expand Down
43 changes: 43 additions & 0 deletions debian/mariadb-server-10.0.postinst
Expand Up @@ -73,6 +73,49 @@ case "$1" in
mysql_cfgdir=/etc/mysql
mysql_upgradedir=/var/lib/mysql-upgrade

# If the following symlink exists, it is a preserved copy the old data dir
# created by the preinst script during a upgrade that would have otherwise
# been replaced by an empty mysql dir. This should restore it.
for dir in DATADIR LOGDIR; do

if [ "$dir" = "DATADIR" ]; then
targetdir=$mysql_datadir
else
targetdir=$mysql_logdir
fi

savelink="$mysql_upgradedir/$dir.link"
if [ -L "$savelink" ]; then
# If the targetdir was a symlink before we upgraded it is supposed
# to be either still be present or not existing anymore now.
if [ -L "$targetdir" ]; then
rm "$savelink"
elif [ ! -d "$targetdir" ]; then
mv "$savelink" "$targetdir"
else
# this should never even happen, but just in case...
mysql_tmp=`mktemp -d -t mysql-symlink-restore-XXXXXX`
echo "this is very strange! see $mysql_tmp/README..." >&2
mv "$targetdir" "$mysql_tmp"
cat << EOF > "$mysql_tmp/README"
Ff you're reading this, it's most likely because you had replaced /var/lib/mysql
with a symlink, then upgraded to a new version of mysql, and then dpkg
removed your symlink (see #182747 and others). The mysql packages noticed
that this happened, and as a workaround have restored it. However, because
/var/lib/mysql seems to have been re-created in the meantime, and because
e don't want to rm -rf something we don't know as much about, we are going
to leave this unexpected directory here. If your database looks normal,
and this is not a symlink to your database, you should be able to blow
this all away.
EOF
fi
fi
rmdir $mysql_upgradedir 2>/dev/null || true

done

# Ensure the existence and right permissions for the database and
# log files.
if [ ! -d "$mysql_statedir" -a ! -L "$mysql_statedir" ]; then mkdir "$mysql_statedir"; fi
Expand Down
29 changes: 14 additions & 15 deletions debian/mariadb-server-10.0.preinst
Expand Up @@ -14,9 +14,8 @@ ${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 }

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

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

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

# Safe the user from stupidities.
show_downgrade_warning=0
for i in `ls $DATADIR/debian-*.flag 2>/dev/null`; do
for i in `ls $mysql_datadir/debian-*.flag 2>/dev/null`; do
found_version=`echo $i | sed 's/.*debian-\([0-9\.]\+\).flag/\1/'`
if dpkg --compare-versions "$this_version" '<<' "$found_version"; then
show_downgrade_warning=1
Expand All @@ -82,11 +81,11 @@ if [ "$show_downgrade_warning" = 1 ]; then
db_go
db_get mariadb-server-$this_version/really_downgrade || true
if [ "$RET" = "true" ]; then
rm -f $DATADIR/debian-*.flag
rm -f $mysql_datadir/debian-*.flag
else
echo "Aborting downgrade from (at least) $found_version to $this_version." 1>&2
echo "If are sure you want to downgrade to $this_version, remove the file" 1>&2
echo "$DATADIR/debian-*.flag and try installing again." 1>&2
echo "$mysql_datadir/debian-*.flag and try installing again." 1>&2
db_stop
exit 1
fi
Expand Down Expand Up @@ -140,19 +139,19 @@ set -e
for dir in DATADIR LOGDIR; do
checkdir=`eval echo "$"$dir`
if [ -L "$checkdir" ]; then
mkdir -p "$UPGRADEDIR"
cp -dT "$checkdir" "$UPGRADEDIR/$dir.link"
mkdir -p "$mysql_upgradedir"
cp -dT "$checkdir" "$mysql_upgradedir/$dir.link"
fi
done

# creating mysql home directory
if [ ! -d $DATADIR -a ! -L $DATADIR ]; then
mkdir $DATADIR
if [ ! -d $mysql_datadir -a ! -L $mysql_datadir ]; then
mkdir $mysql_datadir
fi

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

Expand Down

0 comments on commit ada2c8c

Please sign in to comment.