@ -1,184 +1,160 @@
#!/bin/bash
#!/bin/bash
##### Two way sync script
#### Osyc
##### (C) 2013 by Orsiris "Ozy" de Jong | ozy@badministrateur.com
## Rsync based two way sync engine. Master/slave setup.
OSYNC_VERSION = 0.0 #### Build 1806201301
OSYNC_VERSION = 0.4
OSYNC_BUILD = 1507201301
DEBUG = yes
DEBUG = no
SCRIPT_PID = $$
SCRIPT_PID = $$
LOCAL_USER = $( whoami)
LOCAL_USER = $( whoami)
LOCAL_HOST = $( hostname)
LOCAL_HOST = $( hostname)
## Flags
## Default log file until config file is loaded
error_alert = 0
LOG_FILE = /var/log/osync.log
dryrun = 0
silent = 0
## Working directory on master
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.
KEEP_LOGGING = 1801
function Log
function Log
{
{
echo " TIME: $SECONDS - $1 " >> " $LOG_FILE "
echo " TIME: $SECONDS - $1 " >> " $LOG_FILE "
if [ $silent -eq 0 ]
if [ $silent -eq 0 ]
then
then
echo " TIME: $SECONDS - $1 "
echo " TIME: $SECONDS - $1 "
fi
fi
}
}
function LogError
function LogError
{
{
Log " $1 "
Log " $1 "
error_alert = 1
error_alert = 1
}
}
function TrapError
function TrapError
{
{
local JOB = " $0 "
local JOB = " $0 "
local LINE = " $1 "
local LINE = " $1 "
local CODE = " ${ 2 :- 1 } "
local CODE = " ${ 2 :- 1 } "
if [ $silent -eq 0 ]
if [ $silent -eq 0 ]
then
then
echo " /!\ Error in ${ JOB } : Near line ${ LINE } , exit code ${ CODE } "
echo " /!\ Error in ${ JOB } : Near line ${ LINE } , exit code ${ CODE } "
fi
fi
}
function TrapStop
{
LogError " /!\ WARNING: Manual exit of sync script. Synchronization may be in inconsistent state."
if [ " $DEBUG " = = "no" ]
then
CleanUp
fi
exit 1
}
}
function Spinner
function Spinner
{
{
if [ $silent -eq 1 ]
if [ $silent -eq 1 ]
then
then
return 1
return 1
fi
fi
case $toggle
in
1)
echo -n $1 " \ "
echo -ne "\r"
toggle = "2"
; ;
2)
echo -n $1 " | "
echo -ne "\r"
toggle = "3"
; ;
3)
echo -n $1 " / "
echo -ne "\r"
toggle = "4"
; ;
*)
echo -n $1 " - "
echo -ne "\r"
toggle = "1"
; ;
esac
}
function Dummy
{
exit 1;
}
function StripQuotes
case $toggle
{
in
echo $( echo $1 | sed "s/^\([\"']\)\(.*\)\1\$/\2/g" )
1)
echo -n $1 " \ "
echo -ne "\r"
toggle = "2"
; ;
2)
echo -n $1 " | "
echo -ne "\r"
toggle = "3"
; ;
3)
echo -n $1 " / "
echo -ne "\r"
toggle = "4"
; ;
*)
echo -n $1 " - "
echo -ne "\r"
toggle = "1"
; ;
esac
}
}
function EscapeSpaces
function CleanUp
{
{
echo $( echo $1 | sed 's/ /\\ /g' )
rm -f /dev/shm/osync_config_$SCRIPT_PID
rm -f /dev/shm/osync_run_local_$SCRIPT_PID
rm -f /dev/shm/osync_run_remote_$SCRIPT_PID
}
}
function SendAlert
function SendAlert
{
{
CheckConnectivityRemoteHost
CheckConnectivityRemoteHost
CheckConnectivity3rdPartyHosts
CheckConnectivity3rdPartyHosts
cat " $LOG_FILE " | gzip -9 > /tmp/osync_lastlog.gz
cat " $LOG_FILE " | gzip -9 > /tmp/osync_lastlog.gz
if type -p mutt > /dev/null 2>& 1
if type -p mutt > /dev/null 2>& 1
then
then
echo $MAIL_ALERT_MSG | $( which mutt) -x -s " Sync alert for $SYNC_ID " $DESTINATION_MAILS -a /tmp/osync_lastlog.gz
echo $MAIL_ALERT_MSG | $( which mutt) -x -s " Sync alert for $SYNC_ID " $DESTINATION_MAILS -a /tmp/osync_lastlog.gz
if [ $? != 0 ]
if [ $? != 0 ]
then
then
Log " WARNING: Cannot send alert email via $( which mutt) !!! "
Log " WARNING: Cannot send alert email via $( which mutt) !!! "
else
else
Log "Sent alert mail using mutt."
Log "Sent alert mail using mutt."
fi
fi
elif type -p mail > /dev/null 2>& 1
elif type -p mail > /dev/null 2>& 1
then
then
echo $MAIL_ALERT_MSG | $( which mail) -a /tmp/osync_lastlog.gz -s " Sync alert for $SYNC_ID " $DESTINATION_MAILS
echo $MAIL_ALERT_MSG | $( which mail) -a /tmp/osync_lastlog.gz -s " Sync alert for $SYNC_ID " $DESTINATION_MAILS
if [ $? != 0 ]
if [ $? != 0 ]
then
then
Log " WARNING: Cannot send alert email via $( which mail) with attachments !!! "
Log " WARNING: Cannot send alert email via $( which mail) with attachments !!! "
echo $MAIL_ALERT_MSG | $( which mail) -s " Sync alert for $SYNC_ID " $DESTINATION_MAILS
echo $MAIL_ALERT_MSG | $( which mail) -s " Sync alert for $SYNC_ID " $DESTINATION_MAILS
if [ $? != 0 ]
if [ $? != 0 ]
then
then
Log " WARNING: Cannot send alert email via $( which mail) without attachments !!! "
Log " WARNING: Cannot send alert email via $( which mail) without attachments !!! "
else
else
Log "Sent alert mail using mail command without attachment."
Log "Sent alert mail using mail command without attachment."
fi
fi
else
else
Log "Sent alert mail using mail command."
Log "Sent alert mail using mail command."
fi
fi
else
else
Log "WARNING: Cannot send alert email (no mutt / mail present) !!!"
Log "WARNING: Cannot send alert email (no mutt / mail present) !!!"
return 1
return 1
fi
fi
}
}
function LoadConfigFile
function LoadConfigFile
{
{
if [ ! -f " $1 " ]
if [ ! -f " $1 " ]
then
then
LogError " Cannot load sync configuration file [ $1 ]. Synchronization cannot start."
LogError " Cannot load configuration file [ $1 ]. Sync cannot start."
return 1
return 1
elif [ [ $1 != *.conf ] ]
elif [ [ $1 != *.conf ] ]
then
then
LogError " Wrong configuration file supplied [ $1 ]. Sync hronization cannot start."
LogError " Wrong configuration file supplied [ $1 ]. Sync cannot start."
else
else
egrep '^#|^[^ ]*=[^;&]*' " $1 " > " /dev/shm/osync_config_ $SCRIPT_PID "
egrep '^#|^[^ ]*=[^;&]*' " $1 " > " /dev/shm/osync_config_ $SCRIPT_PID "
source " /dev/shm/osync_config_ $SCRIPT_PID "
source " /dev/shm/osync_config_ $SCRIPT_PID "
fi
fi
}
}
function CheckEnvironment
function CheckEnvironment
{
{
sed --version > /dev/null 2>& 1
if [ " $REMOTE_SYNC " = = "yes" ]
if [ $? != 0 ]
then
then
LogError "GNU coreutils not found (tested for sed --version). Synchronization cannot start."
if ! type -p ssh > /dev/null 2>& 1
return 1
then
fi
LogError "ssh not present. Cannot start sync."
return 1
fi
if [ " $REMOTE_SYNC " = = "yes" ]
fi
then
if ! type -p rsync > /dev/null 2>& 1
if ! type -p ssh > /dev/null 2>& 1
then
then
LogError "rsync not present. Sync cannot start."
LogError "ssh not present. Cannot start backup."
return 1
return 1
fi
fi
fi
if [ " $BACKUP_FILES " != "no" ]
then
if ! type -p rsync > /dev/null 2>& 1
then
LogError "rsync not present. Backup cannot start."
return 1
fi
fi
}
}
# Waits for pid $1 to complete. Will log an alert if $2 seconds exec time exceeded unless $2 equals 0. Will stop task and log alert if $3 seconds exec time exceeded.
# Waits for pid $1 to complete. Will log an alert if $2 seconds exec time exceeded unless $2 equals 0. Will stop task and log alert if $3 seconds exec time exceeded.
@ -211,204 +187,368 @@ function WaitForTaskCompletition
done
done
}
}
## Runs local command $1 and waits for completition in $2 seconds
## Runs local command $1 and waits for completition in $2 seconds
function RunLocalCommand
function RunLocalCommand
{
{
CheckConnectivity3rdPartyHosts
CheckConnectivity3rdPartyHosts
$1 > /dev/shm/osync_run_local_$SCRIPT_PID &
$1 > /dev/shm/osync_run_local_$SCRIPT_PID &
child_pid = $!
child_pid = $!
WaitForTaskCompletition $child_pid 0 $2
WaitForTaskCompletition $child_pid 0 $2
wait $child_pid
wait $child_pid
retval = $?
retval = $?
if [ $retval -eq 0 ]
if [ $retval -eq 0 ]
then
then
Log " Running command [ $1 ] on local host succeded. "
Log " Running command [ $1 ] on local host succeded. "
else
else
Log " Running command [ $1 ] on local host failed. "
Log " Running command [ $1 ] on local host failed. "
fi
fi
Log "Command output:"
Log "Command output:"
Log " $( cat /dev/shm/osync_run_local_$SCRIPT_PID ) "
Log " $( cat /dev/shm/osync_run_local_$SCRIPT_PID ) "
}
}
## Runs remote command $1 and waits for completition in $2 seconds
## Runs remote command $1 and waits for completition in $2 seconds
function RunRemoteCommand
function RunRemoteCommand
{
{
CheckConnectivity3rdPartyHosts
CheckConnectivity3rdPartyHosts
if [ " $REMOTE_SYNC " = = "yes" ]
if [ " $REMOTE_SYNC " = = "yes" ]
then
then
CheckConnectivityRemoteHost
CheckConnectivityRemoteHost
if [ $? != 0 ]
if [ $? != 0 ]
then
then
LogError "Connectivity test failed. Cannot run remote command."
LogError "Connectivity test failed. Cannot run remote command."
return 1
return 1
else
else
$( which ssh) $SSH_COMP -i $SSH_RSA_PRIVATE_KEY $REMOTE_USER @$REMOTE_HOST -p $REMOTE_PORT " $1 " > /dev/shm/osync_run_remote_$SCRIPT_PID &
$( which ssh) $SSH_COMP -i $SSH_RSA_PRIVATE_KEY $REMOTE_USER @$REMOTE_HOST -p $REMOTE_PORT " $1 " > /dev/shm/osync_run_remote_$SCRIPT_PID &
fi
fi
child_pid = $!
child_pid = $!
WaitForTaskCompletition $child_pid 0 $2
WaitForTaskCompletition $child_pid 0 $2
wait $child_pid
wait $child_pid
retval = $?
retval = $?
if [ $retval -eq 0 ]
if [ $retval -eq 0 ]
then
then
Log " Running command [ $1 ] succeded. "
Log " Running command [ $1 ] succeded. "
else
else
LogError " Running command [ $1 ] failed. "
LogError " Running command [ $1 ] failed. "
fi
fi
Log "Command output:"
if [ -f /dev/shm/osync_run_remote_$SCRIPT_PID ]
Log " $( cat /dev/shm/osync_run_remote_$SCRIPT_PID ) "
then
fi
Log " Command output: $( cat /dev/shm/osync_run_remote_$SCRIPT_PID ) "
fi
fi
}
}
function RunBeforeHook
function RunBeforeHook
{
{
if [ " $LOCAL_RUN_BEFORE_CMD " != "" ]
if [ " $LOCAL_RUN_BEFORE_CMD " != "" ]
then
then
RunLocalCommand " $LOCAL_RUN_BEFORE_CMD " $MAX_EXEC_TIME_PER_CMD_BEFORE
RunLocalCommand " $LOCAL_RUN_BEFORE_CMD " $MAX_EXEC_TIME_PER_CMD_BEFORE
fi
fi
if [ " $REMOTE_RUN_BEFORE_CMD " != "" ]
if [ " $REMOTE_RUN_BEFORE_CMD " != "" ]
then
then
RunRemoteCommand " $REMOTE_RUN_BEFORE_CMD " $MAX_EXEC_TIME_PER_CMD_BEFORE
RunRemoteCommand " $REMOTE_RUN_BEFORE_CMD " $MAX_EXEC_TIME_PER_CMD_BEFORE
fi
fi
}
}
function RunAfterHook
function RunAfterHook
{
{
if [ " $LOCAL_RUN_AFTER_CMD " != "" ]
if [ " $LOCAL_RUN_AFTER_CMD " != "" ]
then
then
RunLocalCommand " $LOCAL_RUN_AFTER_CMD " $MAX_EXEC_TIME_PER_CMD_AFTER
RunLocalCommand " $LOCAL_RUN_AFTER_CMD " $MAX_EXEC_TIME_PER_CMD_AFTER
fi
fi
if [ " $REMOTE_RUN_AFTER_CMD " != "" ]
if [ " $REMOTE_RUN_AFTER_CMD " != "" ]
then
then
RunRemoteCommand " $REMOTE_RUN_AFTER_CMD " $MAX_EXEC_TIME_PER_CMD_AFTER
RunRemoteCommand " $REMOTE_RUN_AFTER_CMD " $MAX_EXEC_TIME_PER_CMD_AFTER
fi
fi
}
}
function SetCompressionOptions
function SetCompressionOptions
{
{
if [ " $COMPRESSION_PROGRAM " = = "xz" ] && type -p xz > /dev/null 2>& 1
if [ " $SSH_COMPRESSION " = = "yes" ]
then
then
COMPRESSION_EXTENSION = .xz
SSH_COMP = -C
elif [ " $COMPRESSION_PROGRAM " = = "lzma" ] && type -p lzma > /dev/null 2>& 1
else
SSH_COMP =
fi
}
function SetSudoOptions
{
## Add this to support prior config files without RSYNC_EXECUTABLE option
if [ " $RSYNC_EXECUTABLE " = = "" ]
then
RSYNC_EXECUTABLE = rsync
fi
if [ " $SUDO_EXEC " = = "yes" ]
then
RSYNC_PATH = " sudo $( which $RSYNC_EXECUTABLE ) "
COMMAND_SUDO = "sudo"
else
RSYNC_PATH = " $( which $RSYNC_EXECUTABLE ) "
COMMAND_SUDO = ""
fi
}
function CheckConnectivityRemoteHost
{
if [ " $REMOTE_HOST_PING " != "no" ] && [ " $REMOTE_SYNC " != "no" ]
then
ping $REMOTE_HOST -c 2 > /dev/null 2>& 1
if [ $? != 0 ]
then
LogError " Cannot ping $REMOTE_HOST "
return 1
fi
fi
}
function CheckConnectivity3rdPartyHosts
{
if [ " $REMOTE_3RD_PARTY_HOSTS " != "" ]
then
remote_3rd_party_success = 0
for $i in $REMOTE_3RD_PARTY_HOSTS
do
ping $i -c 2 > /dev/null 2>& 1
if [ $? != 0 ]
then
LogError " Cannot ping 3rd party host $i "
else
remote_3rd_party_success = 1
fi
done
if [ $remote_3rd_party_success -ne 1 ]
then
LogError "No remote 3rd party host responded to ping. No internet ?"
return 1
fi
fi
}
function CreateDirs
{
if ! [ -d $MASTER_SYNC_DIR /$OSYNC_DIR ]
then
then
COMPRESSION_EXTENSION = .lzma
mkdir $MASTER_SYNC_DIR /$OSYNC_DIR
elif [ " $COMPRESSION_PROGRAM " = = "gzip" ] && type -p gzip > /dev/null 2>& 1
then
COMPRESSION_EXTENSION = .gz
COMPRESSION_OPTIONS = --rsyncable
else
COMPRESSION_EXTENSION =
fi
fi
if ! [ -d $STATE_DIR ]
if [ " $SSH_COMPRESSION " = = "yes" ]
then
then
SSH_COMP = -C
mkdir $STATE_DIR
else
SSH_COMP =
fi
fi
}
}
function SetSudoOptions
function CheckMasterSlaveDir s
{
{
if [ " $SUDO_EXEC " = = "yes" ]
if ! [ -d $MASTER_SYNC_DIR ]
then
then
RSYNC_PATH = " sudo $( which rsync) "
LogError " Master directory [ $MASTER_SYNC_DIR ] does not exist. "
COMMAND_SUDO = "sudo"
return 1
else
RSYNC_PATH = " $( which rsync) "
COMMAND_SUDO = ""
fi
fi
}
function CreateLocalStorageDirectories
if ! [ -d $SLAVE_SYNC_DIR ]
{
if [ ! -d $LOCAL_FILE_STORAGE ] && [ " $BACKUP_FILES " != "no" ]
then
then
mkdir -p $LOCAL_FILE_STORAGE
LogError " Slave directory [ $SLAVE_SYNC_DIR ] does not exist. "
return 1
fi
fi
}
}
function CheckLocalSpace
function LockMaster
{
echo o
}
function LockSlave
{
{
# Not elegant solution to make df silent on errors
echo o
df -P $LOCAL_FILE_STORAGE > /dev/shm/osync_local_space_$SCRIPT_PID 2>& 1
}
if [ $? != 0 ]
function Sync
{
## decide if local or remote prevalence
## Lock master dir
## Lock slave dir
Log "Starting synchronization task."
## Create local file list
Log "Creating current master file list"
rsync -rlptgodE --exclude " $OSYNC_DIR " --list-only $MASTER_SYNC_DIR / | grep "^-\|^d" | awk '{print $5}' | grep -v " ^\. $" > $STATE_DIR /master-tree-current
Log "Creating current slave file list"
## Create distant file list
rsync -rlptgodE --exclude " $OSYNC_DIR " --list-only $SLAVE_SYNC_DIR / | grep "^-\|^d" | awk '{print $5}' | grep -v " ^\. $" > $STATE_DIR /slave-tree-current
## diff local file list and before file list except if before file list is empty >> deleted
Log "Creating master deleted file list"
if [ -f $STATE_DIR /master-tree-before ]
then
then
LOCAL_SPACE = 0
comm --nocheck-order -23 $STATE_DIR /master-tree-before $STATE_DIR /master-tree-current > $STATE_DIR /master-deleted-list
else
else
LOCAL_SPACE = $( cat /dev/shm/osync_local_space_$SCRIPT_PID | tail -1 | awk '{print $4}' )
touch $STATE_DIR /master-deleted-list
fi
fi
if [ $LOCAL_SPACE -eq 0 ]
## diff local file list and before file list except if before file list is empty >> deleted
Log "Creating slave deleted file list"
if [ -f $STATE_DIR /slave-tree-before ]
then
then
LogError "Local disk space reported to be 0 Ko. This may also happen if local storage path doesn't exist."
comm --nocheck-order -23 $STATE_DIR /slave-tree-before $STATE_DIR /slave-tree-current > $STATE_DIR /slave-deleted-list
elif [ $SYNC_SIZE_MINIMUM -gt $(( $TOTAL_DATABASES_SIZE + $TOTAL_FILES_SIZE )) ]
else
then
touch $STATE_DIR /slave-deleted-list
LogError "Backup size is smaller then expected."
elif [ $LOCAL_STORAGE_WARN_MIN_SPACE -gt $LOCAL_SPACE ]
then
LogError " Local disk space is lower than warning value ( $LOCAL_SPACE free Ko). "
elif [ $LOCAL_SPACE -lt $(( $TOTAL_DATABASES_SIZE + $TOTAL_FILES_SIZE )) ]
then
LogError "Local disk space may be insufficient (depending on rsync delta and DB compression ratio)."
fi
fi
Log " Local Space: $LOCAL_SPACE Ko - Databases size: $TOTAL_DATABASES_SIZE Ko - Files size: $TOTAL_FILES_SIZE Ko "
## update local -> remote except deleted
Log "Updating slave replica"
rsync -rlptgodEui --backup --backup-dir " $MASTER_BACKUP_DIR " --exclude " $OSYNC_DIR " --exclude-from " $STATE_DIR /master-deleted-list " --exclude-from " $STATE_DIR /slave-deleted-list " $MASTER_SYNC_DIR / $SLAVE_SYNC_DIR /
## update remote -> local except deleted
Log "Updating master replica"
rsync -rlptgodEui --backup --backup-dir " $SLAVE_BACKUP_DIR " --exclude " $OSYNC_DIR " --exclude-from " $STATE_DIR /slave-deleted-list " --exclude-from " $STATE_DIR /master-deleted-list " $SLAVE_SYNC_DIR / $MASTER_SYNC_DIR /
Log "Propagating deletitions to slave"
rsync -rlptgodEui --backup --backup-dir " $MASTER_DELETE_DIR " --delete --exclude " $OSYNC_DIR " --include-from " $STATE_DIR /master-deleted-list " --exclude= '*' $MASTER_SYNC_DIR / $SLAVE_SYNC_DIR /
Log "Propagating deletitions to master"
rsync -rlptgodEui --backup --backup-dir " $SLAVE_DELETE_DIR " --delete --exclude " $OSYNC_DIR " --include-from " $STATE_DIR /slave-deleted-list " --exclude= '*' $SLAVE_SYNC_DIR / $MASTER_SYNC_DIR /
## Create local file list
Log "Creating new master file list"
rsync -rlptgodE --exclude " $OSYNC_DIR " --list-only $MASTER_SYNC_DIR / | grep "^-\|^d" | awk '{print $5}' | grep -v " ^\. $" > $STATE_DIR /master-tree-before
Log "Creating new slave file list"
## Create distant file list
rsync -rlptgodE --exclude " $OSYNC_DIR " --list-only $SLAVE_SYNC_DIR / | grep "^-\|^d" | awk '{print $5}' | grep -v " ^\. $" > $STATE_DIR /slave-tree-before
Log "Finished synchronization task."
}
}
function CheckTotalExecutionTime
function SoftDelet e
{
{
#### Check if max execution time of whole script as been reached
echo softd
if [ $SECONDS -gt $SOFT_MAX_EXEC_TIME_TOTAL ]
}
function Init
{
# Set error exit code if a piped command fails
set -o pipefail
set -o errtrace
trap TrapStop SIGINT SIGQUIT
if [ " $DEBUG " = = "yes" ]
then
then
if [ $soft_alert_total -eq 0 ]
trap 'TrapError ${LINENO} $?' ERR
then
LogError " Max soft execution time of the whole sync exceeded while backing up $BACKUP_TASK . "
soft_alert_total = 1
fi
if [ $SECONDS -gt $HARD_MAX_EXEC_TIME_TOTAL ]
then
LogError " Max hard execution time of the whole backup exceeded while backing up $BACKUP_TASK , stopping backup process. "
exit 1
fi
fi
fi
LOG_FILE = /var/log/osync_$osync_VERSION -$BACKUP_ID .log
MAIL_ALERT_MSG = " Warning: Execution of osync instance $OSYNC_ID (pid $SCRIPT_PID ) as $LOCAL_USER @ $LOCAL_HOST produced errors. "
STATE_DIR = " $MASTER_SYNC_DIR / $OSYNC_DIR /state "
## Working directories to keep backups of updated / deleted files
MASTER_BACKUP_DIR = " $MASTER_SYNC_DIR / $OSYNC_DIR /backups "
MASTER_DELETE_DIR = " $MASTER_SYNC_DIR / $OSYNC_DIR /deleted "
SLAVE_BACKUP_DIR = " $SLAVE_SYNC_DIR / $OSYNC_DIR /backups "
SLAVE_DELETE_DIR = " $SLAVE_SYNC_DIR / $OSYNC_DIR /deleted "
}
}
function CheckConnectivityRemoteHost
function DryRun
{
{
if [ " $REMOTE_HOST_PING " != "no" ]
echo dry
then
ping $REMOTE_HOST -c 2 > /dev/null 2>& 1
if [ $? != 0 ]
then
LogError " Cannot ping $REMOTE_HOST "
return 1
fi
fi
}
}
function CheckConnectivity3rdPartyHosts
function Main
{
CreateDirs
Sync
}
function Usage
{
{
if [ " $REMOTE_3RD_PARTY_HOSTS " != "" ]
echo " Osync $OSYNC_VERSION $OSYNC_BUILD "
echo ""
echo "usage: osync /path/to/conf.file [--dry] [--silent]"
echo ""
echo "--dry: will run osync without actuallyv doing anything; just testing"
echo "--silent: will run osync without any output to stdout, usefull for cron jobs"
exit 128
}
# Comand line argument flags
dryrun = 0
silent = 0
# Alert flags
soft_alert_total = 0
error_alert = 0
if [ $# -eq 0 ]
then
Usage
exit
fi
for i in " $@ "
do
case $i in
--dry)
dryrun = 1
; ;
--silent)
silent = 1
; ;
--help| -h)
Usage
; ;
esac
done
CheckEnvironment
if [ $? = = 0 ]
then
if [ " $1 " != "" ]
then
then
remote_3rd_party_success = 0
LoadConfigFile $1
for $i in $REMOTE_3RD_PARTY_HOSTS
if [ $? = = 0 ]
do
then
ping $i -c 2 > /dev/null 2>& 1
Init
if [ $? != 0 ]
DATE = $( date)
Log "---------------------------------------------------------"
Log " $DATE - Osync v $OSYNC_VERSION script begin. "
Log "----------------------------------------------------------"
CheckMasterSlaveDirs
if [ $? = = 0 ]
then
then
LogError " Cannot ping 3rd party host $i "
if [ $dryrun -eq 1 ]
else
then
remote_3rd_party_success = 1
DryRun
else
RunBeforeHook
Main
RunAfterHook
fi
CleanUp
fi
fi
done
else
if [ $remote_3rd_party_success -ne 1 ]
LogError "Configuration file could not be loaded."
then
exit 1
LogError "No remote 3rd party host responded to ping. No internet ?"
return 1
fi
fi
else
LogError "No configuration file provided."
exit 1
fi
fi
}
else
LogError "Environment not suitable to run osync."
fi
if [ $error_alert -ne 0 ]
then
SendAlert
LogError "Osync finished with errros."
exit 1
else
Log "Osync script finished."
exit 0
fi