mirror of
https://github.com/deajan/obackup.git
synced 2024-11-15 04:03:41 +01:00
Rebuilt targets
This commit is contained in:
parent
42684fbdf8
commit
233ec565e3
File diff suppressed because it is too large
Load Diff
120
install.sh
120
install.sh
@ -10,7 +10,7 @@ PROGRAM_BINARY=$PROGRAM".sh"
|
||||
PROGRAM_BATCH=$PROGRAM"-batch.sh"
|
||||
SSH_FILTER="ssh_filter.sh"
|
||||
|
||||
SCRIPT_BUILD=2018100206
|
||||
SCRIPT_BUILD=2019022601
|
||||
INSTANCE_ID="installer-$SCRIPT_BUILD"
|
||||
|
||||
## osync / obackup / pmocr / zsnap install script
|
||||
@ -18,7 +18,7 @@ INSTANCE_ID="installer-$SCRIPT_BUILD"
|
||||
## Please adapt this to fit your distro needs
|
||||
|
||||
_OFUNCTIONS_VERSION=2.3.0-RC2
|
||||
_OFUNCTIONS_BUILD=2018122103
|
||||
_OFUNCTIONS_BUILD=2019012801
|
||||
_OFUNCTIONS_BOOTSTRAP=true
|
||||
|
||||
if ! type "$BASH" > /dev/null; then
|
||||
@ -50,9 +50,9 @@ ERROR_ALERT=false
|
||||
WARN_ALERT=false
|
||||
|
||||
|
||||
## allow debugging from command line with _DEBUG=yes
|
||||
if [ ! "$_DEBUG" == "yes" ]; then
|
||||
_DEBUG=no
|
||||
## allow debugging from command line with _DEBUG=true
|
||||
if [ ! "$_DEBUG" == true ]; then
|
||||
_DEBUG=false
|
||||
_LOGGER_VERBOSE=false
|
||||
else
|
||||
trap 'TrapError ${LINENO} $?' ERR
|
||||
@ -83,7 +83,6 @@ else
|
||||
LOG_FILE="/tmp/$PROGRAM.log"
|
||||
fi
|
||||
|
||||
#### RUN_DIR SUBSET ####
|
||||
## Default directory where to store temporary run files
|
||||
|
||||
if [ -w /tmp ]; then
|
||||
@ -99,7 +98,6 @@ if [ "$_REMOTE_EXECUTION" == true ]; then
|
||||
mkdir -p "$RUN_DIR/$PROGRAM.remote"
|
||||
RUN_DIR="$RUN_DIR/$PROGRAM.remote"
|
||||
fi
|
||||
#### RUN_DIR SUBSET END ####
|
||||
|
||||
# Get a random number on Windows BusyBox alike, also works on most Unixes that have dd, if dd is not found, then return $RANDOM
|
||||
function PoorMansRandomGenerator {
|
||||
@ -201,19 +199,19 @@ function RemoteLogger {
|
||||
|
||||
if [ "$level" == "CRITICAL" ]; then
|
||||
_Logger "" "$prefix\e[1;33;41m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
elif [ "$level" == "ERROR" ]; then
|
||||
_Logger "" "$prefix\e[31m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
elif [ "$level" == "WARN" ]; then
|
||||
_Logger "" "$prefix\e[33m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
@ -231,7 +229,7 @@ function RemoteLogger {
|
||||
_Logger "" "$prefix$value"
|
||||
return
|
||||
elif [ "$level" == "DEBUG" ]; then
|
||||
if [ "$_DEBUG" == "yes" ]; then
|
||||
if [ "$_DEBUG" == true ]; then
|
||||
_Logger "" "$prefix$value"
|
||||
return
|
||||
fi
|
||||
@ -253,10 +251,9 @@ function RemoteLogger {
|
||||
|
||||
# CRITICAL, ERROR, WARN sent to stderr, color depending on level, level also logged
|
||||
# NOTICE sent to stdout
|
||||
# VERBOSE sent to stdout if _LOGGER_VERBOSE = true
|
||||
# ALWAYS is sent to stdout unless _LOGGER_SILENT = true
|
||||
# DEBUG & PARANOIA_DEBUG are only sent to stdout if _DEBUG=yes
|
||||
# SIMPLE is a wrapper for QuickLogger that does not use advanced functionality
|
||||
# VERBOSE sent to stdout if _LOGGER_VERBOSE=true
|
||||
# ALWAYS is sent to stdout unless _LOGGER_SILENT=true
|
||||
# DEBUG & PARANOIA_DEBUG are only sent to stdout if _DEBUG=true
|
||||
function Logger {
|
||||
local value="${1}" # Sentence to log (in double quotes)
|
||||
local level="${2}" # Log level
|
||||
@ -306,17 +303,10 @@ function Logger {
|
||||
_Logger "$prefix$value" "$prefix$value"
|
||||
return
|
||||
elif [ "$level" == "DEBUG" ]; then
|
||||
if [ "$_DEBUG" == "yes" ]; then
|
||||
if [ "$_DEBUG" == true ]; then
|
||||
_Logger "$prefix$value" "$prefix$value"
|
||||
return
|
||||
fi
|
||||
elif [ "$level" == "SIMPLE" ]; then
|
||||
if [ "$_LOGGER_SILENT" == true ]; then
|
||||
_Logger "$preix$value"
|
||||
else
|
||||
_Logger "$preix$value" "$prefix$value"
|
||||
fi
|
||||
return
|
||||
else
|
||||
_Logger "\e[41mLogger function called without proper loglevel [$level].\e[0m" "\e[41mLogger function called without proper loglevel [$level].\e[0m" true
|
||||
_Logger "Value was: $prefix$value" "Value was: $prefix$value" true
|
||||
@ -409,7 +399,7 @@ function KillAllChilds {
|
||||
}
|
||||
|
||||
function CleanUp {
|
||||
if [ "$_DEBUG" != "yes" ]; then
|
||||
if [ "$_DEBUG" != true ]; then
|
||||
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP"
|
||||
# Fix for sed -i requiring backup extension for BSD & Mac (see all sed -i statements)
|
||||
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP.tmp"
|
||||
@ -462,7 +452,7 @@ function GetCommandlineArguments {
|
||||
Usage
|
||||
;;
|
||||
*)
|
||||
Logger "Unknown option '$i'" "SIMPLE"
|
||||
Logger "Unknown option '$i'" "ERROR"
|
||||
Usage
|
||||
exit
|
||||
;;
|
||||
@ -573,7 +563,7 @@ function GetLocalOS {
|
||||
LOCAL_OS="BusyBox"
|
||||
;;
|
||||
*)
|
||||
if [ "$IGNORE_OS_TYPE" == "yes" ]; then
|
||||
if [ "$IGNORE_OS_TYPE" == true ]; then
|
||||
Logger "Running on unknown local OS [$localOsVar]." "WARN"
|
||||
return
|
||||
fi
|
||||
@ -668,12 +658,12 @@ function SetLocalOSSettings {
|
||||
esac
|
||||
|
||||
if [ "$LOCAL_OS" == "Android" ] || [ "$LOCAL_OS" == "BusyBox" ]; then
|
||||
Logger "Cannot be installed on [$LOCAL_OS]. Please use $PROGRAM.sh directly." "SIMPLE"
|
||||
Logger "Cannot be installed on [$LOCAL_OS]. Please use $PROGRAM.sh directly." "CRITICAL"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ([ "$USER" != "" ] && [ "$(whoami)" != "$USER" ] && [ "$FAKEROOT" == "" ]); then
|
||||
Logger "Must be run as $USER." "SIMPLE"
|
||||
Logger "Must be run as $USER." "CRITICAL"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -683,17 +673,17 @@ function SetLocalOSSettings {
|
||||
function GetInit {
|
||||
if [ -f /sbin/openrc-run ]; then
|
||||
init="openrc"
|
||||
Logger "Detected openrc." "SIMPLE"
|
||||
Logger "Detected openrc." "NOTICE"
|
||||
elif [ -f /sbin/init ]; then
|
||||
if file /sbin/init | grep systemd > /dev/null; then
|
||||
init="systemd"
|
||||
Logger "Detected systemd." "SIMPLE"
|
||||
Logger "Detected systemd." "NOTICE"
|
||||
else
|
||||
init="initV"
|
||||
Logger "Detected initV." "SIMPLE"
|
||||
Logger "Detected initV." "NOTICE"
|
||||
fi
|
||||
else
|
||||
Logger "Can't detect initV, systemd or openRC. Service files won't be installed. You can still run $PROGRAM manually or via cron." "SIMPLE"
|
||||
Logger "Can't detect initV, systemd or openRC. Service files won't be installed. You can still run $PROGRAM manually or via cron." "WARN"
|
||||
init="none"
|
||||
fi
|
||||
}
|
||||
@ -712,9 +702,9 @@ function CreateDir {
|
||||
mkdir -p "$dir"
|
||||
)
|
||||
if [ $? == 0 ]; then
|
||||
Logger "Created directory [$dir]." "SIMPLE"
|
||||
Logger "Created directory [$dir]." "NOTICE"
|
||||
else
|
||||
Logger "Cannot create directory [$dir]." "SIMPLE"
|
||||
Logger "Cannot create directory [$dir]." "CRITICAL"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
@ -726,10 +716,10 @@ function CreateDir {
|
||||
fi
|
||||
chown "$userGroup" "$dir"
|
||||
if [ $? != 0 ]; then
|
||||
Logger "Could not set directory ownership on [$dir] to [$userGroup]." "SIMPLE"
|
||||
Logger "Could not set directory ownership on [$dir] to [$userGroup]." "CRITICAL"
|
||||
exit 1
|
||||
else
|
||||
Logger "Set file ownership on [$dir] to [$userGroup]." "SIMPLE"
|
||||
Logger "Set file ownership on [$dir] to [$userGroup]." "NOTICE"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@ -753,26 +743,26 @@ function CopyFile {
|
||||
|
||||
if [ -f "$destPath/$destFileName" ] && [ $overwrite == false ]; then
|
||||
destfileName="$sourceFileName.new"
|
||||
Logger "Copying [$sourceFileName] to [$destPath/$destFilename]." "SIMPLE"
|
||||
Logger "Copying [$sourceFileName] to [$destPath/$destFilename]." "NOTICE"
|
||||
fi
|
||||
|
||||
cp "$sourcePath/$sourceFileName" "$destPath/$destFileName"
|
||||
if [ $? != 0 ]; then
|
||||
Logger "Cannot copy [$sourcePath/$sourceFileName] to [$destPath/$destFileName]. Make sure to run install script in the directory containing all other files." "SIMPLE"
|
||||
Logger "Also make sure you have permissions to write to [$BIN_DIR]." "SIMPLE"
|
||||
Logger "Cannot copy [$sourcePath/$sourceFileName] to [$destPath/$destFileName]. Make sure to run install script in the directory containing all other files." "CRITICAL"
|
||||
Logger "Also make sure you have permissions to write to [$BIN_DIR]." "ERROR"
|
||||
exit 1
|
||||
else
|
||||
Logger "Copied [$sourcePath/$sourceFileName] to [$destPath/$destFileName]." "SIMPLE"
|
||||
Logger "Copied [$sourcePath/$sourceFileName] to [$destPath/$destFileName]." "NOTICE"
|
||||
if [ "$(IsInteger $fileMod)" -eq 1 ]; then
|
||||
chmod "$fileMod" "$destPath/$destFileName"
|
||||
if [ $? != 0 ]; then
|
||||
Logger "Cannot set file permissions of [$destPath/$destFileName] to [$fileMod]." "SIMPLE"
|
||||
Logger "Cannot set file permissions of [$destPath/$destFileName] to [$fileMod]." "CRITICAL"
|
||||
exit 1
|
||||
else
|
||||
Logger "Set file permissions to [$fileMod] on [$destPath/$destFileName]." "SIMPLE"
|
||||
Logger "Set file permissions to [$fileMod] on [$destPath/$destFileName]." "NOTICE"
|
||||
fi
|
||||
elif [ "$fileMod" != "" ]; then
|
||||
Logger "Bogus filemod [$fileMod] for [$destPath] given." "SIMPLE"
|
||||
Logger "Bogus filemod [$fileMod] for [$destPath] given." "WARN"
|
||||
fi
|
||||
|
||||
if [ "$fileUser" != "" ]; then
|
||||
@ -784,10 +774,10 @@ function CopyFile {
|
||||
|
||||
chown "$userGroup" "$destPath/$destFileName"
|
||||
if [ $? != 0 ]; then
|
||||
Logger "Could not set file ownership on [$destPath/$destFileName] to [$userGroup]." "SIMPLE"
|
||||
Logger "Could not set file ownership on [$destPath/$destFileName] to [$userGroup]." "CRITICAL"
|
||||
exit 1
|
||||
else
|
||||
Logger "Set file ownership on [$destPath/$destFileName] to [$userGroup]." "SIMPLE"
|
||||
Logger "Set file ownership on [$destPath/$destFileName] to [$userGroup]." "NOTICE"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@ -839,25 +829,25 @@ function CopyServiceFiles {
|
||||
CreateDir "$SERVICE_DIR_SYSTEMD_USER"
|
||||
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_SYSTEMD_USER" "$SERVICE_FILE_SYSTEMD_USER" "$SERVICE_FILE_SYSTEMD_USER" "" "" "" true
|
||||
fi
|
||||
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_SYSTEMD_SYSTEM] and [$SERVICE_DIR_SYSTEMD_USER]." "SIMPLE"
|
||||
Logger "Can be activated with [systemctl start SERVICE_NAME@instance.conf] where instance.conf is the name of the config file in $CONF_DIR." "SIMPLE"
|
||||
Logger "Can be enabled on boot with [systemctl enable $SERVICE_NAME@instance.conf]." "SIMPLE"
|
||||
Logger "In userland, active with [systemctl --user start $SERVICE_NAME@instance.conf]." "SIMPLE"
|
||||
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_SYSTEMD_SYSTEM] and [$SERVICE_DIR_SYSTEMD_USER]." "NOTICE"
|
||||
Logger "Can be activated with [systemctl start SERVICE_NAME@instance.conf] where instance.conf is the name of the config file in $CONF_DIR." "NOTICE"
|
||||
Logger "Can be enabled on boot with [systemctl enable $SERVICE_NAME@instance.conf]." "NOTICE"
|
||||
Logger "In userland, active with [systemctl --user start $SERVICE_NAME@instance.conf]." "NOTICE"
|
||||
elif ([ "$init" == "initV" ] && [ -f "$SCRIPT_PATH/$SERVICE_FILE_INIT" ] && [ -d "$SERVICE_DIR_INIT" ]); then
|
||||
#CreateDir "$SERVICE_DIR_INIT"
|
||||
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_INIT" "$SERVICE_FILE_INIT" "$SERVICE_FILE_INIT" "755" "" "" true
|
||||
|
||||
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_INIT]." "SIMPLE"
|
||||
Logger "Can be activated with [service $SERVICE_FILE_INIT start]." "SIMPLE"
|
||||
Logger "Can be enabled on boot with [chkconfig $SERVICE_FILE_INIT on]." "SIMPLE"
|
||||
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_INIT]." "NOTICE"
|
||||
Logger "Can be activated with [service $SERVICE_FILE_INIT start]." "NOTICE"
|
||||
Logger "Can be enabled on boot with [chkconfig $SERVICE_FILE_INIT on]." "NOTICE"
|
||||
elif ([ "$init" == "openrc" ] && [ -f "$SCRIPT_PATH/$SERVICE_FILE_OPENRC" ] && [ -d "$SERVICE_DIR_OPENRC" ]); then
|
||||
# Rename service to usual service file
|
||||
CopyFile "$SCRIPT_PATH" "$SERVICE_DIR_OPENRC" "$SERVICE_FILE_OPENRC" "$SERVICE_FILE_INIT" "755" "" "" true
|
||||
|
||||
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_OPENRC]." "SIMPLE"
|
||||
Logger "Can be activated with [rc-update add $SERVICE_NAME.instance] where instance is a configuration file found in /etc/osync." "SIMPLE"
|
||||
Logger "Created [$SERVICE_NAME] service in [$SERVICE_DIR_OPENRC]." "NOTICE"
|
||||
Logger "Can be activated with [rc-update add $SERVICE_NAME.instance] where instance is a configuration file found in /etc/osync." "NOTICE"
|
||||
else
|
||||
Logger "Cannot properly find how to deal with init on this system. Skipping service file installation." "SIMPLE"
|
||||
Logger "Cannot properly find how to deal with init on this system. Skipping service file installation." "NOTICE"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -876,7 +866,7 @@ function Statistics {
|
||||
fi
|
||||
fi
|
||||
|
||||
Logger "Neiter wget nor curl could be used for. Cannot run statistics. Use the provided link please." "SIMPLE"
|
||||
Logger "Neiter wget nor curl could be used for. Cannot run statistics. Use the provided link please." "WARN"
|
||||
return 1
|
||||
}
|
||||
|
||||
@ -886,12 +876,12 @@ function RemoveFile {
|
||||
if [ -f "$file" ]; then
|
||||
rm -f "$file"
|
||||
if [ $? != 0 ]; then
|
||||
Logger "Could not remove file [$file]." "SIMPLE"
|
||||
Logger "Could not remove file [$file]." "ERROR"
|
||||
else
|
||||
Logger "Removed file [$file]." "SIMPLE"
|
||||
Logger "Removed file [$file]." "NOTICE"
|
||||
fi
|
||||
else
|
||||
Logger "File [$file] not found. Skipping." "SIMPLE"
|
||||
Logger "File [$file] not found. Skipping." "NOTICE"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -905,13 +895,13 @@ function RemoveAll {
|
||||
if [ ! -f "$BIN_DIR/osync.sh" ] && [ ! -f "$BIN_DIR/obackup.sh" ]; then # Check if any other program requiring ssh filter is present before removal
|
||||
RemoveFile "$BIN_DIR/$SSH_FILTER"
|
||||
else
|
||||
Logger "Skipping removal of [$BIN_DIR/$SSH_FILTER] because other programs present that need it." "SIMPLE"
|
||||
Logger "Skipping removal of [$BIN_DIR/$SSH_FILTER] because other programs present that need it." "NOTICE"
|
||||
fi
|
||||
RemoveFile "$SERVICE_DIR_SYSTEMD_SYSTEM/$SERVICE_FILE_SYSTEMD_SYSTEM"
|
||||
RemoveFile "$SERVICE_DIR_SYSTEMD_USER/$SERVICE_FILE_SYSTEMD_USER"
|
||||
RemoveFile "$SERVICE_DIR_INIT/$SERVICE_FILE_INIT"
|
||||
|
||||
Logger "Skipping configuration files in [$CONF_DIR]. You may remove this directory manually." "SIMPLE"
|
||||
Logger "Skipping configuration files in [$CONF_DIR]. You may remove this directory manually." "NOTICE"
|
||||
}
|
||||
|
||||
function Usage {
|
||||
@ -962,7 +952,7 @@ STATS_LINK="http://instcount.netpower.fr?program=$PROGRAM&version=$PROGRAM_VERSI
|
||||
|
||||
if [ "$ACTION" == "uninstall" ]; then
|
||||
RemoveAll
|
||||
Logger "$PROGRAM uninstalled." "SIMPLE"
|
||||
Logger "$PROGRAM uninstalled." "NOTICE"
|
||||
else
|
||||
CreateDir "$CONF_DIR"
|
||||
CreateDir "$BIN_DIR"
|
||||
@ -971,10 +961,10 @@ else
|
||||
if [ "$PROGRAM" == "osync" ] || [ "$PROGRAM" == "pmocr" ]; then
|
||||
CopyServiceFiles
|
||||
fi
|
||||
Logger "$PROGRAM installed. Use with $BIN_DIR/$PROGRAM_BINARY" "SIMPLE"
|
||||
Logger "$PROGRAM installed. Use with $BIN_DIR/$PROGRAM_BINARY" "NOTICE"
|
||||
if [ "$PROGRAM" == "osync" ] || [ "$PROGRAM" == "obackup" ]; then
|
||||
echo ""
|
||||
Logger "If connecting remotely, consider setup ssh filter to enhance security." "SIMPLE"
|
||||
Logger "If connecting remotely, consider setup ssh filter to enhance security." "NOTICE"
|
||||
echo ""
|
||||
fi
|
||||
fi
|
||||
@ -983,7 +973,7 @@ if [ $_STATS -eq 1 ]; then
|
||||
if [ $_LOGGER_SILENT == true ]; then
|
||||
Statistics
|
||||
else
|
||||
Logger "In order to make usage statistics, the script would like to connect to $STATS_LINK" "SIMPLE"
|
||||
Logger "In order to make usage statistics, the script would like to connect to $STATS_LINK" "NOTICE"
|
||||
read -r -p "No data except those in the url will be send. Allow [Y/n] " response
|
||||
case $response in
|
||||
[nN])
|
||||
|
@ -91,19 +91,19 @@ function RemoteLogger {
|
||||
|
||||
if [ "$level" == "CRITICAL" ]; then
|
||||
_Logger "" "$prefix\e[1;33;41m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
elif [ "$level" == "ERROR" ]; then
|
||||
_Logger "" "$prefix\e[31m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
elif [ "$level" == "WARN" ]; then
|
||||
_Logger "" "$prefix\e[33m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
@ -121,7 +121,7 @@ function RemoteLogger {
|
||||
_Logger "" "$prefix$value"
|
||||
return
|
||||
elif [ "$level" == "DEBUG" ]; then
|
||||
if [ "$_DEBUG" == "yes" ]; then
|
||||
if [ "$_DEBUG" == true ]; then
|
||||
_Logger "" "$prefix$value"
|
||||
return
|
||||
fi
|
||||
@ -144,10 +144,9 @@ function RemoteLogger {
|
||||
|
||||
# CRITICAL, ERROR, WARN sent to stderr, color depending on level, level also logged
|
||||
# NOTICE sent to stdout
|
||||
# VERBOSE sent to stdout if _LOGGER_VERBOSE = true
|
||||
# ALWAYS is sent to stdout unless _LOGGER_SILENT = true
|
||||
# DEBUG & PARANOIA_DEBUG are only sent to stdout if _DEBUG=yes
|
||||
# SIMPLE is a wrapper for QuickLogger that does not use advanced functionality
|
||||
# VERBOSE sent to stdout if _LOGGER_VERBOSE=true
|
||||
# ALWAYS is sent to stdout unless _LOGGER_SILENT=true
|
||||
# DEBUG & PARANOIA_DEBUG are only sent to stdout if _DEBUG=true
|
||||
function Logger {
|
||||
local value="${1}" # Sentence to log (in double quotes)
|
||||
local level="${2}" # Log level
|
||||
@ -197,17 +196,10 @@ function Logger {
|
||||
_Logger "$prefix$value" "$prefix$value"
|
||||
return
|
||||
elif [ "$level" == "DEBUG" ]; then
|
||||
if [ "$_DEBUG" == "yes" ]; then
|
||||
if [ "$_DEBUG" == true ]; then
|
||||
_Logger "$prefix$value" "$prefix$value"
|
||||
return
|
||||
fi
|
||||
elif [ "$level" == "SIMPLE" ]; then
|
||||
if [ "$_LOGGER_SILENT" == true ]; then
|
||||
_Logger "$preix$value"
|
||||
else
|
||||
_Logger "$preix$value" "$prefix$value"
|
||||
fi
|
||||
return
|
||||
else
|
||||
_Logger "\e[41mLogger function called without proper loglevel [$level].\e[0m" "\e[41mLogger function called without proper loglevel [$level].\e[0m" true
|
||||
_Logger "Value was: $prefix$value" "Value was: $prefix$value" true
|
||||
|
314
obackup.sh
314
obackup.sh
@ -8,11 +8,11 @@ AUTHOR="(C) 2013-2019 by Orsiris de Jong"
|
||||
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
|
||||
PROGRAM_VERSION=2.1-RC1
|
||||
PROGRAM_BUILD=2018110602
|
||||
IS_STABLE=yes
|
||||
IS_STABLE=true
|
||||
|
||||
|
||||
_OFUNCTIONS_VERSION=2.3.0-RC2
|
||||
_OFUNCTIONS_BUILD=2018122103
|
||||
_OFUNCTIONS_BUILD=2019012801
|
||||
_OFUNCTIONS_BOOTSTRAP=true
|
||||
|
||||
if ! type "$BASH" > /dev/null; then
|
||||
@ -44,9 +44,9 @@ ERROR_ALERT=false
|
||||
WARN_ALERT=false
|
||||
|
||||
|
||||
## allow debugging from command line with _DEBUG=yes
|
||||
if [ ! "$_DEBUG" == "yes" ]; then
|
||||
_DEBUG=no
|
||||
## allow debugging from command line with _DEBUG=true
|
||||
if [ ! "$_DEBUG" == true ]; then
|
||||
_DEBUG=false
|
||||
_LOGGER_VERBOSE=false
|
||||
else
|
||||
trap 'TrapError ${LINENO} $?' ERR
|
||||
@ -77,7 +77,6 @@ else
|
||||
LOG_FILE="/tmp/$PROGRAM.log"
|
||||
fi
|
||||
|
||||
#### RUN_DIR SUBSET ####
|
||||
## Default directory where to store temporary run files
|
||||
|
||||
if [ -w /tmp ]; then
|
||||
@ -93,7 +92,6 @@ if [ "$_REMOTE_EXECUTION" == true ]; then
|
||||
mkdir -p "$RUN_DIR/$PROGRAM.remote"
|
||||
RUN_DIR="$RUN_DIR/$PROGRAM.remote"
|
||||
fi
|
||||
#### RUN_DIR SUBSET END ####
|
||||
|
||||
# Get a random number on Windows BusyBox alike, also works on most Unixes that have dd, if dd is not found, then return $RANDOM
|
||||
function PoorMansRandomGenerator {
|
||||
@ -195,19 +193,19 @@ function RemoteLogger {
|
||||
|
||||
if [ "$level" == "CRITICAL" ]; then
|
||||
_Logger "" "$prefix\e[1;33;41m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
elif [ "$level" == "ERROR" ]; then
|
||||
_Logger "" "$prefix\e[31m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
elif [ "$level" == "WARN" ]; then
|
||||
_Logger "" "$prefix\e[33m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
@ -225,7 +223,7 @@ function RemoteLogger {
|
||||
_Logger "" "$prefix$value"
|
||||
return
|
||||
elif [ "$level" == "DEBUG" ]; then
|
||||
if [ "$_DEBUG" == "yes" ]; then
|
||||
if [ "$_DEBUG" == true ]; then
|
||||
_Logger "" "$prefix$value"
|
||||
return
|
||||
fi
|
||||
@ -247,10 +245,9 @@ function RemoteLogger {
|
||||
|
||||
# CRITICAL, ERROR, WARN sent to stderr, color depending on level, level also logged
|
||||
# NOTICE sent to stdout
|
||||
# VERBOSE sent to stdout if _LOGGER_VERBOSE = true
|
||||
# ALWAYS is sent to stdout unless _LOGGER_SILENT = true
|
||||
# DEBUG & PARANOIA_DEBUG are only sent to stdout if _DEBUG=yes
|
||||
# SIMPLE is a wrapper for QuickLogger that does not use advanced functionality
|
||||
# VERBOSE sent to stdout if _LOGGER_VERBOSE=true
|
||||
# ALWAYS is sent to stdout unless _LOGGER_SILENT=true
|
||||
# DEBUG & PARANOIA_DEBUG are only sent to stdout if _DEBUG=true
|
||||
function Logger {
|
||||
local value="${1}" # Sentence to log (in double quotes)
|
||||
local level="${2}" # Log level
|
||||
@ -300,17 +297,10 @@ function Logger {
|
||||
_Logger "$prefix$value" "$prefix$value"
|
||||
return
|
||||
elif [ "$level" == "DEBUG" ]; then
|
||||
if [ "$_DEBUG" == "yes" ]; then
|
||||
if [ "$_DEBUG" == true ]; then
|
||||
_Logger "$prefix$value" "$prefix$value"
|
||||
return
|
||||
fi
|
||||
elif [ "$level" == "SIMPLE" ]; then
|
||||
if [ "$_LOGGER_SILENT" == true ]; then
|
||||
_Logger "$preix$value"
|
||||
else
|
||||
_Logger "$preix$value" "$prefix$value"
|
||||
fi
|
||||
return
|
||||
else
|
||||
_Logger "\e[41mLogger function called without proper loglevel [$level].\e[0m" "\e[41mLogger function called without proper loglevel [$level].\e[0m" true
|
||||
_Logger "Value was: $prefix$value" "Value was: $prefix$value" true
|
||||
@ -403,7 +393,7 @@ function KillAllChilds {
|
||||
}
|
||||
|
||||
function CleanUp {
|
||||
if [ "$_DEBUG" != "yes" ]; then
|
||||
if [ "$_DEBUG" != true ]; then
|
||||
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP"
|
||||
# Fix for sed -i requiring backup extension for BSD & Mac (see all sed -i statements)
|
||||
rm -f "$RUN_DIR/$PROGRAM."*".$SCRIPT_PID.$TSTAMP.tmp"
|
||||
@ -443,7 +433,7 @@ function SendAlert {
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ "$_DEBUG" == "yes" ]; then
|
||||
if [ "$_DEBUG" == true ]; then
|
||||
Logger "Debug mode, no warning mail will be sent." "NOTICE"
|
||||
return 0
|
||||
fi
|
||||
@ -521,8 +511,9 @@ function SendEmail {
|
||||
|
||||
local i
|
||||
|
||||
if [ "${destinationMails[@]}" != "" ]; then
|
||||
for i in "${destinationMails[@]}"; do
|
||||
if [ "${destinationMails}" != "" ]; then
|
||||
# Not quoted since we split at space character, and emails cannot contain spaces
|
||||
for i in ${destinationMails}; do
|
||||
if [ $(CheckRFC822 "$i") -ne 1 ]; then
|
||||
Logger "Given email [$i] does not seem to be valid." "WARN"
|
||||
fi
|
||||
@ -701,7 +692,7 @@ function LoadConfigFile {
|
||||
else
|
||||
revisionPresent=$(GetConfFileValue "$configFile" "CONFIG_FILE_REVISION" true)
|
||||
if [ "$(IsNumeric $revisionPresent)" -eq 0 ]; then
|
||||
revisionPresent=0
|
||||
Logger "CONFIG_FILE_REVISION does not seem numeric [$revisionPresent]." "DEBUG"
|
||||
fi
|
||||
if [ "$revisionRequired" != "" ]; then
|
||||
if [ $(VerComp "$revisionPresent" "$revisionRequired") -eq 2 ]; then
|
||||
@ -825,7 +816,7 @@ function ExecTasks {
|
||||
|
||||
|
||||
# Since ExecTasks takes up to 17 arguments, do a quick preflight check in DEBUG mode
|
||||
if [ "$_DEBUG" == "yes" ]; then
|
||||
if [ "$_DEBUG" == true ]; then
|
||||
declare -a booleans=(readFromFile counting spinner noTimeErrorLog noErrorLogsAtAll)
|
||||
for i in "${booleans[@]}"; do
|
||||
test="if [ \$$i != false ] && [ \$$i != true ]; then Logger \"Bogus $i value [\$$i] given to ${FUNCNAME[0]}.\" \"CRITICAL\"; exit 1; fi"
|
||||
@ -1420,7 +1411,7 @@ function GetLocalOS {
|
||||
LOCAL_OS="BusyBox"
|
||||
;;
|
||||
*)
|
||||
if [ "$IGNORE_OS_TYPE" == "yes" ]; then
|
||||
if [ "$IGNORE_OS_TYPE" == true ]; then
|
||||
Logger "Running on unknown local OS [$localOsVar]." "WARN"
|
||||
return
|
||||
fi
|
||||
@ -1477,7 +1468,7 @@ function GetLocalOS {
|
||||
|
||||
function GetRemoteOS {
|
||||
|
||||
if [ "$REMOTE_OPERATION" != "yes" ]; then
|
||||
if [ "$REMOTE_OPERATION" != true ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
@ -1594,7 +1585,7 @@ ENDSSH
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
if [ "$IGNORE_OS_TYPE" == "yes" ]; then #DOC: Undocumented debug only setting
|
||||
if [ "$IGNORE_OS_TYPE" == true ]; then #DOC: Undocumented debug only setting
|
||||
Logger "Running on unknown remote OS [$remoteOsVar]." "WARN"
|
||||
return
|
||||
fi
|
||||
@ -1633,7 +1624,7 @@ function RunLocalCommand {
|
||||
Logger "Command output:\n$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP)" "NOTICE"
|
||||
fi
|
||||
|
||||
if [ "$STOP_ON_CMD_ERROR" == "yes" ] && [ $retval -ne 0 ]; then
|
||||
if [ "$STOP_ON_CMD_ERROR" == true ] && [ $retval -ne 0 ]; then
|
||||
Logger "Stopping on command execution error." "CRITICAL"
|
||||
exit 1
|
||||
fi
|
||||
@ -1645,7 +1636,7 @@ function RunRemoteCommand {
|
||||
local hardMaxTime="${2}" # Max time to wait for command to compleet
|
||||
|
||||
|
||||
if [ "$REMOTE_OPERATION" != "yes" ]; then
|
||||
if [ "$REMOTE_OPERATION" != true ]; then
|
||||
Logger "Ignoring remote command [$command] because remote host is not configured." "WARN"
|
||||
return 0
|
||||
fi
|
||||
@ -1675,7 +1666,7 @@ function RunRemoteCommand {
|
||||
Logger "Command output:\n$(cat $RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP)" "NOTICE"
|
||||
fi
|
||||
|
||||
if [ "$STOP_ON_CMD_ERROR" == "yes" ] && [ $retval -ne 0 ]; then
|
||||
if [ "$STOP_ON_CMD_ERROR" == true ] && [ $retval -ne 0 ]; then
|
||||
Logger "Stopping on command execution error." "CRITICAL"
|
||||
exit 1
|
||||
fi
|
||||
@ -1724,7 +1715,7 @@ function CheckConnectivityRemoteHost {
|
||||
local retval
|
||||
|
||||
|
||||
if [ "$REMOTE_HOST_PING" != "no" ] && [ "$REMOTE_OPERATION" != "no" ]; then
|
||||
if [ "$REMOTE_HOST_PING" != false ] && [ "$REMOTE_OPERATION" != false ]; then
|
||||
eval "$PING_CMD $REMOTE_HOST > /dev/null 2>&1" &
|
||||
ExecTasks $! "${FUNCNAME[0]}" false 0 0 60 180 true $SLEEP_TIME $KEEP_LOGGING
|
||||
#ExecTasks "${FUNCNAME[0]}" 0 0 60 180 $SLEEP_TIME $KEEP_LOGGING true true false false 1 $!
|
||||
@ -1849,14 +1840,14 @@ function PreInit {
|
||||
local compressionString
|
||||
|
||||
## SSH compression
|
||||
if [ "$SSH_COMPRESSION" != "no" ]; then
|
||||
if [ "$SSH_COMPRESSION" != false ]; then
|
||||
SSH_COMP=-C
|
||||
else
|
||||
SSH_COMP=
|
||||
fi
|
||||
|
||||
## Ignore SSH known host verification
|
||||
if [ "$SSH_IGNORE_KNOWN_HOSTS" == "yes" ]; then
|
||||
if [ "$SSH_IGNORE_KNOWN_HOSTS" == true ]; then
|
||||
SSH_OPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
|
||||
fi
|
||||
|
||||
@ -1866,7 +1857,7 @@ function PreInit {
|
||||
fi
|
||||
|
||||
## Sudo execution option
|
||||
if [ "$SUDO_EXEC" == "yes" ]; then
|
||||
if [ "$SUDO_EXEC" == true ]; then
|
||||
if [ "$RSYNC_REMOTE_PATH" != "" ]; then
|
||||
RSYNC_PATH="sudo $RSYNC_REMOTE_PATH/$RSYNC_EXECUTABLE"
|
||||
else
|
||||
@ -2027,19 +2018,19 @@ function InitRemoteOSDependingSettings {
|
||||
fi
|
||||
|
||||
RSYNC_ATTR_ARGS=""
|
||||
if [ "$PRESERVE_PERMISSIONS" != "no" ]; then
|
||||
if [ "$PRESERVE_PERMISSIONS" != false ]; then
|
||||
RSYNC_ATTR_ARGS=$RSYNC_ATTR_ARGS" -p"
|
||||
fi
|
||||
if [ "$PRESERVE_OWNER" != "no" ]; then
|
||||
if [ "$PRESERVE_OWNER" != false ]; then
|
||||
RSYNC_ATTR_ARGS=$RSYNC_ATTR_ARGS" -o"
|
||||
fi
|
||||
if [ "$PRESERVE_GROUP" != "no" ]; then
|
||||
if [ "$PRESERVE_GROUP" != false ]; then
|
||||
RSYNC_ATTR_ARGS=$RSYNC_ATTR_ARGS" -g"
|
||||
fi
|
||||
if [ "$PRESERVE_EXECUTABILITY" != "no" ]; then
|
||||
if [ "$PRESERVE_EXECUTABILITY" != false ]; then
|
||||
RSYNC_ATTR_ARGS=$RSYNC_ATTR_ARGS" --executability"
|
||||
fi
|
||||
if [ "$PRESERVE_ACL" == "yes" ]; then
|
||||
if [ "$PRESERVE_ACL" == true ]; then
|
||||
if [ "$LOCAL_OS" != "MacOSX" ] && [ "$REMOTE_OS" != "MacOSX" ] && [ "$LOCAL_OS" != "msys" ] && [ "$REMOTE_OS" != "msys" ] && [ "$LOCAL_OS" != "Cygwin" ] && [ "$REMOTE_OS" != "Cygwin" ] && [ "$LOCAL_OS" != "BusyBox" ] && [ "$REMOTE_OS" != "BusyBox" ] && [ "$LOCAL_OS" != "Android" ] && [ "$REMOTE_OS" != "Android" ]; then
|
||||
RSYNC_ATTR_ARGS=$RSYNC_ATTR_ARGS" -A"
|
||||
else
|
||||
@ -2047,45 +2038,45 @@ function InitRemoteOSDependingSettings {
|
||||
|
||||
fi
|
||||
fi
|
||||
if [ "$PRESERVE_XATTR" == "yes" ]; then
|
||||
if [ "$PRESERVE_XATTR" == true ]; then
|
||||
if [ "$LOCAL_OS" != "MacOSX" ] && [ "$REMOTE_OS" != "MacOSX" ] && [ "$LOCAL_OS" != "msys" ] && [ "$REMOTE_OS" != "msys" ] && [ "$LOCAL_OS" != "Cygwin" ] && [ "$REMOTE_OS" != "Cygwin" ] && [ "$LOCAL_OS" != "BusyBox" ] && [ "$REMOTE_OS" != "BusyBox" ]; then
|
||||
RSYNC_ATTR_ARGS=$RSYNC_ATTR_ARGS" -X"
|
||||
else
|
||||
Logger "Disabling extended attributes synchronization on [$LOCAL_OS] due to lack of support." "NOTICE"
|
||||
fi
|
||||
fi
|
||||
if [ "$RSYNC_COMPRESS" == "yes" ]; then
|
||||
if [ "$RSYNC_COMPRESS" == true ]; then
|
||||
if [ "$LOCAL_OS" != "MacOSX" ] && [ "$REMOTE_OS" != "MacOSX" ]; then
|
||||
RSYNC_DEFAULT_ARGS=$RSYNC_DEFAULT_ARGS" -zz --skip-compress=gz/xz/lz/lzma/lzo/rz/jpg/mp3/mp4/7z/bz2/rar/zip/sfark/s7z/ace/apk/arc/cab/dmg/jar/kgb/lzh/lha/lzx/pak/sfx"
|
||||
else
|
||||
Logger "Disabling compression skips on synchronization on [$LOCAL_OS] due to lack of support." "NOTICE"
|
||||
fi
|
||||
fi
|
||||
if [ "$COPY_SYMLINKS" == "yes" ]; then
|
||||
if [ "$COPY_SYMLINKS" == true ]; then
|
||||
RSYNC_DEFAULT_ARGS=$RSYNC_DEFAULT_ARGS" -L"
|
||||
fi
|
||||
if [ "$KEEP_DIRLINKS" == "yes" ]; then
|
||||
if [ "$KEEP_DIRLINKS" == true ]; then
|
||||
RSYNC_DEFAULT_ARGS=$RSYNC_DEFAULT_ARGS" -K"
|
||||
fi
|
||||
if [ "$RSYNC_OPTIONAL_ARGS" != "" ]; then
|
||||
RSYNC_DEFAULT_ARGS=$RSYNC_DEFAULT_ARGS" "$RSYNC_OPTIONAL_ARGS
|
||||
fi
|
||||
if [ "$PRESERVE_HARDLINKS" == "yes" ]; then
|
||||
if [ "$PRESERVE_HARDLINKS" == true ]; then
|
||||
RSYNC_DEFAULT_ARGS=$RSYNC_DEFAULT_ARGS" -H"
|
||||
fi
|
||||
if [ "$CHECKSUM" == "yes" ]; then
|
||||
if [ "$CHECKSUM" == true ]; then
|
||||
RSYNC_TYPE_ARGS=$RSYNC_TYPE_ARGS" --checksum"
|
||||
fi
|
||||
if [ "$BANDWIDTH" != "" ] && [ "$BANDWIDTH" != "0" ]; then
|
||||
RSYNC_DEFAULT_ARGS=$RSYNC_DEFAULT_ARGS" --bwlimit=$BANDWIDTH"
|
||||
fi
|
||||
|
||||
if [ "$PARTIAL" == "yes" ]; then
|
||||
if [ "$PARTIAL" == true ]; then
|
||||
RSYNC_DEFAULT_ARGS=$RSYNC_DEFAULT_ARGS" --partial --partial-dir=\"$PARTIAL_DIR\""
|
||||
RSYNC_PARTIAL_EXCLUDE="--exclude=\"$PARTIAL_DIR\""
|
||||
fi
|
||||
|
||||
if [ "$DELTA_COPIES" != "no" ]; then
|
||||
if [ "$DELTA_COPIES" != false ]; then
|
||||
RSYNC_DEFAULT_ARGS=$RSYNC_DEFAULT_ARGS" --no-whole-file"
|
||||
else
|
||||
RSYNC_DEFAULT_ARGS=$RSYNC_DEFAULT_ARGS" --whole-file"
|
||||
@ -2278,14 +2269,14 @@ function TrapQuit {
|
||||
fi
|
||||
|
||||
if [ $ERROR_ALERT == true ]; then
|
||||
if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then
|
||||
if [ "$RUN_AFTER_CMD_ON_ERROR" == true ]; then
|
||||
RunAfterHook
|
||||
fi
|
||||
Logger "$PROGRAM finished with errors." "ERROR"
|
||||
SendAlert
|
||||
exitcode=1
|
||||
elif [ $WARN_ALERT == true ]; then
|
||||
if [ "$RUN_AFTER_CMD_ON_ERROR" == "yes" ]; then
|
||||
if [ "$RUN_AFTER_CMD_ON_ERROR" == true ]; then
|
||||
RunAfterHook
|
||||
fi
|
||||
Logger "$PROGRAM finished with warnings." "WARN"
|
||||
@ -2308,7 +2299,7 @@ function TrapQuit {
|
||||
|
||||
function CheckEnvironment {
|
||||
|
||||
if [ "$REMOTE_OPERATION" == "yes" ]; then
|
||||
if [ "$REMOTE_OPERATION" == true ]; then
|
||||
if ! type ssh > /dev/null 2>&1 ; then
|
||||
Logger "ssh not present. Cannot start backup." "CRITICAL"
|
||||
exit 1
|
||||
@ -2319,7 +2310,7 @@ function CheckEnvironment {
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if [ "$SQL_BACKUP" != "no" ]; then
|
||||
if [ "$SQL_BACKUP" != false ]; then
|
||||
if ! type mysqldump > /dev/null 2>&1 ; then
|
||||
Logger "mysqldump not present. Cannot backup SQL." "CRITICAL"
|
||||
CAN_BACKUP_SQL=false
|
||||
@ -2331,14 +2322,14 @@ function CheckEnvironment {
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$FILE_BACKUP" != "no" ]; then
|
||||
if [ "$FILE_BACKUP" != false ]; then
|
||||
if ! type rsync > /dev/null 2>&1 ; then
|
||||
Logger "rsync not present. Cannot backup files." "CRITICAL"
|
||||
CAN_BACKUP_FILES=false
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$ENCRYPTION" == "yes" ]; then
|
||||
if [ "$ENCRYPTION" == true ]; then
|
||||
CheckCryptEnvironnment
|
||||
fi
|
||||
|
||||
@ -2364,15 +2355,20 @@ function CheckCryptEnvironnment {
|
||||
|
||||
function CheckCurrentConfig {
|
||||
|
||||
local test
|
||||
local booleans
|
||||
local num_vars
|
||||
|
||||
if [ "$INSTANCE_ID" == "" ]; then
|
||||
Logger "No INSTANCE_ID defined in config file." "CRITICAL"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check all variables that should contain "yes" or "no"
|
||||
declare -a yes_no_vars=(SQL_BACKUP FILE_BACKUP ENCRYPTION CREATE_DIRS KEEP_ABSOLUTE_PATHS GET_BACKUP_SIZE SSH_COMPRESSION SSH_IGNORE_KNOWN_HOSTS REMOTE_HOST_PING SUDO_EXEC DATABASES_ALL PRESERVE_PERMISSIONS PRESERVE_OWNER PRESERVE_GROUP PRESERVE_EXECUTABILITY PRESERVE_ACL PRESERVE_XATTR COPY_SYMLINKS KEEP_DIRLINKS PRESERVE_HARDLINKS RSYNC_COMPRESS PARTIAL DELETE_VANISHED_FILES DELTA_COPIES ROTATE_SQL_BACKUPS ROTATE_FILE_BACKUPS STOP_ON_CMD_ERROR RUN_AFTER_CMD_ON_ERROR)
|
||||
for i in "${yes_no_vars[@]}"; do
|
||||
test="if [ \"\$$i\" != \"yes\" ] && [ \"\$$i\" != \"no\" ]; then Logger \"Bogus $i value [\$$i] defined in config file. Correct your config file or update it with the update script if using and old version.\" \"CRITICAL\"; exit 1; fi"
|
||||
# v2 config will use true / false instead of yes / no
|
||||
# Check all variables that should contain "yes" or "no", true or false
|
||||
declare -a booleans=(SQL_BACKUP FILE_BACKUP ENCRYPTION CREATE_DIRS KEEP_ABSOLUTE_PATHS GET_BACKUP_SIZE SSH_COMPRESSION SSH_IGNORE_KNOWN_HOSTS REMOTE_HOST_PING SUDO_EXEC DATABASES_ALL PRESERVE_PERMISSIONS PRESERVE_OWNER PRESERVE_GROUP PRESERVE_EXECUTABILITY PRESERVE_ACL PRESERVE_XATTR COPY_SYMLINKS KEEP_DIRLINKS PRESERVE_HARDLINKS RSYNC_COMPRESS PARTIAL DELETE_VANISHED_FILES DELTA_COPIES ROTATE_SQL_BACKUPS ROTATE_FILE_BACKUPS STOP_ON_CMD_ERROR RUN_AFTER_CMD_ON_ERROR)
|
||||
for i in "${booleans[@]}"; do
|
||||
test="if [ \"\$$i\" != \"yes\" ] && [ \"\$$i\" != \"no\" ] && [ \"\$$i\" != true ] && [ \"\$$i\" != false ]; then Logger \"Bogus $i value [\$$i] defined in config file. Correct your config file or update it with the update script if using and old version.\" \"CRITICAL\"; exit 1; fi"
|
||||
eval "$test"
|
||||
done
|
||||
|
||||
@ -2388,14 +2384,14 @@ function CheckCurrentConfig {
|
||||
eval "$test"
|
||||
done
|
||||
|
||||
if [ "$FILE_BACKUP" == "yes" ]; then
|
||||
if [ "$FILE_BACKUP" == true ]; then
|
||||
if [ "$DIRECTORY_LIST" == "" ] && [ "$RECURSIVE_DIRECTORY_LIST" == "" ]; then
|
||||
Logger "No directories specified in config file, no files to backup." "ERROR"
|
||||
CAN_BACKUP_FILES=false
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$REMOTE_OPERATION" == "yes" ] && [ ! -f "$SSH_RSA_PRIVATE_KEY" ]; then
|
||||
if [ "$REMOTE_OPERATION" == true ] && [ ! -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
|
||||
@ -2406,17 +2402,17 @@ function CheckCurrentConfig {
|
||||
# exit 1
|
||||
#fi
|
||||
|
||||
if [ "$SQL_BACKUP" == "yes" ] && [ "$SQL_STORAGE" == "" ]; then
|
||||
if [ "$SQL_BACKUP" == true ] && [ "$SQL_STORAGE" == "" ]; then
|
||||
Logger "SQL_STORAGE not defined." "CRITICAL"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$FILE_BACKUP" == "yes" ] && [ "$FILE_STORAGE" == "" ]; then
|
||||
if [ "$FILE_BACKUP" == true ] && [ "$FILE_STORAGE" == "" ]; then
|
||||
Logger "FILE_STORAGE not defined." "CRITICAL"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$ENCRYPTION" == "yes" ]; then
|
||||
if [ "$ENCRYPTION" == true ]; then
|
||||
if [ "$CRYPT_STORAGE" == "" ]; then
|
||||
Logger "CRYPT_STORAGE not defined." "CRITICAL"
|
||||
exit 1
|
||||
@ -2427,12 +2423,25 @@ function CheckCurrentConfig {
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$REMOTE_OPERATION" == "yes" ] && ([ ! -f "$SSH_RSA_PRIVATE_KEY" ] && [ ! -f "$SSH_PASSWORD_FILE" ]); then
|
||||
if [ "$REMOTE_OPERATION" == true ] && ([ ! -f "$SSH_RSA_PRIVATE_KEY" ] && [ ! -f "$SSH_PASSWORD_FILE" ]); then
|
||||
Logger "Cannot find rsa private key [$SSH_RSA_PRIVATE_KEY] nor password file [$SSH_PASSWORD_FILE]. No authentication method provided." "CRITICAL"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Change all booleans with "yes" or "no" to true / false for v2 config syntax compatibility
|
||||
function UpdateBooleans {
|
||||
local update
|
||||
local booleans
|
||||
|
||||
declare -a booleans=(SQL_BACKUP FILE_BACKUP ENCRYPTION CREATE_DIRS KEEP_ABSOLUTE_PATHS GET_BACKUP_SIZE SSH_COMPRESSION SSH_IGNORE_KNOWN_HOSTS REMOTE_HOST_PING SUDO_EXEC DATABASES_ALL PRESERVE_PERMISSIONS PRESERVE_OWNER PRESERVE_GROUP PRESERVE_EXECUTABILITY PRESERVE_ACL PRESERVE_XATTR COPY_SYMLINKS KEEP_DIRLINKS PRESERVE_HARDLINKS RSYNC_COMPRESS PARTIAL DELETE_VANISHED_FILES DELTA_COPIES ROTATE_SQL_BACKUPS ROTATE_FILE_BACKUPS STOP_ON_CMD_ERROR RUN_AFTER_CMD_ON_ERROR)
|
||||
|
||||
for i in "${booleans[@]}"; do
|
||||
update="if [ \"\$$i\" == \"yes\" ]; then $i=true; fi; if [ \"\$$i\" == \"no\" ]; then $i=false; fi"
|
||||
eval "$update"
|
||||
done
|
||||
}
|
||||
|
||||
function CheckRunningInstances {
|
||||
|
||||
if [ -f "$RUN_DIR/$PROGRAM.$INSTANCE_ID" ]; then
|
||||
@ -2530,7 +2539,7 @@ function ListDatabases {
|
||||
while read -r line; do
|
||||
while read -r name size; do dbName=$name; dbSize=$size; done <<< "$line"
|
||||
|
||||
if [ "$DATABASES_ALL" == "yes" ]; then
|
||||
if [ "$DATABASES_ALL" == true ]; then
|
||||
dbBackup=true
|
||||
IFS=$PATH_SEPARATOR_CHAR read -r -a dbArray <<< "$DATABASES_ALL_EXCLUDE_LIST"
|
||||
for j in "${dbArray[@]}"; do
|
||||
@ -2632,9 +2641,9 @@ env _REMOTE_EXECUTION="true" env PROGRAM="'$PROGRAM'" env SCRIPT_PID="'$SCRIPT_P
|
||||
env RECURSIVE_DIRECTORY_LIST="'$RECURSIVE_DIRECTORY_LIST'" env PATH_SEPARATOR_CHAR="'$PATH_SEPARATOR_CHAR'" \
|
||||
env REMOTE_FIND_CMD="'$REMOTE_FIND_CMD'" $COMMAND_SUDO' bash -s' << 'ENDSSH' > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" 2> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID.$TSTAMP"
|
||||
|
||||
## allow debugging from command line with _DEBUG=yes
|
||||
if [ ! "$_DEBUG" == "yes" ]; then
|
||||
_DEBUG=no
|
||||
## allow debugging from command line with _DEBUG=true
|
||||
if [ ! "$_DEBUG" == true ]; then
|
||||
_DEBUG=false
|
||||
_LOGGER_VERBOSE=false
|
||||
else
|
||||
trap 'TrapError ${LINENO} $?' ERR
|
||||
@ -2704,19 +2713,19 @@ function RemoteLogger {
|
||||
|
||||
if [ "$level" == "CRITICAL" ]; then
|
||||
_Logger "" "$prefix\e[1;33;41m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
elif [ "$level" == "ERROR" ]; then
|
||||
_Logger "" "$prefix\e[31m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
elif [ "$level" == "WARN" ]; then
|
||||
_Logger "" "$prefix\e[33m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
@ -2734,7 +2743,7 @@ function RemoteLogger {
|
||||
_Logger "" "$prefix$value"
|
||||
return
|
||||
elif [ "$level" == "DEBUG" ]; then
|
||||
if [ "$_DEBUG" == "yes" ]; then
|
||||
if [ "$_DEBUG" == true ]; then
|
||||
_Logger "" "$prefix$value"
|
||||
return
|
||||
fi
|
||||
@ -2915,9 +2924,9 @@ env _REMOTE_EXECUTION="true" env PROGRAM="'$PROGRAM'" env SCRIPT_PID="'$SCRIPT_P
|
||||
dirList="'$dirList'" \
|
||||
$COMMAND_SUDO' bash -s' << 'ENDSSH' > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" 2> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID.$TSTAMP" &
|
||||
|
||||
## allow debugging from command line with _DEBUG=yes
|
||||
if [ ! "$_DEBUG" == "yes" ]; then
|
||||
_DEBUG=no
|
||||
## allow debugging from command line with _DEBUG=true
|
||||
if [ ! "$_DEBUG" == true ]; then
|
||||
_DEBUG=false
|
||||
_LOGGER_VERBOSE=false
|
||||
else
|
||||
trap 'TrapError ${LINENO} $?' ERR
|
||||
@ -2987,19 +2996,19 @@ function RemoteLogger {
|
||||
|
||||
if [ "$level" == "CRITICAL" ]; then
|
||||
_Logger "" "$prefix\e[1;33;41m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
elif [ "$level" == "ERROR" ]; then
|
||||
_Logger "" "$prefix\e[31m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
elif [ "$level" == "WARN" ]; then
|
||||
_Logger "" "$prefix\e[33m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
@ -3017,7 +3026,7 @@ function RemoteLogger {
|
||||
_Logger "" "$prefix$value"
|
||||
return
|
||||
elif [ "$level" == "DEBUG" ]; then
|
||||
if [ "$_DEBUG" == "yes" ]; then
|
||||
if [ "$_DEBUG" == true ]; then
|
||||
_Logger "" "$prefix$value"
|
||||
return
|
||||
fi
|
||||
@ -3064,11 +3073,11 @@ function GetDirectoriesSize {
|
||||
Logger "Getting files size" "NOTICE"
|
||||
|
||||
if [ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]; then
|
||||
if [ "$FILE_BACKUP" != "no" ]; then
|
||||
if [ "$FILE_BACKUP" != false ]; then
|
||||
_GetDirectoriesSizeLocal "$FILE_SIZE_LIST"
|
||||
fi
|
||||
elif [ "$BACKUP_TYPE" == "pull" ]; then
|
||||
if [ "$FILE_BACKUP" != "no" ]; then
|
||||
if [ "$FILE_BACKUP" != false ]; then
|
||||
_GetDirectoriesSizeRemote "$FILE_SIZE_LIST"
|
||||
fi
|
||||
fi
|
||||
@ -3108,9 +3117,9 @@ env _DEBUG="'$_DEBUG'" env _PARANOIA_DEBUG="'$_PARANOIA_DEBUG'" env _LOGGER_SILE
|
||||
env _REMOTE_EXECUTION="true" env PROGRAM="'$PROGRAM'" env SCRIPT_PID="'$SCRIPT_PID'" env TSTAMP="'$TSTAMP'" \
|
||||
env dirToCreate="'$dirToCreate'" $COMMAND_SUDO' bash -s' << 'ENDSSH' > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" 2>&1 &
|
||||
|
||||
## allow debugging from command line with _DEBUG=yes
|
||||
if [ ! "$_DEBUG" == "yes" ]; then
|
||||
_DEBUG=no
|
||||
## allow debugging from command line with _DEBUG=true
|
||||
if [ ! "$_DEBUG" == true ]; then
|
||||
_DEBUG=false
|
||||
_LOGGER_VERBOSE=false
|
||||
else
|
||||
trap 'TrapError ${LINENO} $?' ERR
|
||||
@ -3180,19 +3189,19 @@ function RemoteLogger {
|
||||
|
||||
if [ "$level" == "CRITICAL" ]; then
|
||||
_Logger "" "$prefix\e[1;33;41m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
elif [ "$level" == "ERROR" ]; then
|
||||
_Logger "" "$prefix\e[31m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
elif [ "$level" == "WARN" ]; then
|
||||
_Logger "" "$prefix\e[33m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
@ -3210,7 +3219,7 @@ function RemoteLogger {
|
||||
_Logger "" "$prefix$value"
|
||||
return
|
||||
elif [ "$level" == "DEBUG" ]; then
|
||||
if [ "$_DEBUG" == "yes" ]; then
|
||||
if [ "$_DEBUG" == true ]; then
|
||||
_Logger "" "$prefix$value"
|
||||
return
|
||||
fi
|
||||
@ -3242,38 +3251,38 @@ ENDSSH
|
||||
function CreateStorageDirectories {
|
||||
|
||||
if [ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "pull" ]; then
|
||||
if [ "$SQL_BACKUP" != "no" ]; then
|
||||
if [ "$SQL_BACKUP" != false ]; then
|
||||
_CreateDirectoryLocal "$SQL_STORAGE"
|
||||
if [ $? -ne 0 ]; then
|
||||
CAN_BACKUP_SQL=false
|
||||
fi
|
||||
fi
|
||||
if [ "$FILE_BACKUP" != "no" ]; then
|
||||
if [ "$FILE_BACKUP" != false ]; then
|
||||
_CreateDirectoryLocal "$FILE_STORAGE"
|
||||
if [ $? -ne 0 ]; then
|
||||
CAN_BACKUP_FILES=false
|
||||
fi
|
||||
fi
|
||||
if [ "$ENCRYPTION" == "yes" ]; then
|
||||
if [ "$ENCRYPTION" == true ]; then
|
||||
_CreateDirectoryLocal "$CRYPT_STORAGE"
|
||||
if [ $? -ne 0 ]; then
|
||||
CAN_BACKUP_FILES=false
|
||||
fi
|
||||
fi
|
||||
elif [ "$BACKUP_TYPE" == "push" ]; then
|
||||
if [ "$SQL_BACKUP" != "no" ]; then
|
||||
if [ "$SQL_BACKUP" != false ]; then
|
||||
_CreateDirectoryRemote "$SQL_STORAGE"
|
||||
if [ $? -ne 0 ]; then
|
||||
CAN_BACKUP_SQL=false
|
||||
fi
|
||||
fi
|
||||
if [ "$FILE_BACKUP" != "no" ]; then
|
||||
if [ "$FILE_BACKUP" != false ]; then
|
||||
_CreateDirectoryRemote "$FILE_STORAGE"
|
||||
if [ $? -ne 0 ]; then
|
||||
CAN_BACKUP_FILES=false
|
||||
fi
|
||||
fi
|
||||
if [ "$ENCRYPTION" == "yes" ]; then
|
||||
if [ "$ENCRYPTION" == true ]; then
|
||||
_CreateDirectoryLocal "$CRYPT_STORAGE"
|
||||
if [ $? -ne 0 ]; then
|
||||
CAN_BACKUP_FILES=false
|
||||
@ -3327,9 +3336,9 @@ env _REMOTE_EXECUTION="true" env PROGRAM="'$PROGRAM'" env SCRIPT_PID="'$SCRIPT_P
|
||||
env DF_CMD="'$DF_CMD'" \
|
||||
env pathToCheck="'$pathToCheck'" $COMMAND_SUDO' bash -s' << 'ENDSSH' > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" 2> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID.$TSTAMP" &
|
||||
|
||||
## allow debugging from command line with _DEBUG=yes
|
||||
if [ ! "$_DEBUG" == "yes" ]; then
|
||||
_DEBUG=no
|
||||
## allow debugging from command line with _DEBUG=true
|
||||
if [ ! "$_DEBUG" == true ]; then
|
||||
_DEBUG=false
|
||||
_LOGGER_VERBOSE=false
|
||||
else
|
||||
trap 'TrapError ${LINENO} $?' ERR
|
||||
@ -3399,19 +3408,19 @@ function RemoteLogger {
|
||||
|
||||
if [ "$level" == "CRITICAL" ]; then
|
||||
_Logger "" "$prefix\e[1;33;41m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
elif [ "$level" == "ERROR" ]; then
|
||||
_Logger "" "$prefix\e[31m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
elif [ "$level" == "WARN" ]; then
|
||||
_Logger "" "$prefix\e[33m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
@ -3429,7 +3438,7 @@ function RemoteLogger {
|
||||
_Logger "" "$prefix$value"
|
||||
return
|
||||
elif [ "$level" == "DEBUG" ]; then
|
||||
if [ "$_DEBUG" == "yes" ]; then
|
||||
if [ "$_DEBUG" == true ]; then
|
||||
_Logger "" "$prefix$value"
|
||||
return
|
||||
fi
|
||||
@ -3483,7 +3492,7 @@ function CheckDiskSpace {
|
||||
|
||||
|
||||
if [ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "pull" ]; then
|
||||
if [ "$SQL_BACKUP" != "no" ]; then
|
||||
if [ "$SQL_BACKUP" != false ]; then
|
||||
GetDiskSpaceLocal "$SQL_STORAGE"
|
||||
if [ $? -ne 0 ]; then
|
||||
SQL_DISK_SPACE=0
|
||||
@ -3493,7 +3502,7 @@ function CheckDiskSpace {
|
||||
SQL_DRIVE=$DRIVE
|
||||
fi
|
||||
fi
|
||||
if [ "$FILE_BACKUP" != "no" ]; then
|
||||
if [ "$FILE_BACKUP" != false ]; then
|
||||
GetDiskSpaceLocal "$FILE_STORAGE"
|
||||
if [ $? -ne 0 ]; then
|
||||
FILE_DISK_SPACE=0
|
||||
@ -3503,7 +3512,7 @@ function CheckDiskSpace {
|
||||
FILE_DRIVE=$DRIVE
|
||||
fi
|
||||
fi
|
||||
if [ "$ENCRYPTION" != "no" ]; then
|
||||
if [ "$ENCRYPTION" != false ]; then
|
||||
GetDiskSpaceLocal "$CRYPT_STORAGE"
|
||||
if [ $? -ne 0 ]; then
|
||||
CRYPT_DISK_SPACE=0
|
||||
@ -3515,7 +3524,7 @@ function CheckDiskSpace {
|
||||
fi
|
||||
fi
|
||||
elif [ "$BACKUP_TYPE" == "push" ]; then
|
||||
if [ "$SQL_BACKUP" != "no" ]; then
|
||||
if [ "$SQL_BACKUP" != false ]; then
|
||||
GetDiskSpaceRemote "$SQL_STORAGE"
|
||||
if [ $? -ne 0 ]; then
|
||||
SQL_DISK_SPACE=0
|
||||
@ -3524,7 +3533,7 @@ function CheckDiskSpace {
|
||||
SQL_DRIVE=$DRIVE
|
||||
fi
|
||||
fi
|
||||
if [ "$FILE_BACKUP" != "no" ]; then
|
||||
if [ "$FILE_BACKUP" != false ]; then
|
||||
GetDiskSpaceRemote "$FILE_STORAGE"
|
||||
if [ $? -ne 0 ]; then
|
||||
FILE_DISK_SPACE=0
|
||||
@ -3533,7 +3542,7 @@ function CheckDiskSpace {
|
||||
FILE_DRIVE=$DRIVE
|
||||
fi
|
||||
fi
|
||||
if [ "$ENCRYPTION" != "no" ]; then
|
||||
if [ "$ENCRYPTION" != false ]; then
|
||||
GetDiskSpaceLocal "$CRYPT_STORAGE"
|
||||
if [ $? -ne 0 ]; then
|
||||
CRYPT_DISK_SPACE=0
|
||||
@ -3554,7 +3563,7 @@ function CheckDiskSpace {
|
||||
TOTAL_FILES_SIZE=-1
|
||||
fi
|
||||
|
||||
if [ "$SQL_BACKUP" != "no" ] && [ $CAN_BACKUP_SQL == true ]; then
|
||||
if [ "$SQL_BACKUP" != false ] && [ $CAN_BACKUP_SQL == true ]; then
|
||||
if [ $SQL_DISK_SPACE -eq 0 ]; then
|
||||
Logger "Storage space in [$SQL_STORAGE] reported to be 0Ko." "WARN"
|
||||
fi
|
||||
@ -3567,7 +3576,7 @@ function CheckDiskSpace {
|
||||
Logger "SQL storage Space: $SQL_DISK_SPACE Ko - Databases size: $TOTAL_DATABASES_SIZE Ko" "NOTICE"
|
||||
fi
|
||||
|
||||
if [ "$FILE_BACKUP" != "no" ] && [ $CAN_BACKUP_FILES == true ]; then
|
||||
if [ "$FILE_BACKUP" != false ] && [ $CAN_BACKUP_FILES == true ]; then
|
||||
if [ $FILE_DISK_SPACE -eq 0 ]; then
|
||||
Logger "Storage space in [$FILE_STORAGE] reported to be 0 Ko." "WARN"
|
||||
fi
|
||||
@ -3580,8 +3589,8 @@ function CheckDiskSpace {
|
||||
Logger "File storage space: $FILE_DISK_SPACE Ko - Files size: $TOTAL_FILES_SIZE Ko" "NOTICE"
|
||||
fi
|
||||
|
||||
if [ "$ENCRYPTION" == "yes" ]; then
|
||||
if [ "$SQL_BACKUP" != "no" ]; then
|
||||
if [ "$ENCRYPTION" == true ]; then
|
||||
if [ "$SQL_BACKUP" != false ]; then
|
||||
if [ "$SQL_DRIVE" == "$CRYPT_DRIVE" ]; then
|
||||
if [ $((SQL_DISK_SPACE/2)) -lt $((TOTAL_DATABASES_SIZE)) ]; then
|
||||
Logger "Disk space in [$SQL_STORAGE] and [$CRYPT_STORAGE] may be insufficient to backup SQL ($SQL_DISK_SPACE Ko available in $SQL_DRIVE) (non compressed databases calculation + crypt storage space)." "WARN"
|
||||
@ -3593,7 +3602,7 @@ function CheckDiskSpace {
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$FILE_BACKUP" != "no" ]; then
|
||||
if [ "$FILE_BACKUP" != false ]; then
|
||||
if [ "$FILE_DRIVE" == "$CRYPT_DRIVE" ]; then
|
||||
if [ $((FILE_DISK_SPACE/2)) -lt $((TOTAL_FILES_SIZE)) ]; then
|
||||
Logger "Disk space in [$FILE_STORAGE] and [$CRYPT_STORAGE] may be insufficient to encrypt Sfiles ($FILE_DISK_SPACE Ko available in $FILE_DRIVE)." "WARN"
|
||||
@ -3608,7 +3617,7 @@ function CheckDiskSpace {
|
||||
Logger "Crypt storage space: $CRYPT_DISK_SPACE Ko" "NOTICE"
|
||||
fi
|
||||
|
||||
if [ $BACKUP_SIZE_MINIMUM -gt $((TOTAL_DATABASES_SIZE+TOTAL_FILES_SIZE)) ] && [ "$GET_BACKUP_SIZE" != "no" ]; then
|
||||
if [ $BACKUP_SIZE_MINIMUM -gt $((TOTAL_DATABASES_SIZE+TOTAL_FILES_SIZE)) ] && [ "$GET_BACKUP_SIZE" != false ]; then
|
||||
Logger "Backup size is smaller than expected." "WARN"
|
||||
fi
|
||||
}
|
||||
@ -3765,7 +3774,7 @@ function BackupDatabase {
|
||||
mysqlOptions="$MYSQLDUMP_OPTIONS"
|
||||
fi
|
||||
|
||||
if [ "$ENCRYPTION" == "yes" ]; then
|
||||
if [ "$ENCRYPTION" == true ]; then
|
||||
encrypt=true
|
||||
Logger "Backing up encrypted database [$database]." "NOTICE"
|
||||
else
|
||||
@ -4069,7 +4078,7 @@ function FilesBackup {
|
||||
for backupTask in "${backupTasks[@]}"; do
|
||||
# Backup directories from simple list
|
||||
|
||||
if [ "$KEEP_ABSOLUTE_PATHS" != "no" ]; then
|
||||
if [ "$KEEP_ABSOLUTE_PATHS" != false ]; then
|
||||
# Fix for backup of '/'
|
||||
if [ "${backupTask#/}/" == "/" ]; then
|
||||
destinationDir="$FILE_STORAGE/"
|
||||
@ -4083,14 +4092,14 @@ function FilesBackup {
|
||||
fi
|
||||
|
||||
Logger "Beginning file backup of [$backupTask] to [$destinationDir] as $BACKUP_TYPE backup." "NOTICE"
|
||||
if [ "$ENCRYPTION" == "yes" ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
||||
if [ "$ENCRYPTION" == true ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
||||
EncryptFiles "$backupTask" "$CRYPT_STORAGE" "$GPG_RECIPIENT" true true
|
||||
if [ $? -eq 0 ]; then
|
||||
Rsync "$CRYPT_STORAGE/$backupTask" "$destinationDir" true
|
||||
else
|
||||
Logger "backup failed." "ERROR"
|
||||
fi
|
||||
elif [ "$ENCRYPTION" == "yes" ] && [ "$BACKUP_TYPE" == "pull" ]; then
|
||||
elif [ "$ENCRYPTION" == true ] && [ "$BACKUP_TYPE" == "pull" ]; then
|
||||
Rsync "$backupTask" "$destinationDir" true
|
||||
if [ $? -eq 0 ]; then
|
||||
EncryptFiles "$encryptDir" "$CRYPT_STORAGE/$backupTask" "$GPG_RECIPIENT" true false
|
||||
@ -4105,7 +4114,7 @@ function FilesBackup {
|
||||
for backupTask in "${backupTasks[@]}"; do
|
||||
# Backup recursive directories without recursion
|
||||
|
||||
if [ "$KEEP_ABSOLUTE_PATHS" != "no" ]; then
|
||||
if [ "$KEEP_ABSOLUTE_PATHS" != false ]; then
|
||||
# Fix for backup of '/'
|
||||
if [ "${backupTask#/}/" == "/" ]; then
|
||||
destinationDir="$FILE_STORAGE/"
|
||||
@ -4119,14 +4128,14 @@ function FilesBackup {
|
||||
fi
|
||||
|
||||
Logger "Beginning non recursive file backup of [$backupTask] to [$destinationDir] as $BACKUP_TYPE backup." "NOTICE"
|
||||
if [ "$ENCRYPTION" == "yes" ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
||||
if [ "$ENCRYPTION" == true ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
||||
EncryptFiles "$backupTask" "$CRYPT_STORAGE" "$GPG_RECIPIENT" false true
|
||||
if [ $? -eq 0 ]; then
|
||||
Rsync "$CRYPT_STORAGE/$backupTask" "$destinationDir" false
|
||||
else
|
||||
Logger "backup failed." "ERROR"
|
||||
fi
|
||||
elif [ "$ENCRYPTION" == "yes" ] && [ "$BACKUP_TYPE" == "pull" ]; then
|
||||
elif [ "$ENCRYPTION" == true ] && [ "$BACKUP_TYPE" == "pull" ]; then
|
||||
Rsync "$backupTask" "$destinationDir" false
|
||||
if [ $? -eq 0 ]; then
|
||||
EncryptFiles "$encryptDir" "$CRYPT_STORAGE/$backupTask" "$GPG_RECIPIENT" false false
|
||||
@ -4141,7 +4150,7 @@ function FilesBackup {
|
||||
for backupTask in "${backupTasks[@]}"; do
|
||||
# Backup sub directories of recursive directories
|
||||
|
||||
if [ "$KEEP_ABSOLUTE_PATHS" != "no" ]; then
|
||||
if [ "$KEEP_ABSOLUTE_PATHS" != false ]; then
|
||||
# Fix for backup of '/'
|
||||
if [ "${backupTask#/}/" == "/" ]; then
|
||||
destinationDir="$FILE_STORAGE/"
|
||||
@ -4155,14 +4164,14 @@ function FilesBackup {
|
||||
fi
|
||||
|
||||
Logger "Beginning recursive child file backup of [$backupTask] to [$destinationDir] as $BACKUP_TYPE backup." "NOTICE"
|
||||
if [ "$ENCRYPTION" == "yes" ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
||||
if [ "$ENCRYPTION" == true ] && ([ "$BACKUP_TYPE" == "local" ] || [ "$BACKUP_TYPE" == "push" ]); then
|
||||
EncryptFiles "$backupTask" "$CRYPT_STORAGE" "$GPG_RECIPIENT" true true
|
||||
if [ $? -eq 0 ]; then
|
||||
Rsync "$CRYPT_STORAGE/$backupTask" "$destinationDir" true
|
||||
else
|
||||
Logger "backup failed." "ERROR"
|
||||
fi
|
||||
elif [ "$ENCRYPTION" == "yes" ] && [ "$BACKUP_TYPE" == "pull" ]; then
|
||||
elif [ "$ENCRYPTION" == true ] && [ "$BACKUP_TYPE" == "pull" ]; then
|
||||
Rsync "$backupTask" "$destinationDir" true
|
||||
if [ $? -eq 0 ]; then
|
||||
EncryptFiles "$encryptDir" "$CRYPT_STORAGE/$backupTask" "$GPG_RECIPIENT" true false
|
||||
@ -4243,7 +4252,7 @@ function _RotateBackupsLocal {
|
||||
fi
|
||||
|
||||
else
|
||||
#elif [ "$REMOTE_OPERATION" == "yes" ]; then
|
||||
#elif [ "$REMOTE_OPERATION" == true ]; then
|
||||
cmd="cp -R \"$backup\" \"$backup.$PROGRAM.1\""
|
||||
Logger "Launching command [$cmd]." "DEBUG"
|
||||
eval "$cmd" &
|
||||
@ -4276,9 +4285,9 @@ env _REMOTE_EXECUTION="true" env PROGRAM="'$PROGRAM'" env SCRIPT_PID="'$SCRIPT_P
|
||||
env REMOTE_FIND_CMD="'$REMOTE_FIND_CMD'" env rotateCopies="'$rotateCopies'" env backupPath="'$backupPath'" \
|
||||
$COMMAND_SUDO' bash -s' << 'ENDSSH' > "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.$SCRIPT_PID.$TSTAMP" 2> "$RUN_DIR/$PROGRAM.${FUNCNAME[0]}.error.$SCRIPT_PID.$TSTAMP"
|
||||
|
||||
## allow debugging from command line with _DEBUG=yes
|
||||
if [ ! "$_DEBUG" == "yes" ]; then
|
||||
_DEBUG=no
|
||||
## allow debugging from command line with _DEBUG=true
|
||||
if [ ! "$_DEBUG" == true ]; then
|
||||
_DEBUG=false
|
||||
_LOGGER_VERBOSE=false
|
||||
else
|
||||
trap 'TrapError ${LINENO} $?' ERR
|
||||
@ -4348,19 +4357,19 @@ function RemoteLogger {
|
||||
|
||||
if [ "$level" == "CRITICAL" ]; then
|
||||
_Logger "" "$prefix\e[1;33;41m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
elif [ "$level" == "ERROR" ]; then
|
||||
_Logger "" "$prefix\e[31m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
elif [ "$level" == "WARN" ]; then
|
||||
_Logger "" "$prefix\e[33m$value\e[0m" true
|
||||
if [ $_DEBUG == "yes" ]; then
|
||||
if [ $_DEBUG == true ]; then
|
||||
_Logger -e "" "[$retval] in [$(joinString , ${FUNCNAME[@]})] SP=$SCRIPT_PID P=$$" true
|
||||
fi
|
||||
return
|
||||
@ -4378,7 +4387,7 @@ function RemoteLogger {
|
||||
_Logger "" "$prefix$value"
|
||||
return
|
||||
elif [ "$level" == "DEBUG" ]; then
|
||||
if [ "$_DEBUG" == "yes" ]; then
|
||||
if [ "$_DEBUG" == true ]; then
|
||||
_Logger "" "$prefix$value"
|
||||
return
|
||||
fi
|
||||
@ -4434,7 +4443,7 @@ function _RotateBackupsRemoteSSH {
|
||||
fi
|
||||
|
||||
else
|
||||
#elif [ "$REMOTE_OPERATION" == "yes" ]; then
|
||||
#elif [ "$REMOTE_OPERATION" == true ]; then
|
||||
cmd="cp -R \"$backup\" \"$backup.$PROGRAM.1\""
|
||||
RemoteLogger "Launching command [$cmd]." "DEBUG"
|
||||
eval "$cmd"
|
||||
@ -4494,7 +4503,7 @@ function Init {
|
||||
|
||||
## Test if target dir is a ssh uri, and if yes, break it down it its values
|
||||
if [ "${REMOTE_SYSTEM_URI:0:6}" == "ssh://" ] && [ "$BACKUP_TYPE" != "local" ]; then
|
||||
REMOTE_OPERATION="yes"
|
||||
REMOTE_OPERATION=true
|
||||
|
||||
# remove leadng 'ssh://'
|
||||
uri=${REMOTE_SYSTEM_URI#ssh://*}
|
||||
@ -4531,7 +4540,7 @@ function Init {
|
||||
RSYNC_TYPE_ARGS=$RSYNC_TYPE_ARGS" -i"
|
||||
fi
|
||||
|
||||
if [ "$DELETE_VANISHED_FILES" == "yes" ]; then
|
||||
if [ "$DELETE_VANISHED_FILES" == true ]; then
|
||||
RSYNC_TYPE_ARGS=$RSYNC_TYPE_ARGS" --delete"
|
||||
fi
|
||||
|
||||
@ -4545,12 +4554,12 @@ function Init {
|
||||
|
||||
function Main {
|
||||
|
||||
if [ "$SQL_BACKUP" != "no" ] && [ $CAN_BACKUP_SQL == true ]; then
|
||||
if [ "$SQL_BACKUP" != false ] && [ $CAN_BACKUP_SQL == true ]; then
|
||||
ListDatabases
|
||||
fi
|
||||
if [ "$FILE_BACKUP" != "no" ] && [ $CAN_BACKUP_FILES == true ]; then
|
||||
if [ "$FILE_BACKUP" != false ] && [ $CAN_BACKUP_FILES == true ]; then
|
||||
ListRecursiveBackupDirectories
|
||||
if [ "$GET_BACKUP_SIZE" != "no" ]; then
|
||||
if [ "$GET_BACKUP_SIZE" != false ]; then
|
||||
GetDirectoriesSize
|
||||
else
|
||||
TOTAL_FILES_SIZE=-1
|
||||
@ -4564,21 +4573,21 @@ function Main {
|
||||
SSH_PASSWORD_FILE="${SSH_PASSWORD_FILE/#\~/$HOME}"
|
||||
ENCRYPT_PUBKEY="${ENCRYPT_PUBKEY/#\~/$HOME}"
|
||||
|
||||
if [ "$CREATE_DIRS" != "no" ]; then
|
||||
if [ "$CREATE_DIRS" != false ]; then
|
||||
CreateStorageDirectories
|
||||
fi
|
||||
CheckDiskSpace
|
||||
|
||||
# Actual backup process
|
||||
if [ "$SQL_BACKUP" != "no" ] && [ $CAN_BACKUP_SQL == true ]; then
|
||||
if [ $_DRYRUN == false ] && [ "$ROTATE_SQL_BACKUPS" == "yes" ]; then
|
||||
if [ "$SQL_BACKUP" != false ] && [ $CAN_BACKUP_SQL == true ]; then
|
||||
if [ $_DRYRUN == false ] && [ "$ROTATE_SQL_BACKUPS" == true ]; then
|
||||
RotateBackups "$SQL_STORAGE" "$ROTATE_SQL_COPIES"
|
||||
fi
|
||||
BackupDatabases
|
||||
fi
|
||||
|
||||
if [ "$FILE_BACKUP" != "no" ] && [ $CAN_BACKUP_FILES == true ]; then
|
||||
if [ $_DRYRUN == false ] && [ "$ROTATE_FILE_BACKUPS" == "yes" ]; then
|
||||
if [ "$FILE_BACKUP" != false ] && [ $CAN_BACKUP_FILES == true ]; then
|
||||
if [ $_DRYRUN == false ] && [ "$ROTATE_FILE_BACKUPS" == true ]; then
|
||||
RotateBackups "$FILE_STORAGE" "$ROTATE_FILE_COPIES"
|
||||
fi
|
||||
## Add Rsync include / exclude patterns
|
||||
@ -4590,7 +4599,7 @@ function Main {
|
||||
function Usage {
|
||||
|
||||
|
||||
if [ "$IS_STABLE" != "yes" ]; then
|
||||
if [ "$IS_STABLE" != true ]; then
|
||||
echo -e "\e[93mThis is an unstable dev build. Please use with caution.\e[0m"
|
||||
fi
|
||||
|
||||
@ -4748,6 +4757,9 @@ else
|
||||
LOG_FILE="$LOGFILE"
|
||||
fi
|
||||
|
||||
# v2.3 config syntax compatibility
|
||||
UpdateBooleans
|
||||
|
||||
if [ ! -w "$(dirname $LOG_FILE)" ]; then
|
||||
echo "Cannot write to log [$(dirname $LOG_FILE)]."
|
||||
else
|
||||
@ -4764,18 +4776,18 @@ if [ $no_maxtime == true ]; then
|
||||
fi
|
||||
|
||||
if [ $partial_transfers == true ]; then
|
||||
PARTIAL="yes"
|
||||
PARTIAL=true
|
||||
fi
|
||||
|
||||
if [ $delete_vanished == true ]; then
|
||||
DELETE_VANISHED_FILES="yes"
|
||||
DELETE_VANISHED_FILES=true
|
||||
fi
|
||||
|
||||
if [ $dont_get_backup_size == true ]; then
|
||||
GET_BACKUP_SIZE="no"
|
||||
GET_BACKUP_SIZE=false
|
||||
fi
|
||||
|
||||
if [ "$IS_STABLE" != "yes" ]; then
|
||||
if [ "$IS_STABLE" != true ]; then
|
||||
Logger "This is an unstable dev build [$PROGRAM_BUILD]. Please use with caution." "WARN"
|
||||
fi
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user