Minor enhancements

pull/41/merge
deajan 9 years ago
parent 8a088d92cc
commit f4116ba69c

@ -4,7 +4,7 @@ PROGRAM="Osync instance upagrade script" # Rsync based two way sync engine with
AUTHOR="(L) 2015 by Orsiris \"Ozy\" de Jong"
CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr"
PROGRAM_VERSION="1.0x to v1.1"
PROGRAM_BUILD=2015092501
PROGRAM_BUILD=2015092601
function Init {
OSYNC_DIR=".osync_workdir"
@ -17,45 +17,45 @@ function Init {
FAILED_DELETE_LIST_FILENAME="-failed-delete-$SYNC_ID"
if [ "${SLAVE_SYNC_DIR:0:6}" == "ssh://" ]; then
REMOTE_SYNC="yes"
# remove leadng 'ssh://'
uri=${SLAVE_SYNC_DIR#ssh://*}
if [[ "$uri" == *"@"* ]]; then
# remove everything after '@'
REMOTE_USER=${uri%@*}
else
REMOTE_USER=$LOCAL_USER
fi
if [ "$SSH_RSA_PRIVATE_KEY" == "" ]; then
SSH_RSA_PRIVATE_KEY=~/.ssh/id_rsa
fi
# remove everything before '@'
_hosturiandpath=${uri#*@}
# remove everything after first '/'
_hosturi=${_hosturiandpath%%/*}
if [[ "$_hosturi" == *":"* ]]; then
REMOTE_PORT=${_hosturi##*:}
else
REMOTE_PORT=22
fi
REMOTE_HOST=${_hosturi%%:*}
REMOTE_SYNC="yes"
# remove leadng 'ssh://'
uri=${SLAVE_SYNC_DIR#ssh://*}
if [[ "$uri" == *"@"* ]]; then
# remove everything after '@'
REMOTE_USER=${uri%@*}
else
REMOTE_USER=$LOCAL_USER
fi
if [ "$SSH_RSA_PRIVATE_KEY" == "" ]; then
SSH_RSA_PRIVATE_KEY=~/.ssh/id_rsa
fi
# remove everything before '@'
_hosturiandpath=${uri#*@}
# remove everything after first '/'
_hosturi=${_hosturiandpath%%/*}
if [[ "$_hosturi" == *":"* ]]; then
REMOTE_PORT=${_hosturi##*:}
else
REMOTE_PORT=22
fi
REMOTE_HOST=${_hosturi%%:*}
# remove everything before first '/'
SLAVE_SYNC_DIR=${_hosturiandpath#*/}
fi
SLAVE_SYNC_DIR=${_hosturiandpath#*/}
fi
SSH_CMD="$(type -p ssh) $SSH_COMP -i $SSH_RSA_PRIVATE_KEY $REMOTE_USER@$REMOTE_HOST -p $REMOTE_PORT"
}
function Usage {
echo "$PROGRAM $PROGRAM_VERSION $PROGRAM_BUILD"
echo $AUTHOR
echo $CONTACT
echo ""
echo "This script migrates osync v1.0x setups to v1.1 by updating state filenames and config files."
echo "$PROGRAM $PROGRAM_VERSION $PROGRAM_BUILD"
echo $AUTHOR
echo $CONTACT
echo ""
echo "This script migrates osync v1.0x setups to v1.1 by updating state filenames and config files."
echo ""
echo "Usage: upgrade.sh /path/to/config_file.conf"
echo "Usage: upgrade.sh --master=/path/to/master/replica --slave=/path/to/local/slave/replica --sync-id=existing_id"
@ -64,39 +64,40 @@ function Usage {
echo "If config file is provided, the config file itself and both replicas from config file will be updated."
echo "If no config file provided, assume you run the update script just like any other quicksync task."
echo "If sync-id is not specified, it will assume handling a quicksync task."
exit 128
exit 128
}
function CheckEnvironment {
if [ "$REMOTE_SYNC" == "yes" ]; then
if ! type -p ssh > /dev/null 2>&1
then
Logger "ssh not present. Cannot start sync." "CRITICAL"
return 1
fi
fi
if ! type -p rsync > /dev/null 2>&1
then
Logger "rsync not present. Sync cannot start." "CRITICAL"
return 1
fi
if [ "$REMOTE_SYNC" == "yes" ]; then
if ! type -p ssh > /dev/null 2>&1
then
Logger "ssh not present. Cannot start sync." "CRITICAL"
return 1
fi
fi
if ! type -p rsync > /dev/null 2>&1
then
Logger "rsync not present. Sync cannot start." "CRITICAL"
return 1
fi
}
function LoadConfigFile {
local config_file="${1}"
if [ ! -f "$config_file" ]; then
echo "Cannot load configuration file [$config_file]. Sync cannot start."
exit 1
elif [[ "$1" != *".conf" ]]; then
echo "Wrong configuration file supplied [$config_file]. Sync cannot start."
exit 1
else
egrep '^#|^[^ ]*=[^;&]*' "$config_file" > "./osync.$FUNCNAME.$SCRIPT_PID"
# Shellcheck source=./sync.conf
source "./osync.$FUNCNAME.$SCRIPT_PID"
fi
local config_file="${1}"
if [ ! -f "$config_file" ]; then
echo "Cannot load configuration file [$config_file]. Sync cannot start."
exit 1
elif [[ "$1" != *".conf" ]]; then
echo "Wrong configuration file supplied [$config_file]. Sync cannot start."
exit 1
else
egrep '^#|^[^ ]*=[^;&]*' "$config_file" > "./osync.$FUNCNAME.$$"
# Shellcheck source=./sync.conf
source "./osync.$FUNCNAME.$$"
rm -f "./osync.$FUNCNAME.$$"
fi
}
function _RenameStateFilesLocal {
@ -240,16 +241,23 @@ function _RenameStateFilesLocal {
rewrite=true
fi
fi
if [ $rewrite == true ]; then
echo "State dir rewritten."
else
echo "Nothing rewritten in state dir."
fi
}
function _RenameStateFilesRemote {
echo "Connecting remotely to rewrite state files in [$1]."
$SSH_CMD state_dir="${1}" DELETED_LIST_FILENAME="$DELETED_LIST_FILENAME" FAILED_DELETE_LIST_FILENAME="$FAILED_DELETE_LIST_FILENAME" 'bash -x -s' << 'ENDSSH'
$SSH_CMD state_dir="${1}" DELETED_LIST_FILENAME="$DELETED_LIST_FILENAME" FAILED_DELETE_LIST_FILENAME="$FAILED_DELETE_LIST_FILENAME" 'bash -s' << 'ENDSSH'
# Make sure there is no ending slash
state_dir="${state_dir%/}/"
rewrite=false
if [ -f "$state_dir""master"$DELETED_LIST_FILENAME ]; then
mv -f "$state_dir""master"$DELETED_LIST_FILENAME "$state_dir""initiator"$DELETED_LIST_FILENAME
@ -275,6 +283,12 @@ $SSH_CMD state_dir="${1}" DELETED_LIST_FILENAME="$DELETED_LIST_FILENAME" FAILED_
rewrite=true
fi
fi
if [ $rewrite == true ]; then
echo "State dir rewritten."
else
echo "Nothing rewritten in state dir."
fi
ENDSSH
}
@ -285,7 +299,7 @@ function RenameStateFiles {
else
_RenameStateFilesRemote "$SLAVE_SYNC_DIR/$OSYNC_DIR/$STATE_DIR"
fi
}
}
function RewriteConfigFiles {
local config_file="${1}"
@ -309,22 +323,22 @@ _QUICKSYNC=0
for i in "$@"
do
case $i in
--master=*)
no_maxtime=1
MASTER_SYNC_DIR=${i##*=}
case $i in
--master=*)
no_maxtime=1
MASTER_SYNC_DIR=${i##*=}
QUICK_SYNC=$(($_QUICKSYNC + 1))
;;
--slave=*)
SLAVE_SYNC_DIR=${i##*=}
;;
--slave=*)
SLAVE_SYNC_DIR=${i##*=}
QUICK_SYNC=$(($_QUICKSYNC + 1))
;;
--rsakey=*)
SSH_RSA_PRIVATE_KEY=${i##*=}
;;
--sync-id=*)
SYNC_ID=${i##*=}
;;
;;
--rsakey=*)
SSH_RSA_PRIVATE_KEY=${i##*=}
;;
--sync-id=*)
SYNC_ID=${i##*=}
;;
esac
done

Loading…
Cancel
Save