--- scripts/wsrep_sst_mariabackup.sh.orig 2018-07-13 11:54:07.684349000 +0200 +++ scripts/wsrep_sst_mariabackup.sh 2018-07-13 16:36:00.941511000 +0200 @@ -1,4 +1,4 @@ -#!/usr/local/bin/bash -ue +#!/bin/sh -ue # Copyright (C) 2013 Percona Inc # Copyright (C) 2017 MariaDB # @@ -101,7 +101,7 @@ timeit(){ local cmd="$@" local x1 x2 took extcode - if [[ $ttime -eq 1 ]];then + if [ $ttime -eq 1 ];then x1=$(date +%s) wsrep_log_info "Evaluating $cmd" eval "$cmd" @@ -121,18 +121,18 @@ timeit(){ get_keys() { # $encrypt -eq 1 is for internal purposes only - if [[ $encrypt -ge 2 || $encrypt -eq -1 ]];then + if [ $encrypt -ge 2 -o $encrypt -eq -1 ];then return fi - if [[ $encrypt -eq 0 ]];then + if [ $encrypt -eq 0 ];then if $MY_PRINT_DEFAULTS xtrabackup | grep -q encrypt;then wsrep_log_error "Unexpected option combination. SST may fail. Refer to http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html " fi return fi - if [[ $sfmt == 'tar' ]];then + if [ "$sfmt" = 'tar' ];then wsrep_log_info "NOTE: Xtrabackup-based encryption - encrypt=1 - cannot be enabled with tar format" encrypt=-1 return @@ -140,23 +140,23 @@ get_keys() wsrep_log_info "Xtrabackup based encryption enabled in my.cnf - Supported only from Xtrabackup 2.1.4" - if [[ -z $ealgo ]];then + if [ -z "$ealgo" ];then wsrep_log_error "FATAL: Encryption algorithm empty from my.cnf, bailing out" exit 3 fi - if [[ -z $ekey && ! -r $ekeyfile ]];then + if [ -z "$ekey" -a ! -r "$ekeyfile" ];then wsrep_log_error "FATAL: Either key or keyfile must be readable" exit 3 fi - if [[ -z $ekey ]];then + if [ -z "$ekey" ];then ecmd="${XBCRYPT_BIN} --encrypt-algo=$ealgo --encrypt-key-file=$ekeyfile" else ecmd="${XBCRYPT_BIN} --encrypt-algo=$ealgo --encrypt-key=$ekey" fi - if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + if [ "$WSREP_SST_OPT_ROLE" = "joiner" ];then ecmd+=" -d" fi @@ -165,16 +165,16 @@ get_keys() get_transfer() { - if [[ -z $SST_PORT ]];then + if [ -z "$SST_PORT" ];then TSST_PORT=4444 else TSST_PORT=$SST_PORT fi - if [[ $tfmt == 'nc' ]];then + if [ "$tfmt" = 'nc' ];then wsrep_check_programs nc wsrep_log_info "Using netcat as streamer" - if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + if [ "$WSREP_SST_OPT_ROLE" = "joiner" ];then if nc -h 2>&1 | grep -q ncat;then # Ncat tcmd="nc -l ${TSST_PORT}" @@ -202,34 +202,34 @@ get_transfer() wsrep_check_programs socat wsrep_log_info "Using socat as streamer" - if [[ $encrypt -eq 2 || $encrypt -eq 3 ]] && ! socat -V | grep -q "WITH_OPENSSL 1";then + if [ $encrypt -eq 2 -o $encrypt -eq 3 ] && ! socat -V | grep -q "WITH_OPENSSL 1";then wsrep_log_error "Encryption requested, but socat is not OpenSSL enabled (encrypt=$encrypt)" exit 2 fi - if [[ $encrypt -eq 2 ]];then + if [ $encrypt -eq 2 ];then wsrep_log_info "Using openssl based encryption with socat: with crt and pem" - if [[ -z $tpem || -z $tcert ]];then + if [ -z "$tpem" -o -z "$tcert" ];then wsrep_log_error "Both PEM and CRT files required" exit 22 fi stagemsg+="-OpenSSL-Encrypted-2" - if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + if [ "$WSREP_SST_OPT_ROLE" = "joiner" ];then wsrep_log_info "Decrypting with cert=${tpem}, cafile=${tcert}" tcmd="socat -u openssl-listen:${TSST_PORT},reuseaddr,cert=${tpem},cafile=${tcert}${sockopt} stdio" else wsrep_log_info "Encrypting with cert=${tpem}, cafile=${tcert}" tcmd="socat -u stdio openssl-connect:${REMOTEHOST}:${TSST_PORT},cert=${tpem},cafile=${tcert}${sockopt}" fi - elif [[ $encrypt -eq 3 ]];then + elif [ $encrypt -eq 3 ];then wsrep_log_info "Using openssl based encryption with socat: with key and crt" - if [[ -z $tpem || -z $tkey ]];then + if [ -z $tpem || -z $tkey ];then wsrep_log_error "Both certificate and key files required" exit 22 fi stagemsg+="-OpenSSL-Encrypted-3" - if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then - if [[ -z $tcert ]];then + if [ "$WSREP_SST_OPT_ROLE" = "joiner" ];then + if [ -z "$tcert" ];then wsrep_log_info "Decrypting with cert=${tpem}, key=${tkey}, verify=0" tcmd="socat -u openssl-listen:${TSST_PORT},reuseaddr,cert=${tpem},key=${tkey},verify=0${sockopt} stdio" else @@ -237,7 +237,7 @@ get_transfer() tcmd="socat -u openssl-listen:${TSST_PORT},reuseaddr,cert=${tpem},key=${tkey},cafile=${tcert}${sockopt} stdio" fi else - if [[ -z $tcert ]];then + if [ -z "$tcert" ];then wsrep_log_info "Encrypting with cert=${tpem}, key=${tkey}, verify=0" tcmd="socat -u stdio openssl-connect:${REMOTEIP}:${TSST_PORT},cert=${tpem},key=${tkey},verify=0${sockopt}" else @@ -247,7 +247,7 @@ get_transfer() fi else - if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + if [ "$WSREP_SST_OPT_ROLE" == "joiner" ];then tcmd="socat -u TCP-LISTEN:${TSST_PORT},reuseaddr${sockopt} stdio" else tcmd="socat -u stdio TCP:${REMOTEIP}:${TSST_PORT}${sockopt}" @@ -266,8 +266,8 @@ parse_cnf() # then grep for needed variable # finally get the variable value (if variables has been specified multiple time use the last value only) reval=$($MY_PRINT_DEFAULTS $group | awk -F= '{if ($1 ~ /_/) { gsub(/_/,"-",$1); print $1"="$2 } else { print $0 }}' | grep -- "--$var=" | cut -d= -f2- | tail -1) - if [[ -z $reval ]];then - [[ -n $3 ]] && reval=$3 + if [ -z "$reval" ];then + [ -n "$3" ] && reval=$3 fi echo $reval } @@ -298,18 +298,18 @@ adjust_progress() return fi - if [[ -n $progress && $progress != '1' ]];then - if [[ -e $progress ]];then + if [ -n "$progress" -a "$progress" != '1' ];then + if [ -e "$progress" ];then pcmd+=" 2>>$progress" else pcmd+=" 2>$progress" fi - elif [[ -z $progress && -n $rlimit ]];then + elif [ -z "$progress" -a -n "$rlimit" ];then # When rlimit is non-zero pcmd="pv -q" fi - if [[ -n $rlimit && "$WSREP_SST_OPT_ROLE" == "donor" ]];then + if [ -n "$rlimit" -a "$WSREP_SST_OPT_ROLE" = "donor" ];then wsrep_log_info "Rate-limiting SST to $rlimit" pcmd+=" -L \$rlimit" fi @@ -335,7 +335,7 @@ read_cnf() sdecomp=$(parse_cnf sst decompressor "") # Refer to http://www.percona.com/doc/percona-xtradb-cluster/manual/xtrabackup_sst.html - if [[ -z $ealgo ]];then + if [ -z "$ealgo" ];then ealgo=$(parse_cnf sst encrypt-algo "") ekey=$(parse_cnf sst encrypt-key "") ekeyfile=$(parse_cnf sst encrypt-key-file "") @@ -352,18 +352,18 @@ read_cnf() ssystag=$(parse_cnf mysqld_safe syslog-tag "${SST_SYSLOG_TAG:-}") ssystag+="-" - if [[ $speciald -eq 0 ]];then + if [ $speciald -eq 0 ];then wsrep_log_error "sst-special-dirs equal to 0 is not supported, falling back to 1" speciald=1 fi - if [[ $ssyslog -ne -1 ]];then + if [ $ssyslog -ne -1 ];then if $MY_PRINT_DEFAULTS mysqld_safe | tr '_' '-' | grep -q -- "--syslog";then ssyslog=1 fi fi - if [[ $encrypt -eq 1 ]]; then + if [ $encrypt -eq 1 ]; then wsrep_log_error "Xtrabackup-based encryption is currently not" \ "supported with MariaBackup" exit 2 @@ -372,9 +372,9 @@ read_cnf() get_stream() { - if [[ $sfmt == 'xbstream' ]];then + if [ "$sfmt" == 'xbstream' ];then wsrep_log_info "Streaming with xbstream" - if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + if [ "$WSREP_SST_OPT_ROLE" = "joiner" ];then strmcmd="${XBSTREAM_BIN} -x" else strmcmd="${XBSTREAM_BIN} -c \${INFO_FILE}" @@ -382,7 +382,7 @@ get_stream() else sfmt="tar" wsrep_log_info "Streaming with tar" - if [[ "$WSREP_SST_OPT_ROLE" == "joiner" ]];then + if [ "$WSREP_SST_OPT_ROLE" = "joiner" ];then strmcmd="tar xfi - " else strmcmd="tar cf - \${INFO_FILE} " @@ -395,7 +395,7 @@ get_proc() { set +e nproc=$(grep -c processor /proc/cpuinfo) - [[ -z $nproc || $nproc -eq 0 ]] && nproc=1 + [ -z "$nproc" -o $nproc -eq 0 ] && nproc=1 set -e } @@ -409,18 +409,18 @@ cleanup_joiner() { # Since this is invoked just after exit NNN local estatus=$? - if [[ $estatus -ne 0 ]];then + if [ $estatus -ne 0 ];then wsrep_log_error "Cleanup after exit with status:$estatus" elif [ "${WSREP_SST_OPT_ROLE}" = "joiner" ];then wsrep_log_info "Removing the sst_in_progress file" wsrep_cleanup_progress_file fi - if [[ -n $progress && -p $progress ]];then + if [ -n "$progress" && -p "$progress" ];then wsrep_log_info "Cleaning up fifo file $progress" rm $progress fi - if [[ -n ${STATDIR:-} ]];then - [[ -d $STATDIR ]] && rm -rf $STATDIR + if [ -n "${STATDIR:-}" ];then + [ -d "$STATDIR" ] && rm -rf $STATDIR fi # Final cleanup @@ -428,11 +428,11 @@ cleanup_joiner() # This means no setsid done in mysqld. # We don't want to kill mysqld here otherwise. - if [[ $$ -eq $pgid ]];then + if [ $$ -eq $pgid ];then # This means a signal was delivered to the process. # So, more cleanup. - if [[ $estatus -ge 128 ]];then + if [ $estatus -ge 128 ];then kill -KILL -$$ || true fi @@ -451,11 +451,11 @@ cleanup_donor() { # Since this is invoked just after exit NNN local estatus=$? - if [[ $estatus -ne 0 ]];then + if [ $estatus -ne 0 ];then wsrep_log_error "Cleanup after exit with status:$estatus" fi - if [[ -n ${XTRABACKUP_PID:-} ]];then + if [ -n "${XTRABACKUP_PID:-}" ];then if check_pid $XTRABACKUP_PID then wsrep_log_error "xtrabackup process is still running. Killing... " @@ -465,19 +465,19 @@ cleanup_donor() fi rm -f ${DATA}/${IST_FILE} || true - if [[ -n $progress && -p $progress ]];then + if [ -n "$progress" -a -p "$progress" ];then wsrep_log_info "Cleaning up fifo file $progress" rm -f $progress || true fi wsrep_log_info "Cleaning up temporary directories" - if [[ -n $xtmpdir ]];then - [[ -d $xtmpdir ]] && rm -rf $xtmpdir || true + if [ -n "$xtmpdir" ];then + [ -d "$xtmpdir" ] && rm -rf $xtmpdir || true fi - if [[ -n $itmpdir ]];then - [[ -d $itmpdir ]] && rm -rf $itmpdir || true + if [ -n "$itmpdir" ];then + [ -d "$itmpdir" ] && rm -rf $itmpdir || true fi # Final cleanup @@ -485,11 +485,11 @@ cleanup_donor() # This means no setsid done in mysqld. # We don't want to kill mysqld here otherwise. - if [[ $$ -eq $pgid ]];then + if [ $$ -eq $pgid ];then # This means a signal was delivered to the process. # So, more cleanup. - if [[ $estatus -ge 128 ]];then + if [ $estatus -ge 128 ];then kill -KILL -$$ || true fi @@ -509,11 +509,11 @@ kill_xtrabackup() setup_ports() { - if [[ "$WSREP_SST_OPT_ROLE" == "donor" ]];then + if [ "$WSREP_SST_OPT_ROLE" = "donor" ];then SST_PORT=$(echo $WSREP_SST_OPT_ADDR | awk -F '[:/]' '{ print $2 }') REMOTEIP=$(echo $WSREP_SST_OPT_ADDR | awk -F ':' '{ print $1 }') REMOTEHOST=$(getent hosts $REMOTEIP | awk '{ print $2 }') - if [[ -z $REMOTEHOST ]];then + if [ -z "$REMOTEHOST" ];then REMOTEHOST=$REMOTEIP fi lsn=$(echo $WSREP_SST_OPT_ADDR | awk -F '[:/]' '{ print $4 }') @@ -532,7 +532,11 @@ wait_for_listen() local MODULE=$3 for i in {1..50} do - ss -p state listening "( sport = :$PORT )" | grep -qE 'socat|nc' && break + if [ "$OS" = "FreeBSD" ];then + sockstat -46lp $PORT | grep -qE "^[^ ]* *(socat|nc) *[^ ]* *[^ ]* *[^ ]* *[^ ]*:$PORT" && break + else + ss -p state listening "( sport = :$PORT )" | grep -qE 'socat|nc' && break + fi sleep 0.2 done echo "ready ${ADDR}/${MODULE}//$sst_ver" @@ -541,10 +545,10 @@ wait_for_listen() check_extra() { local use_socket=1 - if [[ $uextra -eq 1 ]];then + if [ $uextra -eq 1 ];then if $MY_PRINT_DEFAULTS --mysqld | tr '_' '-' | grep -- "--thread-handling=" | grep -q 'pool-of-threads';then local eport=$($MY_PRINT_DEFAULTS --mysqld | tr '_' '-' | grep -- "--extra-port=" | cut -d= -f2) - if [[ -n $eport ]];then + if [ -n "$eport" ];then # Xtrabackup works only locally. # Hence, setting host to 127.0.0.1 unconditionally. wsrep_log_info "SST through extra_port $eport" @@ -558,7 +562,7 @@ check_extra() wsrep_log_info "Thread pool not set, ignore the option use_extra" fi fi - if [[ $use_socket -eq 1 ]] && [[ -n "${WSREP_SST_OPT_SOCKET}" ]];then + if [ $use_socket -eq 1 ] && [ -n "${WSREP_SST_OPT_SOCKET}" ];then INNOEXTRA+=" --socket=${WSREP_SST_OPT_SOCKET}" fi } @@ -571,7 +575,7 @@ recv_joiner() local checkf=$4 local ltcmd - if [[ ! -d ${dir} ]];then + if [ ! -d "${dir}" ];then # This indicates that IST is in progress return fi @@ -579,7 +583,7 @@ recv_joiner() pushd ${dir} 1>/dev/null set +e - if [[ $tmt -gt 0 ]] && command -v timeout >/dev/null;then + if [ $tmt -gt 0 ] && command -v timeout >/dev/null;then if timeout --help | grep -q -- '-k';then ltcmd="timeout -k $(( tmt+10 )) $tmt $tcmd" else @@ -593,20 +597,20 @@ recv_joiner() set -e popd 1>/dev/null - if [[ ${RC[0]} -eq 124 ]];then + if [ ${RC[0]} -eq 124 ];then wsrep_log_error "Possible timeout in receving first data from donor in gtid stage" exit 32 fi for ecode in "${RC[@]}";do - if [[ $ecode -ne 0 ]];then + if [ $ecode -ne 0 ];then wsrep_log_error "Error while getting data from donor node: " \ "exit codes: ${RC[@]}" exit 32 fi done - if [[ $checkf -eq 1 && ! -r "${MAGIC_FILE}" ]];then + if [ $checkf -eq 1 -a ! -r "${MAGIC_FILE}" ];then # this message should cause joiner to abort wsrep_log_error "xtrabackup process ended without creating '${MAGIC_FILE}'" wsrep_log_info "Contents of datadir" @@ -629,7 +633,7 @@ send_donor() for ecode in "${RC[@]}";do - if [[ $ecode -ne 0 ]];then + if [ $ecode -ne 0 ];then wsrep_log_error "Error while getting data from donor node: " \ "exit codes: ${RC[@]}" exit 32 @@ -642,7 +646,7 @@ wsrep_check_programs "$INNOBACKUPEX_BIN" rm -f "${MAGIC_FILE}" -if [[ ! ${WSREP_SST_OPT_ROLE} == 'joiner' && ! ${WSREP_SST_OPT_ROLE} == 'donor' ]];then +if [ ! ${WSREP_SST_OPT_ROLE} = 'joiner' -a ! ${WSREP_SST_OPT_ROLE} = 'donor' ];then wsrep_log_error "Invalid role ${WSREP_SST_OPT_ROLE}" exit 22 fi @@ -654,7 +658,7 @@ if ${INNOBACKUPEX_BIN} /tmp --help 2>/de disver="--no-version-check" fi -if [[ ${FORCE_FTWRL:-0} -eq 1 ]];then +if [ ${FORCE_FTWRL:-0} -eq 1 ];then wsrep_log_info "Forcing FTWRL due to environment variable FORCE_FTWRL equal to $FORCE_FTWRL" iopts+=" --no-backup-locks " fi @@ -662,7 +666,7 @@ fi INNOEXTRA="" -if [[ $ssyslog -eq 1 ]];then +if [ $ssyslog -eq 1 ];then if ! command -v logger >/dev/null;then wsrep_log_error "logger not in path: $PATH. Ignoring" @@ -703,13 +707,13 @@ then if [ $WSREP_SST_OPT_BYPASS -eq 0 ] then usrst=0 - if [[ -z $sst_ver ]];then + if [ -z "$sst_ver" ];then wsrep_log_error "Upgrade joiner to 5.6.21 or higher for backup locks support" wsrep_log_error "The joiner is not supported for this version of donor" exit 93 fi - if [[ -z $(parse_cnf mysqld tmpdir "") && -z $(parse_cnf xtrabackup tmpdir "") ]];then + if [ -z $(parse_cnf mysqld tmpdir "") -a -z $(parse_cnf xtrabackup tmpdir "") ];then xtmpdir=$(mktemp -d) tmpopts=" --tmpdir=$xtmpdir " wsrep_log_info "Using $xtmpdir as xtrabackup temporary directory" @@ -718,21 +722,21 @@ then itmpdir=$(mktemp -d) wsrep_log_info "Using $itmpdir as innobackupex temporary directory" - if [[ -n "${WSREP_SST_OPT_USER:-}" && "$WSREP_SST_OPT_USER" != "(null)" ]]; then + if [ -n "${WSREP_SST_OPT_USER:-}" -a "$WSREP_SST_OPT_USER" != "(null)" ]; then INNOEXTRA+=" --user=$WSREP_SST_OPT_USER" usrst=1 fi - if [ -n "${WSREP_SST_OPT_PSWD:-}" ]; then + if [ -n "${WSREP_SST_OPT_PSWD:-}" ];then INNOEXTRA+=" --password=$WSREP_SST_OPT_PSWD" - elif [[ $usrst -eq 1 ]];then + elif [ $usrst -eq 1 ];then # Empty password, used for testing, debugging etc. INNOEXTRA+=" --password=" fi get_keys - if [[ $encrypt -eq 1 ]];then - if [[ -n $ekey ]];then + if [ $encrypt -eq 1 ];then + if [ -n "$ekey" ];then INNOEXTRA+=" --encrypt=$ealgo --encrypt-key=$ekey " else INNOEXTRA+=" --encrypt=$ealgo --encrypt-key-file=$ekeyfile " @@ -750,13 +754,13 @@ then ttcmd="$tcmd" - if [[ $encrypt -eq 1 ]];then - if [[ -n $scomp ]];then + if [ $encrypt -eq 1 ];then + if [ -n "$scomp" ];then tcmd=" $ecmd | $scomp | $tcmd " else tcmd=" $ecmd | $tcmd " fi - elif [[ -n $scomp ]];then + elif [ -n "$scomp" ];then tcmd=" $scomp | $tcmd " fi @@ -764,10 +768,10 @@ then send_donor $DATA "${stagemsg}-gtid" tcmd="$ttcmd" - if [[ -n $progress ]];then + if [ -n "$progress" ];then get_footprint tcmd="$pcmd | $tcmd" - elif [[ -n $rlimit ]];then + elif [ -n "$rlimit" ];then adjust_progress tcmd="$pcmd | $tcmd" fi @@ -777,7 +781,7 @@ then wsrep_log_info "Streaming the backup to joiner at ${REMOTEIP} ${SST_PORT:-4444}" - if [[ -n $scomp ]];then + if [ -n "$scomp" ];then tcmd="$scomp | $tcmd" fi @@ -789,7 +793,7 @@ then wsrep_log_error "${INNOBACKUPEX_BIN} finished with error: ${RC[0]}. " \ "Check ${DATA}/innobackup.backup.log" exit 22 - elif [[ ${RC[$(( ${#RC[@]}-1 ))]} -eq 1 ]];then + elif [ ${RC[$(( ${#RC[@]}-1 ))]} -eq 1 ];then wsrep_log_error "$tcmd finished with error: ${RC[1]}" exit 22 fi @@ -808,13 +812,13 @@ then echo "${WSREP_SST_OPT_GTID} ${WSREP_SST_OPT_GTID_DOMAIN_ID}" > "${MAGIC_FILE}" echo "1" > "${DATA}/${IST_FILE}" get_keys - if [[ $encrypt -eq 1 ]];then - if [[ -n $scomp ]];then + if [ $encrypt -eq 1 ];then + if [ -n "$scomp" ];then tcmd=" $ecmd | $scomp | $tcmd " else tcmd=" $ecmd | $tcmd " fi - elif [[ -n $scomp ]];then + elif [ -n "$scomp" ];then tcmd=" $scomp | $tcmd " fi strmcmd+=" \${IST_FILE}" @@ -828,8 +832,8 @@ then elif [ "${WSREP_SST_OPT_ROLE}" = "joiner" ] then - [[ -e $SST_PROGRESS_FILE ]] && wsrep_log_info "Stale sst_in_progress file: $SST_PROGRESS_FILE" - [[ -n $SST_PROGRESS_FILE ]] && touch $SST_PROGRESS_FILE + [ -e "$SST_PROGRESS_FILE" ] && wsrep_log_info "Stale sst_in_progress file: $SST_PROGRESS_FILE" + [ -n "$SST_PROGRESS_FILE" ] && touch $SST_PROGRESS_FILE ib_home_dir=$(parse_cnf mysqld innodb-data-home-dir "") ib_log_dir=$(parse_cnf mysqld innodb-log-group-home-dir "") @@ -860,19 +864,19 @@ then trap sig_joiner_cleanup HUP PIPE INT TERM trap cleanup_joiner EXIT - if [[ -n $progress ]];then + if [ -n "$progress" ];then adjust_progress tcmd+=" | $pcmd" fi get_keys - if [[ $encrypt -eq 1 && $sencrypted -eq 1 ]];then - if [[ -n $sdecomp ]];then + if [ $encrypt -eq 1 -a $sencrypted -eq 1 ];then + if [ -n "$sdecomp" ];then strmcmd=" $sdecomp | $ecmd | $strmcmd" else strmcmd=" $ecmd | $strmcmd" fi - elif [[ -n $sdecomp ]];then + elif [ -n "$sdecomp" ];then strmcmd=" $sdecomp | $strmcmd" fi @@ -890,7 +894,7 @@ then if [ ! -r "${STATDIR}/${IST_FILE}" ] then - if [[ -d ${DATA}/.sst ]];then + if [ -d "${DATA}/.sst" ];then wsrep_log_info "WARNING: Stale temporary SST directory: ${DATA}/.sst from previous state transfer. Removing" rm -rf ${DATA}/.sst fi @@ -901,13 +905,17 @@ then wsrep_log_info "Cleaning the existing datadir and innodb-data/log directories" - find $ib_home_dir $ib_log_dir $ib_undo_dir $DATA -mindepth 1 -regex $cpat -prune -o -exec rm -rfv {} 1>&2 \+ + if [ "$OS" = "FreeBSD" ]; then + find -E $ib_home_dir $ib_log_dir $ib_undo_dir $DATA -mindepth 1 -regex $cpat -prune -o -exec rm -rfv {} 1>&2 \+ + else + find $ib_home_dir $ib_log_dir $ib_undo_dir $DATA -mindepth 1 -regex $cpat -prune -o -exec rm -rfv {} 1>&2 \+ + fi tempdir=$(parse_cnf mysqld log-bin "") - if [[ -n ${tempdir:-} ]];then + if [ -n "${tempdir:-}" ];then binlog_dir=$(dirname $tempdir) binlog_file=$(basename $tempdir) - if [[ -n ${binlog_dir:-} && $binlog_dir != '.' && $binlog_dir != $DATA ]];then + if [ -n "${binlog_dir:-}" -a "$binlog_dir" != '.' -a "$binlog_dir" != "$DATA" ];then pattern="$binlog_dir/$binlog_file\.[0-9]+$" wsrep_log_info "Cleaning the binlog directory $binlog_dir as well" find $binlog_dir -maxdepth 1 -type f -regex $pattern -exec rm -fv {} 1>&2 \+ || true @@ -915,36 +923,33 @@ then fi fi - - TDATA=${DATA} DATA="${DATA}/.sst" - MAGIC_FILE="${DATA}/${INFO_FILE}" wsrep_log_info "Waiting for SST streaming to complete!" wait $jpid get_proc - if [[ ! -s ${DATA}/xtrabackup_checkpoints ]];then + if [ ! -s "${DATA}/xtrabackup_checkpoints" ];then wsrep_log_error "xtrabackup_checkpoints missing, failed innobackupex/SST on donor" exit 2 fi # Rebuild indexes for compact backups - if grep -q 'compact = 1' ${DATA}/xtrabackup_checkpoints;then + if grep -q 'compact = 1' "${DATA}/xtrabackup_checkpoints";then wsrep_log_info "Index compaction detected" rebuild=1 fi - if [[ $rebuild -eq 1 ]];then + if [ $rebuild -eq 1 ];then nthreads=$(parse_cnf xtrabackup rebuild-threads $nproc) wsrep_log_info "Rebuilding during prepare with $nthreads threads" rebuildcmd="--rebuild-indexes --rebuild-threads=$nthreads" fi - if test -n "$(find ${DATA} -maxdepth 1 -type f -name '*.qp' -print -quit)";then + if [ -n "$(find ${DATA} -maxdepth 1 -type f -name '*.qp' -print -quit)" ];then wsrep_log_info "Compressed qpress files found" @@ -953,7 +958,7 @@ then exit 22 fi - if [[ -n $progress ]] && pv --help | grep -q 'line-mode';then + if [ -n "$progress" ] && pv --help | grep -q 'line-mode';then count=$(find ${DATA} -type f -name '*.qp' | wc -l) count=$(( count*2 )) if pv --help | grep -q FORMAT;then @@ -974,10 +979,10 @@ then timeit "Joiner-Decompression" "find ${DATA} -type f -name '*.qp' -printf '%p\n%h\n' | $dcmd" extcode=$? - if [[ $extcode -eq 0 ]];then + if [ $extcode -eq 0 ];then wsrep_log_info "Removing qpress files after decompression" find ${DATA} -type f -name '*.qp' -delete - if [[ $? -ne 0 ]];then + if [ $? -ne 0 ];then wsrep_log_error "Something went wrong with deletion of qpress files. Investigate" fi else @@ -987,7 +992,7 @@ then fi - if [[ ! -z $WSREP_SST_OPT_BINLOG ]];then + if [ ! -z "$WSREP_SST_OPT_BINLOG" ];then BINLOG_DIRNAME=$(dirname $WSREP_SST_OPT_BINLOG) BINLOG_FILENAME=$(basename $WSREP_SST_OPT_BINLOG) @@ -1018,7 +1023,7 @@ then set -e wsrep_log_info "Moving the backup to ${TDATA}" timeit "Xtrabackup move stage" "$INNOMOVE" - if [[ $? -eq 0 ]];then + if [ $? -eq 0 ];then wsrep_log_info "Move successful, removing ${DATA}" rm -rf $DATA DATA=${TDATA} @@ -1033,7 +1038,7 @@ then wsrep_log_info "${IST_FILE} received from donor: Running IST" fi - if [[ ! -r ${MAGIC_FILE} ]];then + if [ ! -r "${MAGIC_FILE}" ];then wsrep_log_error "SST magic file ${MAGIC_FILE} not found/readable" exit 2 fi --- scripts/wsrep_sst_common.sh.orig 2018-07-13 13:20:36.140952000 +0200 +++ scripts/wsrep_sst_common.sh 2018-07-13 13:21:27.996953000 +0200 @@ -28,6 +28,11 @@ WSREP_SST_OPT_DEFAULT="" WSREP_SST_OPT_EXTRA_DEFAULT="" WSREP_SST_OPT_SUFFIX_DEFAULT="" +# Check to see if we're running bash +[ $(ps -o command -p $$ | grep -c bash) -gt 0 ] && shisbash=1 +# Needed by some scripts +OS=$(uname) + while [ $# -gt 0 ]; do case "$1" in '--address')