e6a51b
#!/bin/bash -ue
e6a51b
e6a51b
# Copyright (C) 2010-2014 Codership Oy
e6a51b
# Copyright (C) 2017-2020 Damien Ciabrini <damien.ciabrini@gmail.com>
e6a51b
#
e6a51b
# This program is free software; you can redistribute it and/or modify
e6a51b
# it under the terms of the GNU General Public License as published by
e6a51b
# the Free Software Foundation; version 2 of the License.
e6a51b
#
e6a51b
# This program is distributed in the hope that it will be useful,
e6a51b
# but WITHOUT ANY WARRANTY; without even the implied warranty of
e6a51b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e6a51b
# GNU General Public License for more details.
e6a51b
#
e6a51b
# You should have received a copy of the GNU General Public License
e6a51b
# along with this program; see the file COPYING. If not, write to the
e6a51b
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston
e6a51b
# MA  02110-1301  USA.
e6a51b
e6a51b
# This is a reference script for rsync-based state snapshot tansfer
e6a51b
# over an encrypted communication channel, managed by socat
e6a51b
e6a51b
RSYNC_PID=                                      # rsync pid file
e6a51b
RSYNC_CONF=                                     # rsync configuration file
e6a51b
RSYNC_REAL_PID=                                 # rsync process id
e6a51b
e6a51b
SOCAT_PID=                                      # socat pid file
e6a51b
SOCAT_REAL_PID=                                 # socat process id
e6a51b
e6a51b
SOCAT_OPTS=                                     # openssl connection args
e6a51b
e6a51b
MODULE="rsync_tunnel_sst"
e6a51b
e6a51b
OS=$(uname)
e6a51b
[ "$OS" == "Darwin" ] && export -n LD_LIBRARY_PATH
e6a51b
e6a51b
# Setting the path for lsof on CentOS
e6a51b
export PATH="/usr/sbin:/sbin:$PATH"
e6a51b
e6a51b
. $(dirname $0)/wsrep_sst_common
e6a51b
e6a51b
wsrep_check_programs rsync socat
e6a51b
e6a51b
cleanup_pid()
e6a51b
{
e6a51b
    local real_pid=$1
e6a51b
    [ "0" != "$real_pid" ]            && \
e6a51b
    kill $real_pid                    && \
e6a51b
    sleep 0.5                         && \
e6a51b
    kill -9 $real_pid >/dev/null 2>&1 || \
e6a51b
    :
e6a51b
}
e6a51b
e6a51b
cleanup_tunnel()
e6a51b
{
e6a51b
    if [ -n "$SOCAT_REAL_PID" ] && ps -p "$SOCAT_REAL_PID" >/dev/null 2>&1; then
e6a51b
	wsrep_log_info "cleanup socat PID: $SOCAT_REAL_PID"
e6a51b
	cleanup_pid $SOCAT_REAL_PID
e6a51b
    fi
e6a51b
    rm -rf "$SOCAT_PID"
e6a51b
}
e6a51b
e6a51b
cleanup_joiner()
e6a51b
{
e6a51b
    wsrep_log_info "Joiner cleanup. rsync PID: $RSYNC_REAL_PID"
e6a51b
    [ -n "$RSYNC_REAL_PID" ] && cleanup_pid $RSYNC_REAL_PID
e6a51b
    rm -rf "$RSYNC_CONF"
e6a51b
    rm -rf "$MAGIC_FILE"
e6a51b
    rm -rf "$RSYNC_PID"
e6a51b
e6a51b
    cleanup_tunnel
e6a51b
e6a51b
    wsrep_log_info "Joiner cleanup done."
e6a51b
    if [ "${WSREP_SST_OPT_ROLE}" = "joiner" ];then
e6a51b
        wsrep_cleanup_progress_file
e6a51b
    fi
e6a51b
}
e6a51b
e6a51b
# Check whether process is still running.
e6a51b
check_pid()
e6a51b
{
e6a51b
    local pid_file=$1
e6a51b
    [ -r "$pid_file" ] && ps -p $(cat $pid_file) >/dev/null 2>&1
e6a51b
}
e6a51b
e6a51b
check_pid_and_port()
e6a51b
{
e6a51b
    local pid_file=$1
e6a51b
    local service_pid=$2
e6a51b
    local service_port=$3
e6a51b
    local service_host=$4
e6a51b
    local service_name=$5
e6a51b
e6a51b
    if ! which lsof > /dev/null; then
e6a51b
      wsrep_log_error "lsof tool not found in PATH! Make sure you have it installed."
e6a51b
      exit 2 # ENOENT
e6a51b
    fi
e6a51b
e6a51b
    local port_info=$(lsof -i "@"$service_host:$service_port -Pn 2>/dev/null | \
e6a51b
        grep "(LISTEN)")
e6a51b
    local is_service=$(echo $port_info | \
e6a51b
        grep -w '^'"$service_name"'[[:space:]]\+'"$service_pid" 2>/dev/null)
e6a51b
e6a51b
    if [ -n "$port_info" -a -z "$is_service" ]; then
e6a51b
        wsrep_log_error "$service_name daemon port '$service_port' has been taken"
e6a51b
        exit 16 # EBUSY
e6a51b
    fi
e6a51b
e6a51b
    if ! check_pid $pid_file; then
e6a51b
        wsrep_log_error "$service_name process terminated unexpectedly"
e6a51b
        exit 10 # ECHILD
e6a51b
    fi
e6a51b
e6a51b
    [ -n "$port_info" ] && [ -n "$is_service" ] && \
e6a51b
        [ $(cat $pid_file) -eq $service_pid ]
e6a51b
}
e6a51b
e6a51b
config_from_cnf()
e6a51b
{
e6a51b
    local group=$1
e6a51b
    local key=$2
e6a51b
    echo $($MY_PRINT_DEFAULTS $group | grep -- "--$key=" | cut -d= -f2- | tail -1)
e6a51b
}
e6a51b
e6a51b
setup_tunnel_args()
e6a51b
{
e6a51b
    tca=$(config_from_cnf sst tca)
e6a51b
    tkey=$(config_from_cnf sst tkey)
e6a51b
    tcert=$(config_from_cnf sst tcert)
e6a51b
    sockopt=$(config_from_cnf sst sockopt)
e6a51b
e6a51b
    if [ -z "$tcert" ]; then
e6a51b
        wsrep_log_error "Encryption certificate not found in my.cnf"
e6a51b
        exit 3
e6a51b
    else
e6a51b
        SOCAT_OPTS="cert=$tcert"
e6a51b
    fi
e6a51b
    [ -n "$tkey" ] && SOCAT_OPTS="$SOCAT_OPTS,key=$tkey"
e6a51b
    [ -n "$tca" ] && SOCAT_OPTS="$SOCAT_OPTS,cafile=$tca"
e6a51b
    wsrep_log_info "Encryption setting to be used for socat tunnel: $SOCAT_OPTS"
e6a51b
e6a51b
    [ -n "$sockopt" ] && SOCAT_OPTS="$SOCAT_OPTS,$sockopt"
e6a51b
}
e6a51b
e6a51b
MAGIC_FILE="$WSREP_SST_OPT_DATA/rsync_tunnel_sst_complete"
e6a51b
rm -rf "$MAGIC_FILE"
e6a51b
e6a51b
BINLOG_TAR_FILE="$WSREP_SST_OPT_DATA/wsrep_sst_binlog.tar"
e6a51b
BINLOG_N_FILES=1
e6a51b
rm -f "$BINLOG_TAR_FILE" || :
e6a51b
e6a51b
if ! [ -z $WSREP_SST_OPT_BINLOG ]
e6a51b
then
e6a51b
    BINLOG_DIRNAME=$(dirname $WSREP_SST_OPT_BINLOG)
