11#! /bin/sh
22me=${0##*/ }
33die () {
4+ echo " $me : $* " >&2
45 exit 1
56}
67
8+ # MARIABACKUP_RR=1 (wrap with "rr record")
9+ # MARIABACKUP_RR="rr record -h" (use a custom recorder command)
10+
11+ rr=
12+ case ${MARIABACKUP_RR:- } in
13+ ' ' |0|no) ;;
14+ 1|yes) rr=" rr record" ;;
15+ * ) rr=$MARIABACKUP_RR ;;
16+ esac
17+ # Where "rr record" stores traces, so we can point at it on a crash.
18+ rr_trace_dir=${_RR_TRACE_DIR:- ${XDG_DATA_HOME:- $HOME / .local/ share} / rr}
19+
20+
721MODE=
822TARGET_DIR=
923DATADIR=
7690
7791[ -n " $TARGET_DIR " ] || die " --target-dir required"
7892
79- # Run mysql with the connection options we collected.
93+ # Run the client with the connection options we collected.
8094ask () { mariadb $MARIADB_OPTS -BN -e " $1 " 2> /dev/null; }
8195
8296
@@ -90,8 +104,13 @@ if [ "$MODE" = prepare ]; then
90104 [ -f " $cnf " ] || die " $cnf missing - was this backup made by the wrapper?"
91105 [ -z " $EXPORT " ] || echo " $me : --export not implemented, doing a plain recovery" >&2
92106
93- mysqld=$( sed -n ' s/^# *mysqld=//p' " $cnf " | tail -n1)
94- [ -n " $mysqld " ] || mysqld=mariadbd
107+ # Prefer mariadbd on PATH; fall back to the path recorded at backup time.
108+ if command -v mariadbd > /dev/null 2>&1 ; then
109+ mariadbd=mariadbd
110+ else
111+ mariadbd=$( sed -n ' s/^# *mariadbd=//p' " $cnf " | tail -n1)
112+ [ -n " $mariadbd " ] || mariadbd=mariadbd
113+ fi
95114
96115 # backup.cnf tells us the LSN window recovery should replay.
97116 start=$( grep ' ^innodb_log_recovery_start' " $TARGET_DIR /backup.cnf" | cut -d= -f2 | tr -d ' ' )
@@ -125,10 +144,14 @@ select concat(@header,@checkpoint,@payload) into dumpfile '$newlog';
125144EOF
126145 fi
127146
128- $mysqld --defaults-file=" $cnf " $opts --bootstrap < " $input "
147+ $rr $mariadbd --defaults-file=" $cnf " $opts --bootstrap < " $input "
129148 rc=$?
130149 [ " $input " = /dev/null ] || rm -f " $input "
131- [ $rc -eq 0 ] || die " recovery failed (mariadbd exited $rc )"
150+ if [ $rc -ne 0 ]; then
151+ [ -z " $rr " ] || echo " $me : rr trace: $rr_trace_dir /latest-trace" \
152+ " (replay with: rr replay $rr_trace_dir /latest-trace)" >&2
153+ die " recovery failed (mariadbd exited $rc )"
154+ fi
132155
133156 if [ -n " $target " ]; then
134157 [ -f " $newlog " ] || die " could not build ib_logfile0 for LSN $target "
@@ -187,22 +210,22 @@ case $PARALLEL in # --parallel=N -> "N CONCURRENT" (1 is the default)
187210esac
188211mariadb $MARIADB_OPTS -e " $sql " || die " BACKUP SERVER failed"
189212
190- # Leave behind backup-prepare.cnf with everything --prepare's offline
191- # bootstrap needs: where mariadbd is, the InnoDB geometry, and (if the
192- # server is encrypted) how to load the key plugin again.
213+ # Create backup-prepare.cnf with everything --prepare's offline
214+ # bootstrap needs: where mariadbd is, the InnoDB parameters,
215+ # and how to load the key plugin again.
193216[ -f " $TARGET_DIR /backup.cnf" ] || exit 0
194217
195- mysqld =
218+ mariadbd =
196219pidfile=$( ask " SELECT @@global.pid_file" )
197220if [ -n " $pidfile " ] && [ -r " $pidfile " ]; then
198221 pid=$( cat " $pidfile " 2> /dev/null)
199- [ -n " $pid " ] && mysqld =$( readlink -f " /proc/$pid /exe" 2> /dev/null)
222+ [ -n " $pid " ] && mariadbd =$( readlink -f " /proc/$pid /exe" 2> /dev/null)
200223fi
201- if [ -z " $mysqld " ]; then
224+ if [ -z " $mariadbd " ]; then
202225 basedir=$( ask " SELECT @@global.basedir" )
203226 for c in " $basedir /sbin/mariadbd" " $basedir /bin/mariadbd" \
204227 " $basedir /sbin/mysqld" " $basedir /bin/mysqld" ; do
205- [ -x " $c " ] && { mysqld =$c ; break ; }
228+ [ -x " $c " ] && { mariadbd =$c ; break ; }
206229 done
207230fi
208231
@@ -217,7 +240,7 @@ enc=$(ask "SELECT LOWER(plugin_name) FROM information_schema.PLUGINS
217240
218241echo " $me : writing backup-prepare.cnf" >&2
219242{
220- [ -n " $mysqld " ] && echo " # mysqld= $mysqld "
243+ [ -n " $mariadbd " ] && echo " # mariadbd= $mariadbd "
221244 echo " [mariadbd]"
222245 [ -n " $page_size " ] && echo " innodb_page_size=$page_size "
223246 [ -n " $data_file_path " ] && echo " innodb_data_file_path=$data_file_path "
0 commit comments