Minor fixes

This commit is contained in:
deajan 2015-09-12 19:02:12 +02:00
parent c44ebd094a
commit e534a7f537
1 changed files with 93 additions and 94 deletions

View File

@ -4,7 +4,7 @@ PROGRAM="Osync" # Rsync based two way sync engine with fault tolerance
AUTHOR="(L) 2013-2015 by Orsiris \"Ozy\" de Jong" AUTHOR="(L) 2013-2015 by Orsiris \"Ozy\" de Jong"
CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr" CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr"
PROGRAM_VERSION=1.1-unstable PROGRAM_VERSION=1.1-unstable
PROGRAM_BUILD=2015091201 PROGRAM_BUILD=2015091203
## type doesn't work on platforms other than linux (bash). If if doesn't work, always assume output is not a zero exitcode ## type doesn't work on platforms other than linux (bash). If if doesn't work, always assume output is not a zero exitcode
if ! type -p "$BASH" > /dev/null; then if ! type -p "$BASH" > /dev/null; then
@ -47,7 +47,7 @@ else
RUN_DIR=. RUN_DIR=.
fi fi
## Working directory. Will keep current file states, backups and soft deleted files. ## Working directory. This is the name of the osync subdirectory contained in every replica.
OSYNC_DIR=".osync_workdir" OSYNC_DIR=".osync_workdir"
## Log a state message every $KEEP_LOGGING seconds. Should not be equal to soft or hard execution time so your log won't be unnecessary big. ## Log a state message every $KEEP_LOGGING seconds. Should not be equal to soft or hard execution time so your log won't be unnecessary big.
@ -196,13 +196,13 @@ function Spinner {
} }
function EscapeSpaces { function EscapeSpaces {
local string="${1}" # String on which space will be escaped local string="${1}" # String on which spaces will be escaped
echo $(echo "$string" | sed 's/ /\\ /g') echo $(echo "$string" | sed 's/ /\\ /g')
} }
function CleanUp { function CleanUp {
if [ "$_DEBUG" != "yes" ]; then if [ "$_DEBUG" != "yes" ]; then
rm -f $RUN_DIR/osync_*_$SCRIPT_PID rm -f "$RUN_DIR/osync_*_$SCRIPT_PID"
fi fi
} }
@ -260,6 +260,7 @@ function SendAlert {
function LoadConfigFile { function LoadConfigFile {
local config_file="${1}" local config_file="${1}"
if [ ! -f "$config_file" ]; then if [ ! -f "$config_file" ]; then
Logger "Cannot load configuration file [$config_file]. Sync cannot start." "CRITICAL" Logger "Cannot load configuration file [$config_file]. Sync cannot start." "CRITICAL"
exit 1 exit 1
@ -267,8 +268,8 @@ function LoadConfigFile {
Logger "Wrong configuration file supplied [$config_file]. Sync cannot start." "CRITICAL" Logger "Wrong configuration file supplied [$config_file]. Sync cannot start." "CRITICAL"
exit 1 exit 1
else else
egrep '^#|^[^ ]*=[^;&]*' "$config_file" > "$RUN_DIR/osync_config_$SCRIPT_PID" egrep '^#|^[^ ]*=[^;&]*' "$config_file" > $RUN_DIR/osync_$FUNCNAME_$SCRIPT_PID
source "$RUN_DIR/osync_config_$SCRIPT_PID" source "$RUN_DIR/osync_$FUNCNAME_$SCRIPT_PID"
fi fi
} }
@ -280,6 +281,7 @@ function CheckEnvironment {
return 1 return 1
fi fi
fi fi
if ! type -p rsync > /dev/null 2>&1 if ! type -p rsync > /dev/null 2>&1
then then
Logger "rsync not present. Sync cannot start." "CRITICAL" Logger "rsync not present. Sync cannot start." "CRITICAL"
@ -288,15 +290,15 @@ function CheckEnvironment {
} }
function GetLocalOS { function GetLocalOS {
LOCAL_OS_VAR=$(uname -spio 2>&1) local local_os_var=$(uname -spio 2>&1)
if [ $? != 0 ]; then if [ $? != 0 ]; then
LOCAL_OS_VAR=$(uname -v 2>&1) local local_os_var=$(uname -v 2>&1)
if [ $? != 0 ]; then if [ $? != 0 ]; then
LOCAL_OS_VAR=($uname) local local_os_var=($uname)
fi fi
fi fi
case $LOCAL_OS_VAR in case $local_os_var in
*"Linux"*) *"Linux"*)
LOCAL_OS="Linux" LOCAL_OS="Linux"
;; ;;
@ -310,28 +312,28 @@ function GetLocalOS {
LOCAL_OS="MacOSX" LOCAL_OS="MacOSX"
;; ;;
*) *)
Logger "Running on >> $LOCAL_OS_VAR << not supported. Please report to the author." "ERROR" Logger "Running on >> $local_os_var << not supported. Please report to the author." "ERROR"
exit 1 exit 1
;; ;;
esac esac
Logger "Local OS: [$LOCAL_OS_VAR]." "DEBUG" Logger "Local OS: [$local_os_var]." "DEBUG"
} }
function GetRemoteOS { function GetRemoteOS {
if [ "$REMOTE_SYNC" == "yes" ]; then if [ "$REMOTE_SYNC" == "yes" ]; then
CheckConnectivity3rdPartyHosts CheckConnectivity3rdPartyHosts
CheckConnectivityRemoteHost CheckConnectivityRemoteHost
eval "$SSH_CMD \"uname -spio\" > $RUN_DIR/osync_remote_os_$SCRIPT_PID 2>&1" & eval "$SSH_CMD \"uname -spio\" > $RUN_DIR/osync_$FUNCNAME_$SCRIPT_PID 2>&1" &
child_pid=$! child_pid=$!
WaitForTaskCompletion $child_pid 120 240 WaitForTaskCompletion $child_pid 120 240
retval=$? retval=$?
if [ $retval != 0 ]; then if [ $retval != 0 ]; then
eval "$SSH_CMD \"uname -v\" > $RUN_DIR/osync_remote_os_$SCRIPT_PID 2>&1" & eval "$SSH_CMD \"uname -v\" > $RUN_DIR/osync_$FUNCNAME_$SCRIPT_PID 2>&1" &
child_pid=$! child_pid=$!
WaitForTaskCompletion $child_pid 120 240 WaitForTaskCompletion $child_pid 120 240
retval=$? retval=$?
if [ $retval != 0 ]; then if [ $retval != 0 ]; then
eval "$SSH_CMD \"uname\" > $RUN_DIR/osync_remote_os_$SCRIPT_PID 2>&1" & eval "$SSH_CMD \"uname\" > $RUN_DIR/osync_$FUNCNAME_$SCRIPT_PID 2>&1" &
child_pid=$! child_pid=$!
WaitForTaskCompletion $child_pid 120 240 WaitForTaskCompletion $child_pid 120 240
retval=$? retval=$?
@ -341,9 +343,9 @@ function GetRemoteOS {
fi fi
fi fi
REMOTE_OS_VAR=$(cat $RUN_DIR/osync_remote_os_$SCRIPT_PID) local remote_os_var=$(cat $RUN_DIR/osync_$FUNCNAME_$SCRIPT_PID)
case $REMOTE_OS_VAR in case $remote_os_var in
*"Linux"*) *"Linux"*)
REMOTE_OS="Linux" REMOTE_OS="Linux"
;; ;;
@ -362,11 +364,11 @@ function GetRemoteOS {
;; ;;
*) *)
Logger "Running on remote OS failed. Please report to the author if the OS is not supported." "CRITICAL" Logger "Running on remote OS failed. Please report to the author if the OS is not supported." "CRITICAL"
Logger "Remote OS said:\n$REMOTE_OS_VAR" "CRITICAL" Logger "Remote OS said:\n$remote_os_var" "CRITICAL"
exit 1 exit 1
esac esac
Logger "Remote OS: [$REMOTE_OS_VAR]." "DEBUG" Logger "Remote OS: [$remote_os_var]." "DEBUG"
fi fi
} }
@ -611,9 +613,7 @@ function __CheckArguments {
fi fi
} }
############################################################################################ ###### realpath.sh implementation from https://github.com/mkropat/sh-realpath
### realpath.sh implementation from https://github.com/mkropat/sh-realpath
realpath() { realpath() {
canonicalize_path "$(resolve_symlinks "$1")" canonicalize_path "$(resolve_symlinks "$1")"
@ -725,7 +725,7 @@ _bsd_stat_readlink() {
stat -f %Y -- "$1" 2>/dev/null stat -f %Y -- "$1" 2>/dev/null
} }
#### Osync specific functions (non shared) ###### Osync specific functions (non shared)
function _CreateStateDirsLocal { function _CreateStateDirsLocal {
local replica_state_dir="${1}" local replica_state_dir="${1}"
@ -1102,7 +1102,7 @@ function tree_list {
local replica_path="${1}" # path to the replica for which a tree needs to be constructed local replica_path="${1}" # path to the replica for which a tree needs to be constructed
local replica_type="${2}" # replica type: initiator, target local replica_type="${2}" # replica type: initiator, target
local tree_filename="${3}" # filename to output tree (will be prefixed with $replica_type) local tree_filename="${3}" # filename to output tree (will be prefixed with $replica_type)
__CheckArguments 3 "$#" "$FUNCNAME" "$*" __CheckArguments 3 $# $FUNCNAME "$*"
local escaped_replica_path=$(EscapeSpaces "$replica_path") #TODO: See if escpaed still needed when using ' instead of " for command eval local escaped_replica_path=$(EscapeSpaces "$replica_path") #TODO: See if escpaed still needed when using ' instead of " for command eval
@ -1122,7 +1122,7 @@ function tree_list {
retval=$? retval=$?
## Retval 24 = some files vanished while creating list ## Retval 24 = some files vanished while creating list
if ([ $retval == 0 ] || [ $retval == 24 ]) && [ -f $RUN_DIR/osync_$replica_type_$SCRIPT_PID ]; then if ([ $retval == 0 ] || [ $retval == 24 ]) && [ -f $RUN_DIR/osync_$replica_type_$SCRIPT_PID ]; then
mv $RUN_DIR/osync_$replica_type_$SCRIPT_PID "$INITIATOR_STATE_DIR/$replica_type$tree_filename" mv -f $RUN_DIR/osync_$replica_type_$SCRIPT_PID "$INITIATOR_STATE_DIR/$replica_type$tree_filename"
return $? return $?
else else
Logger "Cannot create replica file list." "CRITICAL" Logger "Cannot create replica file list." "CRITICAL"
@ -1137,7 +1137,7 @@ function delete_list {
local tree_file_current="${3}" # tree-file-current, will be prefixed with replica type local tree_file_current="${3}" # tree-file-current, will be prefixed with replica type
local deleted_list_file="${4}" # file containing deleted file list, will be prefixed with replica type local deleted_list_file="${4}" # file containing deleted file list, will be prefixed with replica type
local deleted_failed_list_file="${5}" # file containing files that couldn't be deleted on last run, will be prefixed with replica type local deleted_failed_list_file="${5}" # file containing files that couldn't be deleted on last run, will be prefixed with replica type
__CheckArguments 5 "$#" "$FUNCNAME" "$*" __CheckArguments 5 $# $FUNCNAME "$*"
# TODO: Check why external filenames are used (see _DRYRUN option because of NOSUFFIX) # TODO: Check why external filenames are used (see _DRYRUN option because of NOSUFFIX)
@ -1174,7 +1174,7 @@ function sync_update {
local source_replica="${1}" # Contains replica type of source: initiator, target local source_replica="${1}" # Contains replica type of source: initiator, target
local destination_replica="${2}" # Contains replica type of destination: initiator, target local destination_replica="${2}" # Contains replica type of destination: initiator, target
local delete_list_filename="${3}" # Contains deleted list filename, will be prefixed with replica type local delete_list_filename="${3}" # Contains deleted list filename, will be prefixed with replica type
__CheckArguments 3 "$#" "$FUNCNAME" "$*" __CheckArguments 3 $# $FUNCNAME "$*"
Logger "Updating $destination_replica replica." "NOTICE" Logger "Updating $destination_replica replica." "NOTICE"
if [ "$source_replica" == "initiator" ]; then if [ "$source_replica" == "initiator" ]; then
@ -1229,7 +1229,7 @@ function _delete_local {
local deleted_list_file="${2}" # file containing deleted file list, will be prefixed with replica type local deleted_list_file="${2}" # file containing deleted file list, will be prefixed with replica type
local deletion_dir="${3}" # deletion dir in format .[workdir]/deleted local deletion_dir="${3}" # deletion dir in format .[workdir]/deleted
local deleted_failed_list_file="${4}" # file containing files that couldn't be deleted on last run, will be prefixed with replica type local deleted_failed_list_file="${4}" # file containing files that couldn't be deleted on last run, will be prefixed with replica type
__CheckArguments 4 "$#" "$FUNCNAME" "$*" __CheckArguments 4 $# $FUNCNAME "$*"
## On every run, check wheter the next item is already deleted because it's included in a directory already deleted ## On every run, check wheter the next item is already deleted because it's included in a directory already deleted
previous_file="" previous_file=""
@ -1291,7 +1291,7 @@ function _delete_remote {
local deleted_list_file="${2}" # file containing deleted file list, will be prefixed with replica type local deleted_list_file="${2}" # file containing deleted file list, will be prefixed with replica type
local deletion_dir="${3}" # deletion dir in format .[workdir]/deleted local deletion_dir="${3}" # deletion dir in format .[workdir]/deleted
local deleted_failed_list_file="${4}" # file containing files that couldn't be deleted on last run, will be prefixed with replica type local deleted_failed_list_file="${4}" # file containing files that couldn't be deleted on last run, will be prefixed with replica type
__CheckArguments 4 "$#" "$FUNCNAME" "$*" __CheckArguments 4 $# $FUNCNAME "$*"
## This is a special coded function. Need to redelcare local functions on remote host, passing all needed variables as escaped arguments to ssh command. ## This is a special coded function. Need to redelcare local functions on remote host, passing all needed variables as escaped arguments to ssh command.
## Anything beetween << ENDSSH and ENDSSH will be executed remotely ## Anything beetween << ENDSSH and ENDSSH will be executed remotely
@ -1437,7 +1437,7 @@ function deletion_propagation {
local replica_type="${1}" # Contains replica type: initiator, target local replica_type="${1}" # Contains replica type: initiator, target
local deleted_list_file="${2}" # file containing deleted file list, will be prefixed with replica type local deleted_list_file="${2}" # file containing deleted file list, will be prefixed with replica type
local deleted_failed_list_file="${3}" # file containing files that couldn't be deleted on last run, will be prefixed with replica type local deleted_failed_list_file="${3}" # file containing files that couldn't be deleted on last run, will be prefixed with replica type
__CheckArguments 3 "$#" "$FUNCNAME" "$*" __CheckArguments 3 $# $FUNCNAME "$*"
Logger "Propagating deletions to $replica_type replica." "NOTICE" Logger "Propagating deletions to $replica_type replica." "NOTICE"
@ -2248,7 +2248,6 @@ then
else else
LOG_FILE="$LOGFILE" LOG_FILE="$LOGFILE"
fi fi
GetLocalOS GetLocalOS
InitLocalOSSettings InitLocalOSSettings
Init Init