e6a51b
    BINLOG_FILENAME=$(basename $WSREP_SST_OPT_BINLOG)
e6a51b
fi
e6a51b
e6a51b
WSREP_LOG_DIR=${WSREP_LOG_DIR:-""}
e6a51b
# if WSREP_LOG_DIR env. variable is not set, try to get it from my.cnf
e6a51b
if [ -z "$WSREP_LOG_DIR" ]; then
e6a51b
    WSREP_LOG_DIR=$($MY_PRINT_DEFAULTS --mysqld \
e6a51b
                    | grep -- '--innodb[-_]log[-_]group[-_]home[-_]dir=' \
e6a51b
                    | cut -b 29- )
e6a51b
fi
e6a51b
e6a51b
if [ -n "$WSREP_LOG_DIR" ]; then
e6a51b
    # handle both relative and absolute paths
e6a51b
    WSREP_LOG_DIR=$(cd $WSREP_SST_OPT_DATA; mkdir -p "$WSREP_LOG_DIR"; cd $WSREP_LOG_DIR; pwd -P)
e6a51b
else
e6a51b
    # default to datadir
e6a51b
    WSREP_LOG_DIR=$(cd $WSREP_SST_OPT_DATA; pwd -P)
e6a51b
fi
e6a51b
e6a51b
# Old filter - include everything except selected
e6a51b
# FILTER=(--exclude '*.err' --exclude '*.pid' --exclude '*.sock' \
e6a51b
#         --exclude '*.conf' --exclude core --exclude 'galera.*' \
e6a51b
#         --exclude grastate.txt --exclude '*.pem' \
e6a51b
#         --exclude '*.[0-9][0-9][0-9][0-9][0-9][0-9]' --exclude '*.index')
e6a51b
e6a51b
# New filter - exclude everything except dirs (schemas) and innodb files
e6a51b
FILTER=(-f '- /lost+found' -f '- /.fseventsd' -f '- /.Trashes'
e6a51b
        -f '+ /wsrep_sst_binlog.tar' -f '+ /ib_lru_dump' -f '+ /ibdata*' -f '+ /*/' -f '- /*')
