mirror of
https://github.com/deajan/obackup.git
synced 2024-12-25 23:13:41 +01:00
Rebuilt targets
This commit is contained in:
parent
9aaf4ff11d
commit
4755fbacb7
@ -5,12 +5,12 @@ PROGRAM="obackup"
|
|||||||
AUTHOR="(C) 2013-2016 by Orsiris de Jong"
|
AUTHOR="(C) 2013-2016 by Orsiris de Jong"
|
||||||
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
||||||
PROGRAM_VERSION=2.1-dev
|
PROGRAM_VERSION=2.1-dev
|
||||||
PROGRAM_BUILD=2016082202
|
PROGRAM_BUILD=2016082603
|
||||||
IS_STABLE=no
|
IS_STABLE=no
|
||||||
|
|
||||||
#### MINIMAL-FUNCTION-SET BEGIN ####
|
#### MINIMAL-FUNCTION-SET BEGIN ####
|
||||||
|
|
||||||
## FUNC_BUILD=2016082204
|
## FUNC_BUILD=2016082605
|
||||||
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
||||||
|
|
||||||
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
|
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
|
||||||
@ -38,6 +38,9 @@ fi
|
|||||||
ERROR_ALERT=0
|
ERROR_ALERT=0
|
||||||
WARN_ALERT=0
|
WARN_ALERT=0
|
||||||
|
|
||||||
|
# Current log
|
||||||
|
CURRENT_LOG
|
||||||
|
|
||||||
## allow function call checks #__WITH_PARANOIA_DEBUG
|
## allow function call checks #__WITH_PARANOIA_DEBUG
|
||||||
if [ "$_PARANOIA_DEBUG" == "yes" ];then #__WITH_PARANOIA_DEBUG
|
if [ "$_PARANOIA_DEBUG" == "yes" ];then #__WITH_PARANOIA_DEBUG
|
||||||
_DEBUG=yes #__WITH_PARANOIA_DEBUG
|
_DEBUG=yes #__WITH_PARANOIA_DEBUG
|
||||||
@ -99,6 +102,7 @@ function _Logger {
|
|||||||
local evalue="${3}" # What to log to stderr
|
local evalue="${3}" # What to log to stderr
|
||||||
|
|
||||||
echo -e "$lvalue" >> "$LOG_FILE"
|
echo -e "$lvalue" >> "$LOG_FILE"
|
||||||
|
CURRENT_LOG="$CURRENT_LOG"$'\n'"$lvalue"
|
||||||
|
|
||||||
if [ "$_LOGGER_STDERR" -eq 1 ]; then
|
if [ "$_LOGGER_STDERR" -eq 1 ]; then
|
||||||
cat <<< "$evalue" 1>&2
|
cat <<< "$evalue" 1>&2
|
||||||
@ -230,11 +234,14 @@ function KillAllChilds {
|
|||||||
|
|
||||||
# osync/obackup/pmocr script specific mail alert function, use SendEmail function for generic mail sending
|
# osync/obackup/pmocr script specific mail alert function, use SendEmail function for generic mail sending
|
||||||
function SendAlert {
|
function SendAlert {
|
||||||
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
local runAlert="${1:-false}" # Specifies if current message is sent while running or at the end of a run
|
||||||
|
|
||||||
|
__CheckArguments 0-1 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
local mail_no_attachment=
|
local mail_no_attachment=
|
||||||
local attachment_command=
|
local attachment_command=
|
||||||
local subject=
|
local subject=
|
||||||
|
local body=
|
||||||
|
|
||||||
# Windows specific settings
|
# Windows specific settings
|
||||||
local encryption_string=
|
local encryption_string=
|
||||||
@ -263,7 +270,8 @@ function SendAlert {
|
|||||||
else
|
else
|
||||||
mail_no_attachment=0
|
mail_no_attachment=0
|
||||||
fi
|
fi
|
||||||
MAIL_ALERT_MSG="$MAIL_ALERT_MSG"$'\n\n'$(tail -n 50 "$LOG_FILE")
|
body="$MAIL_ALERT_MSG"$'\n\n'"$CURRENT_LOG"
|
||||||
|
|
||||||
if [ $ERROR_ALERT -eq 1 ]; then
|
if [ $ERROR_ALERT -eq 1 ]; then
|
||||||
subject="Error alert for $INSTANCE_ID"
|
subject="Error alert for $INSTANCE_ID"
|
||||||
elif [ $WARN_ALERT -eq 1 ]; then
|
elif [ $WARN_ALERT -eq 1 ]; then
|
||||||
@ -272,11 +280,17 @@ function SendAlert {
|
|||||||
subject="Alert for $INSTANCE_ID"
|
subject="Alert for $INSTANCE_ID"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $runAlert == true ]; then
|
||||||
|
subject="Currently runing - $subject"
|
||||||
|
else
|
||||||
|
subject="Fnished run - $subject"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$mail_no_attachment" -eq 0 ]; then
|
if [ "$mail_no_attachment" -eq 0 ]; then
|
||||||
attachment_command="-a $ALERT_LOG_FILE"
|
attachment_command="-a $ALERT_LOG_FILE"
|
||||||
fi
|
fi
|
||||||
if type mutt > /dev/null 2>&1 ; then
|
if type mutt > /dev/null 2>&1 ; then
|
||||||
echo "$MAIL_ALERT_MSG" | $(type -p mutt) -x -s "$subject" $DESTINATION_MAILS $attachment_command
|
echo "$body" | $(type -p mutt) -x -s "$subject" $DESTINATION_MAILS $attachment_command
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert mail via $(type -p mutt) !!!" "WARN"
|
Logger "Cannot send alert mail via $(type -p mutt) !!!" "WARN"
|
||||||
else
|
else
|
||||||
@ -293,10 +307,10 @@ function SendAlert {
|
|||||||
else
|
else
|
||||||
attachment_command=""
|
attachment_command=""
|
||||||
fi
|
fi
|
||||||
echo "$MAIL_ALERT_MSG" | $(type -p mail) $attachment_command -s "$subject" $DESTINATION_MAILS
|
echo "$body" | $(type -p mail) $attachment_command -s "$subject" $DESTINATION_MAILS
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert mail via $(type -p mail) with attachments !!!" "WARN"
|
Logger "Cannot send alert mail via $(type -p mail) with attachments !!!" "WARN"
|
||||||
echo "$MAIL_ALERT_MSG" | $(type -p mail) -s "$subject" $DESTINATION_MAILS
|
echo "$body" | $(type -p mail) -s "$subject" $DESTINATION_MAILS
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert mail via $(type -p mail) without attachments !!!" "WARN"
|
Logger "Cannot send alert mail via $(type -p mail) without attachments !!!" "WARN"
|
||||||
else
|
else
|
||||||
@ -310,7 +324,7 @@ function SendAlert {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if type sendmail > /dev/null 2>&1 ; then
|
if type sendmail > /dev/null 2>&1 ; then
|
||||||
echo -e "Subject:$subject\r\n$MAIL_ALERT_MSG" | $(type -p sendmail) $DESTINATION_MAILS
|
echo -e "Subject:$subject\r\n$body" | $(type -p sendmail) $DESTINATION_MAILS
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert mail via $(type -p sendmail) !!!" "WARN"
|
Logger "Cannot send alert mail via $(type -p sendmail) !!!" "WARN"
|
||||||
else
|
else
|
||||||
@ -333,7 +347,7 @@ function SendAlert {
|
|||||||
if [ "$SMTP_USER" != "" ] && [ "$SMTP_USER" != "" ]; then
|
if [ "$SMTP_USER" != "" ] && [ "$SMTP_USER" != "" ]; then
|
||||||
auth_string="-auth -user \"$SMTP_USER\" -pass \"$SMTP_PASSWORD\""
|
auth_string="-auth -user \"$SMTP_USER\" -pass \"$SMTP_PASSWORD\""
|
||||||
fi
|
fi
|
||||||
$(type mailsend.exe) -f $SENDER_MAIL -t "$DESTINATION_MAILS" -sub "$subject" -M "$MAIL_ALERT_MSG" -attach "$attachment" -smtp "$SMTP_SERVER" -port "$SMTP_PORT" $encryption_string $auth_string
|
$(type mailsend.exe) -f $SENDER_MAIL -t "$DESTINATION_MAILS" -sub "$subject" -M "$body" -attach "$attachment" -smtp "$SMTP_SERVER" -port "$SMTP_PORT" $encryption_string $auth_string
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send mail via $(type mailsend.exe) !!!" "WARN"
|
Logger "Cannot send mail via $(type mailsend.exe) !!!" "WARN"
|
||||||
else
|
else
|
||||||
@ -349,7 +363,7 @@ function SendAlert {
|
|||||||
else
|
else
|
||||||
SMTP_OPTIONS=""
|
SMTP_OPTIONS=""
|
||||||
fi
|
fi
|
||||||
$(type -p sendemail) -f $SENDER_MAIL -t "$DESTINATION_MAILS" -u "$subject" -m "$MAIL_ALERT_MSG" -s $SMTP_SERVER $SMTP_OPTIONS > /dev/null 2>&1
|
$(type -p sendemail) -f $SENDER_MAIL -t "$DESTINATION_MAILS" -u "$subject" -m "$body" -s $SMTP_SERVER $SMTP_OPTIONS > /dev/null 2>&1
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert mail via $(type -p sendemail) !!!" "WARN"
|
Logger "Cannot send alert mail via $(type -p sendemail) !!!" "WARN"
|
||||||
else
|
else
|
||||||
@ -360,7 +374,7 @@ function SendAlert {
|
|||||||
|
|
||||||
# pfSense specific
|
# pfSense specific
|
||||||
if [ -f /usr/local/bin/mail.php ]; then
|
if [ -f /usr/local/bin/mail.php ]; then
|
||||||
echo "$MAIL_ALERT_MSG" | /usr/local/bin/mail.php -s="$subject"
|
echo "$body" | /usr/local/bin/mail.php -s="$subject"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert mail via /usr/local/bin/mail.php (pfsense) !!!" "WARN"
|
Logger "Cannot send alert mail via /usr/local/bin/mail.php (pfsense) !!!" "WARN"
|
||||||
else
|
else
|
||||||
@ -630,7 +644,7 @@ function WaitForTaskCompletion {
|
|||||||
if [ $soft_alert -eq 0 ] && [ $soft_max_time -ne 0 ]; then
|
if [ $soft_alert -eq 0 ] && [ $soft_max_time -ne 0 ]; then
|
||||||
Logger "Max soft execution time exceeded for task [$caller_name] with pids [$(joinString , ${pidsArray[@]})]." "WARN"
|
Logger "Max soft execution time exceeded for task [$caller_name] with pids [$(joinString , ${pidsArray[@]})]." "WARN"
|
||||||
soft_alert=1
|
soft_alert=1
|
||||||
SendAlert
|
SendAlert true
|
||||||
|
|
||||||
fi
|
fi
|
||||||
if [ $exec_time -gt $hard_max_time ] && [ $hard_max_time -ne 0 ]; then
|
if [ $exec_time -gt $hard_max_time ] && [ $hard_max_time -ne 0 ]; then
|
||||||
@ -643,7 +657,7 @@ function WaitForTaskCompletion {
|
|||||||
Logger "Could not stop task with pid [$pid]." "ERROR"
|
Logger "Could not stop task with pid [$pid]." "ERROR"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
SendAlert
|
SendAlert true
|
||||||
errrorcount=$((errorcount+1))
|
errrorcount=$((errorcount+1))
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -979,7 +993,7 @@ function CheckConnectivityRemoteHost {
|
|||||||
|
|
||||||
if [ "$REMOTE_HOST_PING" != "no" ] && [ "$REMOTE_OPERATION" != "no" ]; then
|
if [ "$REMOTE_HOST_PING" != "no" ] && [ "$REMOTE_OPERATION" != "no" ]; then
|
||||||
eval "$PING_CMD $REMOTE_HOST > /dev/null 2>&1" &
|
eval "$PING_CMD $REMOTE_HOST > /dev/null 2>&1" &
|
||||||
WaitForTaskCompletion $! 10 180 ${FUNCNAME[0]} true $KEEP_LOGGING
|
WaitForTaskCompletion $! 60 180 ${FUNCNAME[0]} true $KEEP_LOGGING
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot ping $REMOTE_HOST" "ERROR"
|
Logger "Cannot ping $REMOTE_HOST" "ERROR"
|
||||||
return 1
|
return 1
|
||||||
@ -1024,12 +1038,15 @@ function __CheckArguments {
|
|||||||
# Checks the number of arguments of a function and raises an error if some are missing
|
# Checks the number of arguments of a function and raises an error if some are missing
|
||||||
|
|
||||||
if [ "$_DEBUG" == "yes" ]; then
|
if [ "$_DEBUG" == "yes" ]; then
|
||||||
local number_of_arguments="${1}" # Number of arguments the tested function should have
|
local numberOfArguments="${1}" # Number of arguments the tested function should have, can be a number of a range, eg 0-2 for zero to two arguments
|
||||||
local number_of_given_arguments="${2}" # Number of arguments that have been passed
|
local numberOfGivenArguments="${2}" # Number of arguments that have been passed
|
||||||
local function_name="${3}" # Function name that called __CheckArguments
|
local functionName="${3}" # Function name that called __CheckArguments
|
||||||
|
|
||||||
|
local minArgs
|
||||||
|
local maxArgs
|
||||||
|
|
||||||
if [ "$_PARANOIA_DEBUG" == "yes" ]; then
|
if [ "$_PARANOIA_DEBUG" == "yes" ]; then
|
||||||
Logger "Entering function [$function_name]." "DEBUG"
|
Logger "Entering function [$functionName]." "DEBUG"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# All arguments of the function to check are passed as array in ${4} (the function call waits for $@)
|
# All arguments of the function to check are passed as array in ${4} (the function call waits for $@)
|
||||||
@ -1037,23 +1054,31 @@ function __CheckArguments {
|
|||||||
# In order to avoid this, we need to iterate over ${4} and count
|
# In order to avoid this, we need to iterate over ${4} and count
|
||||||
|
|
||||||
local iterate=4
|
local iterate=4
|
||||||
local fetch_arguments=1
|
local fetchArguments=1
|
||||||
local arg_list=""
|
local argList=""
|
||||||
while [ $fetch_arguments -eq 1 ]; do
|
local countedArguments
|
||||||
|
while [ $fetchArguments -eq 1 ]; do
|
||||||
cmd='argument=${'$iterate'}'
|
cmd='argument=${'$iterate'}'
|
||||||
eval $cmd
|
eval $cmd
|
||||||
if [ "$argument" = "" ]; then
|
if [ "$argument" = "" ]; then
|
||||||
fetch_arguments=0
|
fetchArguments=0
|
||||||
else
|
else
|
||||||
arg_list="$arg_list [Argument $(($iterate-3)): $argument]"
|
argList="$arg_list [Argument $(($iterate-3)): $argument]"
|
||||||
iterate=$(($iterate+1))
|
iterate=$(($iterate+1))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
local counted_arguments=$((iterate-4))
|
countedArguments=$((iterate-4))
|
||||||
|
|
||||||
if [ $counted_arguments -ne $number_of_arguments ]; then
|
if [ $(IsNumeric "$numberOfArguments") -eq 1 ]; then
|
||||||
Logger "Function $function_name may have inconsistent number of arguments. Expected: $number_of_arguments, count: $counted_arguments, bash seen: $number_of_given_arguments. see log file." "ERROR"
|
minArgs=$numberOfArguments
|
||||||
Logger "Arguments passed: $arg_list" "ERROR"
|
maxArgs=$numberOfArguments
|
||||||
|
else
|
||||||
|
IFS='-' read minArgs maxArgs <<< "$numberOfArguments"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! ([ $countedArguments -ge $minArgs ] && [ $countedArguments -le $maxArgs ]); then
|
||||||
|
Logger "Function $functionName may have inconsistent number of arguments. Expected min: $minArgs, max: $maxArgs, count: $countedArguments, bash seen: $numberOfGivenArguments. see log file." "ERROR"
|
||||||
|
Logger "Arguments passed: $argList" "ERROR"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -1297,7 +1322,6 @@ function InitLocalOSSettings {
|
|||||||
function InitRemoteOSSettings {
|
function InitRemoteOSSettings {
|
||||||
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
__CheckArguments 0 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
#TODO: fix add -E when both initiator and targets don't run MacOSX and PRESERVE_EXECUTABILITY=yes
|
|
||||||
## MacOSX does not use the -E parameter like Linux or BSD does (-E is mapped to extended attrs instead of preserve executability)
|
## MacOSX does not use the -E parameter like Linux or BSD does (-E is mapped to extended attrs instead of preserve executability)
|
||||||
if [ "$PRESERVE_EXECUTABILITY" != "no" ];then
|
if [ "$PRESERVE_EXECUTABILITY" != "no" ];then
|
||||||
if [ "$LOCAL_OS" != "MacOSX" ] && [ "$REMOTE_OS" != "MacOSX" ]; then
|
if [ "$LOCAL_OS" != "MacOSX" ] && [ "$REMOTE_OS" != "MacOSX" ]; then
|
||||||
@ -1357,20 +1381,20 @@ function TrapQuit {
|
|||||||
local exitcode
|
local exitcode
|
||||||
|
|
||||||
if [ $ERROR_ALERT -ne 0 ]; then
|
if [ $ERROR_ALERT -ne 0 ]; then
|
||||||
SendAlert
|
|
||||||
if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then
|
if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then
|
||||||
RunAfterHook
|
RunAfterHook
|
||||||
fi
|
fi
|
||||||
CleanUp
|
CleanUp
|
||||||
Logger "Backup script finished with errors." "ERROR"
|
Logger "Backup script finished with errors." "ERROR"
|
||||||
|
SendAlert
|
||||||
exitcode=1
|
exitcode=1
|
||||||
elif [ $WARN_ALERT -ne 0 ]; then
|
elif [ $WARN_ALERT -ne 0 ]; then
|
||||||
SendAlert
|
|
||||||
if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then
|
if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then
|
||||||
RunAfterHook
|
RunAfterHook
|
||||||
fi
|
fi
|
||||||
CleanUp
|
CleanUp
|
||||||
Logger "Backup script finished with warnings." "WARN"
|
Logger "Backup script finished with warnings." "WARN"
|
||||||
|
SendAlert
|
||||||
exitcode=2
|
exitcode=2
|
||||||
else
|
else
|
||||||
RunAfterHook
|
RunAfterHook
|
||||||
@ -1410,8 +1434,8 @@ function CheckEnvironment {
|
|||||||
|
|
||||||
if [ "$FILE_BACKUP" != "no" ]; then
|
if [ "$FILE_BACKUP" != "no" ]; then
|
||||||
if [ "$ENCRYPTION" == "yes" ]; then
|
if [ "$ENCRYPTION" == "yes" ]; then
|
||||||
if ! type duplicity > /dev/null 2>&1 ; then
|
if ! type gpg > /dev/null 2>&1 ; then
|
||||||
Logger "duplicity not present. Cannot backup encrypted files." "CRITICAL"
|
Logger "gpg not present. Cannot encrypt backup files." "CRITICAL"
|
||||||
CAN_BACKUP_FILES=0
|
CAN_BACKUP_FILES=0
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@ -1458,6 +1482,15 @@ function CheckCurrentConfig {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
#TODO-v2.1: Add runtime variable tests (RSYNC_ARGS etc)
|
#TODO-v2.1: Add runtime variable tests (RSYNC_ARGS etc)
|
||||||
|
if [ "$REMOTE_OPERATION" == "yes" ] && [ ! -f "$SSH_RSA_PRIVATE_KEY" ]; then
|
||||||
|
Logger "Cannot find rsa private key [$SSH_RSA_PRIVATE_KEY]. Cannot connect to remote system." "CRITICAL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "$ENCRYPT_GPG_PYUBKEY" ]; then
|
||||||
|
Logger "Cannot find gpg pubkey [$ENCRPYT_GPG_PUBKEY]. Cannot encrypt backup files." "CRITICAL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function CheckRunningInstances {
|
function CheckRunningInstances {
|
||||||
@ -2135,18 +2168,33 @@ function BackupDatabases {
|
|||||||
for database in $SQL_BACKUP_TASKS
|
for database in $SQL_BACKUP_TASKS
|
||||||
do
|
do
|
||||||
Logger "Backing up database [$database]." "NOTICE"
|
Logger "Backing up database [$database]." "NOTICE"
|
||||||
BackupDatabase $database &
|
BackupDatabase $database
|
||||||
WaitForTaskCompletion $! $SOFT_MAX_EXEC_TIME_DB_TASK $HARD_MAX_EXEC_TIME_DB_TASK ${FUNCNAME[0]} true $KEEP_LOGGING
|
|
||||||
CheckTotalExecutionTime
|
CheckTotalExecutionTime
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function EncryptFiles {
|
function PrepareEncryptFiles {
|
||||||
|
local tmpPath="${2}"
|
||||||
|
|
||||||
|
__CheckArguments 1 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
|
if [ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]; then
|
||||||
|
_CreateDirsLocal "$tmpPath"
|
||||||
|
elif [ "$BACKUP_TYPE" == "pull" ]; then
|
||||||
|
Logger "Encryption only works with [local] or [push] backup types." "CRITICAL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
#WIP: check disk space in tmp dir and compare to backup size else error
|
||||||
|
}
|
||||||
|
|
||||||
|
function EncrpytFiles {
|
||||||
local filePath="${1}" # Path of files to encrypt
|
local filePath="${1}" # Path of files to encrypt
|
||||||
local tmpPath="${2}"
|
local tmpPath="${2}"
|
||||||
|
|
||||||
__CheckArguments 2 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
__CheckArguments 2 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
|
||||||
|
|
||||||
|
#WIP: template code to split into local & remote code
|
||||||
|
|
||||||
#crypt_cmd source temp
|
#crypt_cmd source temp
|
||||||
# Send files to remote, rotate & copy
|
# Send files to remote, rotate & copy
|
||||||
}
|
}
|
||||||
@ -2293,7 +2341,7 @@ function CheckTotalExecutionTime {
|
|||||||
if [ $SECONDS -gt $SOFT_MAX_EXEC_TIME_TOTAL ]; then
|
if [ $SECONDS -gt $SOFT_MAX_EXEC_TIME_TOTAL ]; then
|
||||||
Logger "Max soft execution time of the whole backup exceeded." "ERROR"
|
Logger "Max soft execution time of the whole backup exceeded." "ERROR"
|
||||||
WARN_ALERT=1
|
WARN_ALERT=1
|
||||||
SendAlert
|
SendAlert true
|
||||||
if [ $SECONDS -gt $HARD_MAX_EXEC_TIME_TOTAL ] && [ $HARD_MAX_EXEC_TIME_TOTAL -ne 0 ]; then
|
if [ $SECONDS -gt $HARD_MAX_EXEC_TIME_TOTAL ] && [ $HARD_MAX_EXEC_TIME_TOTAL -ne 0 ]; then
|
||||||
Logger "Max hard execution time of the whole backup exceeded, stopping backup process." "CRITICAL"
|
Logger "Max hard execution time of the whole backup exceeded, stopping backup process." "CRITICAL"
|
||||||
exit 1
|
exit 1
|
||||||
|
80
obackup.sh
80
obackup.sh
@ -5,12 +5,12 @@ PROGRAM="obackup"
|
|||||||
AUTHOR="(C) 2013-2016 by Orsiris de Jong"
|
AUTHOR="(C) 2013-2016 by Orsiris de Jong"
|
||||||
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
||||||
PROGRAM_VERSION=2.1-dev
|
PROGRAM_VERSION=2.1-dev
|
||||||
PROGRAM_BUILD=2016082202
|
PROGRAM_BUILD=2016082603
|
||||||
IS_STABLE=no
|
IS_STABLE=no
|
||||||
|
|
||||||
#### MINIMAL-FUNCTION-SET BEGIN ####
|
#### MINIMAL-FUNCTION-SET BEGIN ####
|
||||||
|
|
||||||
## FUNC_BUILD=2016082204
|
## FUNC_BUILD=2016082605
|
||||||
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
## BEGIN Generic functions for osync & obackup written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
||||||
|
|
||||||
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
|
## type -p does not work on platforms other than linux (bash). If if does not work, always assume output is not a zero exitcode
|
||||||
@ -38,6 +38,9 @@ fi
|
|||||||
ERROR_ALERT=0
|
ERROR_ALERT=0
|
||||||
WARN_ALERT=0
|
WARN_ALERT=0
|
||||||
|
|
||||||
|
# Current log
|
||||||
|
CURRENT_LOG
|
||||||
|
|
||||||
|
|
||||||
## allow debugging from command line with _DEBUG=yes
|
## allow debugging from command line with _DEBUG=yes
|
||||||
if [ ! "$_DEBUG" == "yes" ]; then
|
if [ ! "$_DEBUG" == "yes" ]; then
|
||||||
@ -94,6 +97,7 @@ function _Logger {
|
|||||||
local evalue="${3}" # What to log to stderr
|
local evalue="${3}" # What to log to stderr
|
||||||
|
|
||||||
echo -e "$lvalue" >> "$LOG_FILE"
|
echo -e "$lvalue" >> "$LOG_FILE"
|
||||||
|
CURRENT_LOG="$CURRENT_LOG"$'\n'"$lvalue"
|
||||||
|
|
||||||
if [ "$_LOGGER_STDERR" -eq 1 ]; then
|
if [ "$_LOGGER_STDERR" -eq 1 ]; then
|
||||||
cat <<< "$evalue" 1>&2
|
cat <<< "$evalue" 1>&2
|
||||||
@ -216,10 +220,13 @@ function KillAllChilds {
|
|||||||
|
|
||||||
# osync/obackup/pmocr script specific mail alert function, use SendEmail function for generic mail sending
|
# osync/obackup/pmocr script specific mail alert function, use SendEmail function for generic mail sending
|
||||||
function SendAlert {
|
function SendAlert {
|
||||||
|
local runAlert="${1:-false}" # Specifies if current message is sent while running or at the end of a run
|
||||||
|
|
||||||
|
|
||||||
local mail_no_attachment=
|
local mail_no_attachment=
|
||||||
local attachment_command=
|
local attachment_command=
|
||||||
local subject=
|
local subject=
|
||||||
|
local body=
|
||||||
|
|
||||||
# Windows specific settings
|
# Windows specific settings
|
||||||
local encryption_string=
|
local encryption_string=
|
||||||
@ -248,7 +255,8 @@ function SendAlert {
|
|||||||
else
|
else
|
||||||
mail_no_attachment=0
|
mail_no_attachment=0
|
||||||
fi
|
fi
|
||||||
MAIL_ALERT_MSG="$MAIL_ALERT_MSG"$'\n\n'$(tail -n 50 "$LOG_FILE")
|
body="$MAIL_ALERT_MSG"$'\n\n'"$CURRENT_LOG"
|
||||||
|
|
||||||
if [ $ERROR_ALERT -eq 1 ]; then
|
if [ $ERROR_ALERT -eq 1 ]; then
|
||||||
subject="Error alert for $INSTANCE_ID"
|
subject="Error alert for $INSTANCE_ID"
|
||||||
elif [ $WARN_ALERT -eq 1 ]; then
|
elif [ $WARN_ALERT -eq 1 ]; then
|
||||||
@ -257,11 +265,17 @@ function SendAlert {
|
|||||||
subject="Alert for $INSTANCE_ID"
|
subject="Alert for $INSTANCE_ID"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $runAlert == true ]; then
|
||||||
|
subject="Currently runing - $subject"
|
||||||
|
else
|
||||||
|
subject="Fnished run - $subject"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$mail_no_attachment" -eq 0 ]; then
|
if [ "$mail_no_attachment" -eq 0 ]; then
|
||||||
attachment_command="-a $ALERT_LOG_FILE"
|
attachment_command="-a $ALERT_LOG_FILE"
|
||||||
fi
|
fi
|
||||||
if type mutt > /dev/null 2>&1 ; then
|
if type mutt > /dev/null 2>&1 ; then
|
||||||
echo "$MAIL_ALERT_MSG" | $(type -p mutt) -x -s "$subject" $DESTINATION_MAILS $attachment_command
|
echo "$body" | $(type -p mutt) -x -s "$subject" $DESTINATION_MAILS $attachment_command
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert mail via $(type -p mutt) !!!" "WARN"
|
Logger "Cannot send alert mail via $(type -p mutt) !!!" "WARN"
|
||||||
else
|
else
|
||||||
@ -278,10 +292,10 @@ function SendAlert {
|
|||||||
else
|
else
|
||||||
attachment_command=""
|
attachment_command=""
|
||||||
fi
|
fi
|
||||||
echo "$MAIL_ALERT_MSG" | $(type -p mail) $attachment_command -s "$subject" $DESTINATION_MAILS
|
echo "$body" | $(type -p mail) $attachment_command -s "$subject" $DESTINATION_MAILS
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert mail via $(type -p mail) with attachments !!!" "WARN"
|
Logger "Cannot send alert mail via $(type -p mail) with attachments !!!" "WARN"
|
||||||
echo "$MAIL_ALERT_MSG" | $(type -p mail) -s "$subject" $DESTINATION_MAILS
|
echo "$body" | $(type -p mail) -s "$subject" $DESTINATION_MAILS
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert mail via $(type -p mail) without attachments !!!" "WARN"
|
Logger "Cannot send alert mail via $(type -p mail) without attachments !!!" "WARN"
|
||||||
else
|
else
|
||||||
@ -295,7 +309,7 @@ function SendAlert {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if type sendmail > /dev/null 2>&1 ; then
|
if type sendmail > /dev/null 2>&1 ; then
|
||||||
echo -e "Subject:$subject\r\n$MAIL_ALERT_MSG" | $(type -p sendmail) $DESTINATION_MAILS
|
echo -e "Subject:$subject\r\n$body" | $(type -p sendmail) $DESTINATION_MAILS
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert mail via $(type -p sendmail) !!!" "WARN"
|
Logger "Cannot send alert mail via $(type -p sendmail) !!!" "WARN"
|
||||||
else
|
else
|
||||||
@ -318,7 +332,7 @@ function SendAlert {
|
|||||||
if [ "$SMTP_USER" != "" ] && [ "$SMTP_USER" != "" ]; then
|
if [ "$SMTP_USER" != "" ] && [ "$SMTP_USER" != "" ]; then
|
||||||
auth_string="-auth -user \"$SMTP_USER\" -pass \"$SMTP_PASSWORD\""
|
auth_string="-auth -user \"$SMTP_USER\" -pass \"$SMTP_PASSWORD\""
|
||||||
fi
|
fi
|
||||||
$(type mailsend.exe) -f $SENDER_MAIL -t "$DESTINATION_MAILS" -sub "$subject" -M "$MAIL_ALERT_MSG" -attach "$attachment" -smtp "$SMTP_SERVER" -port "$SMTP_PORT" $encryption_string $auth_string
|
$(type mailsend.exe) -f $SENDER_MAIL -t "$DESTINATION_MAILS" -sub "$subject" -M "$body" -attach "$attachment" -smtp "$SMTP_SERVER" -port "$SMTP_PORT" $encryption_string $auth_string
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send mail via $(type mailsend.exe) !!!" "WARN"
|
Logger "Cannot send mail via $(type mailsend.exe) !!!" "WARN"
|
||||||
else
|
else
|
||||||
@ -334,7 +348,7 @@ function SendAlert {
|
|||||||
else
|
else
|
||||||
SMTP_OPTIONS=""
|
SMTP_OPTIONS=""
|
||||||
fi
|
fi
|
||||||
$(type -p sendemail) -f $SENDER_MAIL -t "$DESTINATION_MAILS" -u "$subject" -m "$MAIL_ALERT_MSG" -s $SMTP_SERVER $SMTP_OPTIONS > /dev/null 2>&1
|
$(type -p sendemail) -f $SENDER_MAIL -t "$DESTINATION_MAILS" -u "$subject" -m "$body" -s $SMTP_SERVER $SMTP_OPTIONS > /dev/null 2>&1
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert mail via $(type -p sendemail) !!!" "WARN"
|
Logger "Cannot send alert mail via $(type -p sendemail) !!!" "WARN"
|
||||||
else
|
else
|
||||||
@ -345,7 +359,7 @@ function SendAlert {
|
|||||||
|
|
||||||
# pfSense specific
|
# pfSense specific
|
||||||
if [ -f /usr/local/bin/mail.php ]; then
|
if [ -f /usr/local/bin/mail.php ]; then
|
||||||
echo "$MAIL_ALERT_MSG" | /usr/local/bin/mail.php -s="$subject"
|
echo "$body" | /usr/local/bin/mail.php -s="$subject"
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot send alert mail via /usr/local/bin/mail.php (pfsense) !!!" "WARN"
|
Logger "Cannot send alert mail via /usr/local/bin/mail.php (pfsense) !!!" "WARN"
|
||||||
else
|
else
|
||||||
@ -611,7 +625,7 @@ function WaitForTaskCompletion {
|
|||||||
if [ $soft_alert -eq 0 ] && [ $soft_max_time -ne 0 ]; then
|
if [ $soft_alert -eq 0 ] && [ $soft_max_time -ne 0 ]; then
|
||||||
Logger "Max soft execution time exceeded for task [$caller_name] with pids [$(joinString , ${pidsArray[@]})]." "WARN"
|
Logger "Max soft execution time exceeded for task [$caller_name] with pids [$(joinString , ${pidsArray[@]})]." "WARN"
|
||||||
soft_alert=1
|
soft_alert=1
|
||||||
SendAlert
|
SendAlert true
|
||||||
|
|
||||||
fi
|
fi
|
||||||
if [ $exec_time -gt $hard_max_time ] && [ $hard_max_time -ne 0 ]; then
|
if [ $exec_time -gt $hard_max_time ] && [ $hard_max_time -ne 0 ]; then
|
||||||
@ -624,7 +638,7 @@ function WaitForTaskCompletion {
|
|||||||
Logger "Could not stop task with pid [$pid]." "ERROR"
|
Logger "Could not stop task with pid [$pid]." "ERROR"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
SendAlert
|
SendAlert true
|
||||||
errrorcount=$((errorcount+1))
|
errrorcount=$((errorcount+1))
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -951,7 +965,7 @@ function CheckConnectivityRemoteHost {
|
|||||||
|
|
||||||
if [ "$REMOTE_HOST_PING" != "no" ] && [ "$REMOTE_OPERATION" != "no" ]; then
|
if [ "$REMOTE_HOST_PING" != "no" ] && [ "$REMOTE_OPERATION" != "no" ]; then
|
||||||
eval "$PING_CMD $REMOTE_HOST > /dev/null 2>&1" &
|
eval "$PING_CMD $REMOTE_HOST > /dev/null 2>&1" &
|
||||||
WaitForTaskCompletion $! 10 180 ${FUNCNAME[0]} true $KEEP_LOGGING
|
WaitForTaskCompletion $! 60 180 ${FUNCNAME[0]} true $KEEP_LOGGING
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
Logger "Cannot ping $REMOTE_HOST" "ERROR"
|
Logger "Cannot ping $REMOTE_HOST" "ERROR"
|
||||||
return 1
|
return 1
|
||||||
@ -1223,7 +1237,6 @@ function InitLocalOSSettings {
|
|||||||
|
|
||||||
function InitRemoteOSSettings {
|
function InitRemoteOSSettings {
|
||||||
|
|
||||||
#TODO: fix add -E when both initiator and targets don't run MacOSX and PRESERVE_EXECUTABILITY=yes
|
|
||||||
## MacOSX does not use the -E parameter like Linux or BSD does (-E is mapped to extended attrs instead of preserve executability)
|
## MacOSX does not use the -E parameter like Linux or BSD does (-E is mapped to extended attrs instead of preserve executability)
|
||||||
if [ "$PRESERVE_EXECUTABILITY" != "no" ];then
|
if [ "$PRESERVE_EXECUTABILITY" != "no" ];then
|
||||||
if [ "$LOCAL_OS" != "MacOSX" ] && [ "$REMOTE_OS" != "MacOSX" ]; then
|
if [ "$LOCAL_OS" != "MacOSX" ] && [ "$REMOTE_OS" != "MacOSX" ]; then
|
||||||
@ -1283,20 +1296,20 @@ function TrapQuit {
|
|||||||
local exitcode
|
local exitcode
|
||||||
|
|
||||||
if [ $ERROR_ALERT -ne 0 ]; then
|
if [ $ERROR_ALERT -ne 0 ]; then
|
||||||
SendAlert
|
|
||||||
if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then
|
if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then
|
||||||
RunAfterHook
|
RunAfterHook
|
||||||
fi
|
fi
|
||||||
CleanUp
|
CleanUp
|
||||||
Logger "Backup script finished with errors." "ERROR"
|
Logger "Backup script finished with errors." "ERROR"
|
||||||
|
SendAlert
|
||||||
exitcode=1
|
exitcode=1
|
||||||
elif [ $WARN_ALERT -ne 0 ]; then
|
elif [ $WARN_ALERT -ne 0 ]; then
|
||||||
SendAlert
|
|
||||||
if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then
|
if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then
|
||||||
RunAfterHook
|
RunAfterHook
|
||||||
fi
|
fi
|
||||||
CleanUp
|
CleanUp
|
||||||
Logger "Backup script finished with warnings." "WARN"
|
Logger "Backup script finished with warnings." "WARN"
|
||||||
|
SendAlert
|
||||||
exitcode=2
|
exitcode=2
|
||||||
else
|
else
|
||||||
RunAfterHook
|
RunAfterHook
|
||||||
@ -1335,8 +1348,8 @@ function CheckEnvironment {
|
|||||||
|
|
||||||
if [ "$FILE_BACKUP" != "no" ]; then
|
if [ "$FILE_BACKUP" != "no" ]; then
|
||||||
if [ "$ENCRYPTION" == "yes" ]; then
|
if [ "$ENCRYPTION" == "yes" ]; then
|
||||||
if ! type duplicity > /dev/null 2>&1 ; then
|
if ! type gpg > /dev/null 2>&1 ; then
|
||||||
Logger "duplicity not present. Cannot backup encrypted files." "CRITICAL"
|
Logger "gpg not present. Cannot encrypt backup files." "CRITICAL"
|
||||||
CAN_BACKUP_FILES=0
|
CAN_BACKUP_FILES=0
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@ -1382,6 +1395,15 @@ function CheckCurrentConfig {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
#TODO-v2.1: Add runtime variable tests (RSYNC_ARGS etc)
|
#TODO-v2.1: Add runtime variable tests (RSYNC_ARGS etc)
|
||||||
|
if [ "$REMOTE_OPERATION" == "yes" ] && [ ! -f "$SSH_RSA_PRIVATE_KEY" ]; then
|
||||||
|
Logger "Cannot find rsa private key [$SSH_RSA_PRIVATE_KEY]. Cannot connect to remote system." "CRITICAL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "$ENCRYPT_GPG_PYUBKEY" ]; then
|
||||||
|
Logger "Cannot find gpg pubkey [$ENCRPYT_GPG_PUBKEY]. Cannot encrypt backup files." "CRITICAL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function CheckRunningInstances {
|
function CheckRunningInstances {
|
||||||
@ -2038,17 +2060,31 @@ function BackupDatabases {
|
|||||||
for database in $SQL_BACKUP_TASKS
|
for database in $SQL_BACKUP_TASKS
|
||||||
do
|
do
|
||||||
Logger "Backing up database [$database]." "NOTICE"
|
Logger "Backing up database [$database]." "NOTICE"
|
||||||
BackupDatabase $database &
|
BackupDatabase $database
|
||||||
WaitForTaskCompletion $! $SOFT_MAX_EXEC_TIME_DB_TASK $HARD_MAX_EXEC_TIME_DB_TASK ${FUNCNAME[0]} true $KEEP_LOGGING
|
|
||||||
CheckTotalExecutionTime
|
CheckTotalExecutionTime
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function EncryptFiles {
|
function PrepareEncryptFiles {
|
||||||
|
local tmpPath="${2}"
|
||||||
|
|
||||||
|
|
||||||
|
if [ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]; then
|
||||||
|
_CreateDirsLocal "$tmpPath"
|
||||||
|
elif [ "$BACKUP_TYPE" == "pull" ]; then
|
||||||
|
Logger "Encryption only works with [local] or [push] backup types." "CRITICAL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
#WIP: check disk space in tmp dir and compare to backup size else error
|
||||||
|
}
|
||||||
|
|
||||||
|
function EncrpytFiles {
|
||||||
local filePath="${1}" # Path of files to encrypt
|
local filePath="${1}" # Path of files to encrypt
|
||||||
local tmpPath="${2}"
|
local tmpPath="${2}"
|
||||||
|
|
||||||
|
|
||||||
|
#WIP: template code to split into local & remote code
|
||||||
|
|
||||||
#crypt_cmd source temp
|
#crypt_cmd source temp
|
||||||
# Send files to remote, rotate & copy
|
# Send files to remote, rotate & copy
|
||||||
}
|
}
|
||||||
@ -2191,7 +2227,7 @@ function CheckTotalExecutionTime {
|
|||||||
if [ $SECONDS -gt $SOFT_MAX_EXEC_TIME_TOTAL ]; then
|
if [ $SECONDS -gt $SOFT_MAX_EXEC_TIME_TOTAL ]; then
|
||||||
Logger "Max soft execution time of the whole backup exceeded." "ERROR"
|
Logger "Max soft execution time of the whole backup exceeded." "ERROR"
|
||||||
WARN_ALERT=1
|
WARN_ALERT=1
|
||||||
SendAlert
|
SendAlert true
|
||||||
if [ $SECONDS -gt $HARD_MAX_EXEC_TIME_TOTAL ] && [ $HARD_MAX_EXEC_TIME_TOTAL -ne 0 ]; then
|
if [ $SECONDS -gt $HARD_MAX_EXEC_TIME_TOTAL ] && [ $HARD_MAX_EXEC_TIME_TOTAL -ne 0 ]; then
|
||||||
Logger "Max hard execution time of the whole backup exceeded, stopping backup process." "CRITICAL"
|
Logger "Max hard execution time of the whole backup exceeded, stopping backup process." "CRITICAL"
|
||||||
exit 1
|
exit 1
|
||||||
|
Loading…
Reference in New Issue
Block a user