1
0
mirror of https://github.com/deajan/obackup.git synced 2024-11-14 03:33:41 +01:00

Some sanity code cleanup

This commit is contained in:
deajan 2016-03-14 21:50:40 +01:00
parent e18ebd1115
commit 5c74224dcd
5 changed files with 45 additions and 50 deletions

View File

@ -1,4 +1,4 @@
Copyright (c) 2013-2015, Orsiris "Ozy" de Jong. ozy@netpower.fr Copyright (c) 2013-2016, Orsiris "Ozy" de Jong. ozy@netpower.fr
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

View File

@ -8,7 +8,7 @@ PROGRAM_VERSION=2.0-pre
PROGRAM_BUILD=2016030302 PROGRAM_BUILD=2016030302
IS_STABLE=no IS_STABLE=no
## FUNC_BUILD=2016031001 ## FUNC_BUILD=2016031101
## 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
@ -200,6 +200,7 @@ function SendAlert {
fi fi
if type mutt > /dev/null 2>&1 ; then if type mutt > /dev/null 2>&1 ; then
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mutt) -x -s \"$subject\" $DESTINATION_MAILS $attachment_command" cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mutt) -x -s \"$subject\" $DESTINATION_MAILS $attachment_command"
Logger "Mail cmd: $cmd" "DEBUG"
eval $cmd eval $cmd
if [ $? != 0 ]; then if [ $? != 0 ]; then
Logger "Cannot send alert email via $(type -p mutt) !!!" "WARN" Logger "Cannot send alert email via $(type -p mutt) !!!" "WARN"
@ -218,10 +219,12 @@ function SendAlert {
attachment_command="" attachment_command=""
fi fi
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) $attachment_command -s \"$subject\" $DESTINATION_MAILS" cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) $attachment_command -s \"$subject\" $DESTINATION_MAILS"
Logger "Mail cmd: $cmd" "DEBUG"
eval $cmd eval $cmd
if [ $? != 0 ]; then if [ $? != 0 ]; then
Logger "Cannot send alert email via $(type -p mail) with attachments !!!" "WARN" Logger "Cannot send alert email via $(type -p mail) with attachments !!!" "WARN"
cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) -s \"$subject\" $DESTINATION_MAILS" cmd="echo \"$MAIL_ALERT_MSG\" | $(type -p mail) -s \"$subject\" $DESTINATION_MAILS"
Logger "Mail cmd: $cmd" "DEBUG"
eval $cmd eval $cmd
if [ $? != 0 ]; then if [ $? != 0 ]; then
Logger "Cannot send alert email via $(type -p mail) without attachments !!!" "WARN" Logger "Cannot send alert email via $(type -p mail) without attachments !!!" "WARN"
@ -237,6 +240,7 @@ function SendAlert {
if type sendmail > /dev/null 2>&1 ; then if type sendmail > /dev/null 2>&1 ; then
cmd="echo -e \"Subject:$subject\r\n$MAIL_ALERT_MSG\" | $(type -p sendmail) $DESTINATION_MAILS" cmd="echo -e \"Subject:$subject\r\n$MAIL_ALERT_MSG\" | $(type -p sendmail) $DESTINATION_MAILS"
Logger "Mail cmd: $cmd" "DEBUG"
eval $cmd eval $cmd
if [ $? != 0 ]; then if [ $? != 0 ]; then
Logger "Cannot send alert email via $(type -p sendmail) !!!" "WARN" Logger "Cannot send alert email via $(type -p sendmail) !!!" "WARN"

View File

@ -3,10 +3,10 @@
PROGRAM=obackup PROGRAM=obackup
PROGRAM_BINARY=$PROGRAM".sh" PROGRAM_BINARY=$PROGRAM".sh"
PROGRAM_BATCH=$PROGRAM"-batch.sh" PROGRAM_BATCH=$PROGRAM"-batch.sh"
SCRIPT_BUILD=2015102701 SCRIPT_BUILD=2016031401
## osync / obackup daemon install script ## osync / obackup daemon install script
## Tested on RHEL / CentOS 6 & 7 and Mint 17 ## Tested on RHEL / CentOS 6 & 7, Fedora 23, Debian 7 & 8, Mint 17 and FreeBSD 8 & 10
## Please adapt this to fit your distro needs ## Please adapt this to fit your distro needs
CONF_DIR=/etc/$PROGRAM CONF_DIR=/etc/$PROGRAM
@ -30,48 +30,48 @@ else
echo "Config directory [$CONF_DIR] exists." echo "Config directory [$CONF_DIR] exists."
fi fi
if [ -f ./sync.conf ]; then if [ -f "./sync.conf" ]; then
cp ./sync.conf /etc/$PROGRAM/sync.conf.example cp "./sync.conf" "/etc/$PROGRAM/sync.conf.example"
fi fi
if [ -f ./host_backup.conf ]; then if [ -f "./host_backup.conf" ]; then
cp ./host_backup.conf /etc/$PROGRAM/host_backup.conf.example cp "./host_backup.conf" "/etc/$PROGRAM/host_backup.conf.example"
fi fi
if [ -f ./exlude.list.example ]; then if [ -f "./exlude.list.example" ]; then
cp ./exclude.list.example /etc/$PROGRAM cp "./exclude.list.example" "/etc/$PROGRAM"
fi fi
cp ./$PROGRAM_BINARY "$BIN_DIR" cp "./$PROGRAM_BINARY" "$BIN_DIR"
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "Cannot copy $PROGRAM_BINARY to [$BIN_DIR]." echo "Cannot copy $PROGRAM_BINARY to [$BIN_DIR]."
else else
echo "Copied $PROGRAM_BINARY to [$BIN_DIR]." echo "Copied $PROGRAM_BINARY to [$BIN_DIR]."
fi fi
cp ./$PROGRAM_BATCH /usr/local/bin cp "./$PROGRAM_BATCH" "/usr/local/bin"
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "Cannot copy $PROGRAM_BATCH to [$BIN_DIR]." echo "Cannot copy $PROGRAM_BATCH to [$BIN_DIR]."
else else
echo "Copied $PROGRAM_BATCH to [$BIN_DIR]." echo "Copied $PROGRAM_BATCH to [$BIN_DIR]."
fi fi
cp ./ssh_filter.sh /usr/local/bin cp "./ssh_filter.sh" "/usr/local/bin"
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "Cannot copy ssh_filter.sh to [$BIN_DIR]." echo "Cannot copy ssh_filter.sh to [$BIN_DIR]."
else else
echo "Copied ssh_filter.sh to [$BIN_DIR]." echo "Copied ssh_filter.sh to [$BIN_DIR]."
fi fi
if [ -f ./osync-srv ]; then if [ -f "./osync-srv" ]; then
cp ./osync-srv "$SERVICE_DIR" cp "./osync-srv" "$SERVICE_DIR"
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "Cannot copy osync-srv to [$SERVICE_DIR]." echo "Cannot copy osync-srv to [$SERVICE_DIR]."
else else
echo "Created osync-srv service in [$SERVICE_DIR]." echo "Created osync-srv service in [$SERVICE_DIR]."
chmod 755 /etc/init.d/osync-srv chmod 755 "/etc/init.d/osync-srv"
fi fi
fi fi
chmod 755 /usr/local/bin/$PROGRAM_BINARY chmod 755 "/usr/local/bin/$PROGRAM_BINARY"
chmod 755 /usr/local/bin/$PROGRAM_BATCH chmod 755 "/usr/local/bin/$PROGRAM_BATCH"
chmod 755 /usr/local/bin/ssh_filter.sh chmod 755 "/usr/local/bin/ssh_filter.sh"
chown root:root /usr/local/bin/ssh_filter.sh chown root:root "/usr/local/bin/ssh_filter.sh"

View File

@ -1,9 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
SUBPROGRAM=obackup SUBPROGRAM=obackup
PROGRAM="$SUBPROGRAM-batch" # Batch program to run osync / obackup instances sequentially and rerun failed ones PROGRAM="$SUBPROGRAM-batch" # Batch program to run osync / obackup instances sequentially and rerun failed ones
AUTHOR="(L) 2013-2015 by Orsiris \"Ozy\" de Jong" AUTHOR="(L) 2013-2016 by Orsiris de Jong"
CONTACT="http://www.netpower.fr - ozy@netpower.fr" CONTACT="http://www.netpower.fr - ozy@netpower.fr"
PROGRAM_BUILD=2015111801 PROGRAM_BUILD=2016031301
## Runs an osync /obackup instance for every conf file found ## Runs an osync /obackup instance for every conf file found
## If an instance fails, run it again if time permits ## If an instance fails, run it again if time permits
@ -43,10 +43,8 @@ function Logger {
if [ "$level" == "CRITICAL" ]; then if [ "$level" == "CRITICAL" ]; then
_logger "$prefix\e[41m$value\e[0m" _logger "$prefix\e[41m$value\e[0m"
ERROR_ALERT=1
elif [ "$level" == "ERROR" ]; then elif [ "$level" == "ERROR" ]; then
_logger "$prefix\e[91m$value\e[0m" _logger "$prefix\e[91m$value\e[0m"
ERROR_ALERT=1
elif [ "$level" == "WARN" ]; then elif [ "$level" == "WARN" ]; then
_logger "$prefix\e[93m$value\e[0m" _logger "$prefix\e[93m$value\e[0m"
elif [ "$level" == "NOTICE" ]; then elif [ "$level" == "NOTICE" ]; then
@ -85,7 +83,7 @@ function CheckEnvironment {
function Batch { function Batch {
## Get list of .conf files ## Get list of .conf files
for i in $(ls $CONF_FILE_PATH/*.conf) for i in $CONF_FILE_PATH/*.conf
do do
if [ "$RUN" == "" ]; then if [ "$RUN" == "" ]; then
RUN="$i" RUN="$i"
@ -104,7 +102,7 @@ function Batch {
wait $! wait $!
if [ $? != 0 ]; then if [ $? != 0 ]; then
Logger "Run instance $(basename $i) failed" "ERROR" Logger "Run instance $(basename $i) failed" "ERROR"
if [ "RUN_AGAIN" == "" ]; then if [ "$RUN_AGAIN" == "" ]; then
RUN_AGAIN="$i" RUN_AGAIN="$i"
else else
RUN_AGAIN=$RUN_AGAIN" $i" RUN_AGAIN=$RUN_AGAIN" $i"
@ -138,23 +136,17 @@ function Usage {
exit 128 exit 128
} }
_SILENT=0
_DRY=0
_VERBOSE=0
opts="" opts=""
for i in "$@" for i in "$@"
do do
case $i in case $i in
--silent) --silent)
_SILENT=1
opts=$opts" --silent" opts=$opts" --silent"
;; ;;
--dry) --dry)
_DRY=1
opts=$opts" --dry" opts=$opts" --dry"
;; ;;
--verbose) --verbose)
_VERBOSE=1
opts=$opts" --verbose" opts=$opts" --verbose"
;; ;;
--no-maxtime) --no-maxtime)

View File

@ -1,21 +1,22 @@
#!/usr/bin/env bash #!/usr/bin/env bash
##### osync / obackup ssh command filter build 2015102701 ##### osync / obackup ssh command filter
##### This script should be located in /usr/local/bin in the remote system to sync / backup ##### This script should be located in /usr/local/bin in the remote system to sync / backup
##### It will filter the commands that can be run remotely via ssh. ##### It will filter the commands that can be run remotely via ssh.
##### Please chmod 755 and chown root:root this file ##### Please chmod 755 and chown root:root this file
##### Obackup needed commands: rsync find du mysql mysqldump (sudo) ##### Obackup needed commands: rsync find du mysql mysqldump (sudo)
##### Osync needed commands: rsync find du echo mkdir rm if df (sudo) ##### Osync needed commands: rsync find du echo mkdir rm if df (sudo)
SCRIPT_BUILD=2016031401
## If enabled, execution of "sudo" command will be allowed. ## If enabled, execution of "sudo" command will be allowed.
SUDO_EXEC=yes SUDO_EXEC=yes
## Paranoia option. Don't change this unless you read the documentation and still feel concerned about security issues. ## Paranoia option. Don't change this unless you read the documentation and still feel concerned about security issues.
RSYNC_EXECUTABLE=rsync RSYNC_EXECUTABLE=rsync
## Enable other commands, useful for remote execution hooks like remotely creating snapshots. ## Enable other commands, useful for remote execution hooks like remotely creating snapshots.
CMD1= CMD1=""
CMD2= CMD2=""
CMD3= CMD3=""
LOG_FILE=~/.ssh/ssh_filter.log LOG_FILE=~/.ssh/ssh_filter.log
@ -25,7 +26,7 @@ function Log {
} }
function Go { function Go {
eval $SSH_ORIGINAL_COMMAND eval "$SSH_ORIGINAL_COMMAND"
} }
case ${SSH_ORIGINAL_COMMAND%% *} in case ${SSH_ORIGINAL_COMMAND%% *} in
@ -47,16 +48,19 @@ case ${SSH_ORIGINAL_COMMAND%% *} in
Go ;; Go ;;
"$CMD1") "$CMD1")
if [ "$CMD1" != "" ]; then if [ "$CMD1" != "" ]; then
Go ;; Go
fi fi
;;
"$CMD2") "$CMD2")
if [ "$CMD2" != "" ]; then if [ "$CMD2" != "" ]; then
Go ;; Go
fi fi
;;
"$CMD3") "$CMD3")
if [ "$CMD3" != "" ]; then if [ "$CMD3" != "" ]; then
Go ;; Go
fi fi
;;
"sudo") "sudo")
if [ "$SUDO_EXEC" == "yes" ]; then if [ "$SUDO_EXEC" == "yes" ]; then
if [[ "$SSH_ORIGINAL_COMMAND" == "sudo $RSYNC_EXECUTABLE"* ]]; then if [[ "$SSH_ORIGINAL_COMMAND" == "sudo $RSYNC_EXECUTABLE"* ]]; then
@ -65,20 +69,15 @@ case ${SSH_ORIGINAL_COMMAND%% *} in
Go Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo find"* ]]; then elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo find"* ]]; then
Go Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mkdir"* ]] elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mkdir"* ]]; then
then
Go Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo rm"* ]] elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo rm"* ]]; then
then
Go Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo echo"* ]] elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo echo"* ]]; then
then
Go Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo df"* ]] elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo df"* ]]; then
then
Go Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mv"* ]] elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mv"* ]]; then
then
Go Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD1"* ]]; then elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD1"* ]]; then
if [ "$CMD1" != "" ]; then if [ "$CMD1" != "" ]; then