e6a51b
e6a51b
SOCAT_PID="$WSREP_SST_OPT_DATA/$MODULE-socat.pid"
e6a51b
e6a51b
if check_pid $SOCAT_PID
e6a51b
then
e6a51b
    wsrep_log_error "socat tunnel already running."
e6a51b
    exit 114 # EALREADY
e6a51b
fi
e6a51b
rm -rf "$SOCAT_PID"
e6a51b
e6a51b
setup_tunnel_args
e6a51b
e6a51b
if [ "$WSREP_SST_OPT_ROLE" = "donor" ]
e6a51b
then
e6a51b
e6a51b
    SOCAT_JOINER_ADDR=$(echo $WSREP_SST_OPT_ADDR | awk -F'/' '{print $1}')
e6a51b
    # map to name in case we received an IP
e6a51b
    SOCAT_JOINER_HOST=$(getent hosts $SOCAT_JOINER_ADDR | awk '{ print $2 }')
e6a51b
    if [ -z "$SOCAT_JOINER_HOST" ]; then
e6a51b
        SOCAT_JOINER_HOST=$SOCAT_JOINER_ADDR
e6a51b
    fi
e6a51b
    SOCAT_PORT=$(echo $SOCAT_JOINER_ADDR | awk -F ':' '{ print $2 }')
e6a51b
    if [ -z "$SOCAT_PORT" ]
e6a51b
    then
e6a51b
        SOCAT_PORT=4444
e6a51b
    fi
e6a51b
    TARGET_ADDR=localhost:$SOCAT_PORT/$MODULE
e6a51b
e6a51b
    trap cleanup_tunnel EXIT
e6a51b
e6a51b
    # Socat forwards rsync connections to the joiner
e6a51b
    SOCAT_SRC=tcp-listen:$SOCAT_PORT,bind=localhost,reuseaddr,fork
e6a51b
    SOCAT_DST=openssl:$SOCAT_JOINER_HOST,$SOCAT_OPTS
e6a51b
    wsrep_log_info "Setting up tunnel for donor: socat $SOCAT_SRC $SOCAT_DST"
e6a51b
    socat $SOCAT_SRC $SOCAT_DST &
e6a51b
    SOCAT_REAL_PID=$!
e6a51b
    # This is ok because a local galera node doesn't run SST concurrently
e6a51b
    echo $SOCAT_REAL_PID >"$SOCAT_PID"
e6a51b
    until check_pid_and_port $SOCAT_PID $SOCAT_REAL_PID $SOCAT_PORT localhost "socat"
e6a51b
    do
e6a51b
        sleep 0.2
e6a51b
    done
e6a51b
e6a51b
    if [ $WSREP_SST_OPT_BYPASS -eq 0 ]
e6a51b
    then
e6a51b
e6a51b
        FLUSHED="$WSREP_SST_OPT_DATA/tables_flushed"
e6a51b
        ERROR="$WSREP_SST_OPT_DATA/sst_error"
e6a51b
e6a51b
        rm -rf "$FLUSHED"
e6a51b
        rm -rf "$ERROR"
e6a51b
e6a51b
        # Use deltaxfer only for WAN
e6a51b
        inv=$(basename $0)
e6a51b
        [ "$inv" = "wsrep_sst_rsync_wan" ] && WHOLE_FILE_OPT="" \
e6a51b
                                           || WHOLE_FILE_OPT="--whole-file"
e6a51b
e6a51b
        echo "flush tables"
e6a51b
e6a51b
        # Wait for :
e6a51b
        # (a) Tables to be flushed, AND
e6a51b
        # (b) Cluster state ID & wsrep_gtid_domain_id to be written to the file, OR
e6a51b
        # (c) ERROR file, in case flush tables operation failed.
e6a51b
e6a51b
        while [ ! -r "$FLUSHED" ] && ! grep -q ':' "$FLUSHED" >/dev/null 2>&1
e6a51b
        do
e6a51b
            # Check whether ERROR file exists.
e6a51b
            if [ -f "$ERROR" ]
e6a51b
            then
e6a51b
                # Flush tables operation failed.
e6a51b
                rm -rf "$ERROR"
e6a51b
                exit 255
e6a51b
            fi
e6a51b
e6a51b
            sleep 0.2
e6a51b
        done
e6a51b
e6a51b
        STATE="$(cat $FLUSHED)"
e6a51b
        rm -rf "$FLUSHED"
e6a51b
e6a51b
        sync
e6a51b
e6a51b
        if ! [ -z $WSREP_SST_OPT_BINLOG ]
e6a51b
        then
e6a51b
            # Prepare binlog files
e6a51b
            pushd $BINLOG_DIRNAME &> /dev/null
e6a51b
            binlog_files_full=$(tail -n $BINLOG_N_FILES ${BINLOG_FILENAME}.index)
e6a51b
            binlog_files=""
e6a51b
            for ii in $binlog_files_full
e6a51b
            do
e6a51b
                binlog_files="$binlog_files $(basename $ii)"
e6a51b
            done
e6a51b
            if ! [ -z "$binlog_files" ]
e6a51b
            then
e6a51b
                wsrep_log_info "Preparing binlog files for transfer:"
e6a51b
                tar -cvf $BINLOG_TAR_FILE $binlog_files >&2
e6a51b
            fi
e6a51b
            popd &> /dev/null
e6a51b
        fi
e6a51b
e6a51b
        # first, the normal directories, so that we can detect incompatible protocol
e6a51b
        RC=0
e6a51b
        rsync --owner --group --perms --links --specials \
e6a51b
              --ignore-times --inplace --dirs --delete --quiet \
e6a51b
              $WHOLE_FILE_OPT "${FILTER[@]}" "$WSREP_SST_OPT_DATA/" \
e6a51b
              rsync://$TARGET_ADDR >&2 || RC=$?
e6a51b
e6a51b
        if [ "$RC" -ne 0 ]; then
e6a51b
            wsrep_log_error "rsync returned code $RC:"
e6a51b
e6a51b
            case $RC in
e6a51b
            12) RC=71  # EPROTO
e6a51b
                wsrep_log_error \
e6a51b
                "rsync server on the other end has incompatible protocol. " \
e6a51b
                "Make sure you have the same version of rsync on all nodes."
e6a51b
                ;;
e6a51b
            22) RC=12  # ENOMEM
e6a51b
                ;;
e6a51b
            *)  RC=255 # unknown error
e6a51b
                ;;
e6a51b
            esac
e6a51b
            exit $RC
e6a51b
        fi
e6a51b
e6a51b
        # second, we transfer InnoDB log files
e6a51b
        rsync --owner --group --perms --links --specials \
e6a51b
              --ignore-times --inplace --dirs --delete --quiet \
e6a51b
              $WHOLE_FILE_OPT -f '+ /ib_logfile[0-9]*' -f '- **' "$WSREP_LOG_DIR/" \
e6a51b
              rsync://$TARGET_ADDR-log_dir >&2 || RC=$?
e6a51b
e6a51b
        if [ $RC -ne 0 ]; then
e6a51b
            wsrep_log_error "rsync innodb_log_group_home_dir returned code $RC:"
e6a51b
            exit 255 # unknown error
e6a51b
        fi
e6a51b
e6a51b
        # then, we parallelize the transfer of database directories, use . so that pathconcatenation works
e6a51b
        pushd "$WSREP_SST_OPT_DATA" >/dev/null
e6a51b
e6a51b
        count=1
e6a51b
        [ "$OS" == "Linux" ] && count=$(grep -c processor /proc/cpuinfo)
e6a51b
        [ "$OS" == "Darwin" -o "$OS" == "FreeBSD" ] && count=$(sysctl -n hw.ncpu)
e6a51b
e6a51b
        find . -maxdepth 1 -mindepth 1 -type d -not -name "lost+found" -print0 | \
e6a51b
             xargs -I{} -0 -P $count \
e6a51b
             rsync --owner --group --perms --links --specials \
e6a51b
             --ignore-times --inplace --recursive --delete --quiet \
e6a51b
             $WHOLE_FILE_OPT --exclude '*/ib_logfile*' "$WSREP_SST_OPT_DATA"/{}/ \
e6a51b
             rsync://$TARGET_ADDR/{} >&2 || RC=$?
e6a51b
e6a51b
        popd >/dev/null
e6a51b
e6a51b
        if [ $RC -ne 0 ]; then
e6a51b
            wsrep_log_error "find/rsync returned code $RC:"
e6a51b
            exit 255 # unknown error
e6a51b
        fi
e6a51b
e6a51b
    else # BYPASS
e6a51b
        wsrep_log_info "Bypassing state dump."
e6a51b
e6a51b
        # Store donor's wsrep GTID (state ID) and wsrep_gtid_domain_id
e6a51b
        # (separated by a space).
e6a51b
        STATE="$WSREP_SST_OPT_GTID $WSREP_SST_OPT_GTID_DOMAIN_ID"
e6a51b
    fi
e6a51b
e6a51b
    echo "continue" # now server can resume updating data
e6a51b
e6a51b
    echo "$STATE" > "$MAGIC_FILE"
e6a51b
    rsync --archive --quiet --checksum "$MAGIC_FILE" rsync://$TARGET_ADDR
e6a51b
e6a51b
    # to avoid cleanup race, stop tunnel before declaring the SST finished.
e6a51b
    # This ensures galera won't start a new SST locally before we exit.
e6a51b
    cleanup_tunnel
e6a51b
e6a51b
    echo "done $STATE"
e6a51b
e6a51b
elif [ "$WSREP_SST_OPT_ROLE" = "joiner" ]
e6a51b
then
e6a51b
    wsrep_check_programs lsof socat
e6a51b
e6a51b
    touch $SST_PROGRESS_FILE
e6a51b
    MYSQLD_PID=$WSREP_SST_OPT_PARENT
e6a51b
e6a51b
    RSYNC_PID="$WSREP_SST_OPT_DATA/$MODULE.pid"
e6a51b
e6a51b
    if check_pid $RSYNC_PID
e6a51b
    then
e6a51b
        wsrep_log_error "rsync daemon already running."
e6a51b
        exit 114 # EALREADY
e6a51b
    fi
e6a51b
    rm -rf "$RSYNC_PID"
e6a51b
e6a51b
    ADDR=$WSREP_SST_OPT_ADDR
e6a51b
    RSYNC_PORT=$(echo $ADDR | awk -F ':' '{ print $2 }')
e6a51b
    if [ -z "$RSYNC_PORT" ]
e6a51b
    then
e6a51b
        RSYNC_PORT=4444
e6a51b
        ADDR="$(echo $ADDR | awk -F ':' '{ print $1 }'):$RSYNC_PORT"
e6a51b
    fi
e6a51b
e6a51b
    SOCAT_ADDR=$(echo $ADDR | awk -F ':' '{ print $1 }')
e6a51b
    # map to name in case we received an IP
e6a51b
    SOCAT_HOST=$(getent hosts $SOCAT_ADDR | awk '{ print $2 }')
e6a51b
    if [ -z "$SOCAT_HOST" ]; then
e6a51b
        SOCAT_HOST=$SOCAT_ADDR
e6a51b
    fi
e6a51b
    SOCAT_PORT=$RSYNC_PORT
e6a51b
e6a51b
    trap "exit 32" HUP PIPE
e6a51b
    trap "exit 3"  INT TERM ABRT
e6a51b
    trap cleanup_joiner EXIT
e6a51b
e6a51b
    RSYNC_CONF="$WSREP_SST_OPT_DATA/$MODULE.conf"
e6a51b
e6a51b
    if [ -n "${MYSQL_TMP_DIR:-}" ] ; then
e6a51b
      SILENT="log file = $MYSQL_TMP_DIR/rsynd.log"
e6a51b
    else
e6a51b
      SILENT=""
e6a51b
    fi
e6a51b
e6a51b
cat << EOF > "$RSYNC_CONF"
e6a51b
pid file = $RSYNC_PID
e6a51b
use chroot = no
e6a51b
read only = no
e6a51b
timeout = 300
e6a51b
$SILENT
e6a51b
[$MODULE]
e6a51b
    path = $WSREP_SST_OPT_DATA
e6a51b
[$MODULE-log_dir]
e6a51b
    path = $WSREP_LOG_DIR
e6a51b
EOF
e6a51b
e6a51b
#    rm -rf "$DATA"/ib_logfile* # we don't want old logs around
e6a51b
e6a51b
    # Socat receives rsync connections from the donor
e6a51b
    SOCAT_SRC=openssl-listen:$SOCAT_PORT,bind=$SOCAT_HOST,reuseaddr,fork,$SOCAT_OPTS
e6a51b
    SOCAT_DST=tcp:localhost:$RSYNC_PORT
e6a51b
    wsrep_log_info "Setting up tunnel for joiner: socat $SOCAT_SRC $SOCAT_DST"
e6a51b
    socat $SOCAT_SRC $SOCAT_DST &
e6a51b
    SOCAT_REAL_PID=$!
e6a51b
    # This is ok because a local galera node doesn't run SST concurrently
e6a51b
    echo $SOCAT_REAL_PID >"$SOCAT_PID"
e6a51b
    until check_pid_and_port $SOCAT_PID $SOCAT_REAL_PID $SOCAT_PORT $SOCAT_HOST "socat"
e6a51b
    do
e6a51b
        sleep 0.2
e6a51b
    done
e6a51b
e6a51b
    wsrep_log_info "rsync --daemon --no-detach --address localhost --port $RSYNC_PORT --config \"$RSYNC_CONF\""
e6a51b
    rsync --daemon --no-detach --address localhost --port $RSYNC_PORT --config "$RSYNC_CONF" &
e6a51b
    RSYNC_REAL_PID=$!
e6a51b
e6a51b
    until check_pid_and_port $RSYNC_PID $RSYNC_REAL_PID $RSYNC_PORT localhost "rsync"
e6a51b
    do
e6a51b
        sleep 0.2
e6a51b
    done
e6a51b
e6a51b
    echo "ready $ADDR/$MODULE"
e6a51b
e6a51b
    # wait for SST to complete by monitoring magic file
e6a51b
    while [ ! -r "$MAGIC_FILE" ] && check_pid "$RSYNC_PID" && \
e6a51b
          check_pid "$SOCAT_PID" && ps -p $MYSQLD_PID >/dev/null
e6a51b
    do
e6a51b
        sleep 1
e6a51b
    done
e6a51b
e6a51b
    # to avoid cleanup race, we can tear down the socat tunnel now
e6a51b
    # before signaling the end of the SST to galera.
e6a51b
    cleanup_tunnel
e6a51b
e6a51b
    if ! ps -p $MYSQLD_PID >/dev/null
e6a51b
    then
e6a51b
        wsrep_log_error \
e6a51b
        "Parent mysqld process (PID:$MYSQLD_PID) terminated unexpectedly."
e6a51b
        exit 32
e6a51b
    fi
e6a51b
e6a51b
    if ! [ -z $WSREP_SST_OPT_BINLOG ]
e6a51b
    then
e6a51b
e6a51b
        pushd $BINLOG_DIRNAME &> /dev/null
e6a51b
        if [ -f $BINLOG_TAR_FILE ]
e6a51b
        then
e6a51b
            # Clean up old binlog files first
e6a51b
            rm -f ${BINLOG_FILENAME}.*
e6a51b
            wsrep_log_info "Extracting binlog files:"
e6a51b
            tar -xvf $BINLOG_TAR_FILE >&2
e6a51b
            for ii in $(ls -1 ${BINLOG_FILENAME}.*)
e6a51b
            do
e6a51b
                echo ${BINLOG_DIRNAME}/${ii} >> ${BINLOG_FILENAME}.index
e6a51b
            done
e6a51b
        fi
e6a51b
        popd &> /dev/null
e6a51b
    fi
e6a51b
    if [ -r "$MAGIC_FILE" ]
e6a51b
    then
e6a51b
        # UUID:seqno & wsrep_gtid_domain_id is received here.
e6a51b
        cat "$MAGIC_FILE" # Output : UUID:seqno wsrep_gtid_domain_id
e6a51b
    else
e6a51b
        # this message should cause joiner to abort
e6a51b
        echo "rsync process ended without creating '$MAGIC_FILE'"
e6a51b
    fi
e6a51b
    wsrep_cleanup_progress_file
e6a51b
#    cleanup_joiner
e6a51b
else
e6a51b
    wsrep_log_error "Unrecognized role: '$WSREP_SST_OPT_ROLE'"
e6a51b
    exit 22 # EINVAL
e6a51b
fi
e6a51b
e6a51b
rm -f $BINLOG_TAR_FILE || :
e6a51b
e6a51b
exit 0