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

View File

@ -3,10 +3,10 @@
PROGRAM=obackup
PROGRAM_BINARY=$PROGRAM".sh"
PROGRAM_BATCH=$PROGRAM"-batch.sh"
SCRIPT_BUILD=2015102701
SCRIPT_BUILD=2016031401
## 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
CONF_DIR=/etc/$PROGRAM
@ -30,48 +30,48 @@ else
echo "Config directory [$CONF_DIR] exists."
fi
if [ -f ./sync.conf ]; then
cp ./sync.conf /etc/$PROGRAM/sync.conf.example
if [ -f "./sync.conf" ]; then
cp "./sync.conf" "/etc/$PROGRAM/sync.conf.example"
fi
if [ -f ./host_backup.conf ]; then
cp ./host_backup.conf /etc/$PROGRAM/host_backup.conf.example
if [ -f "./host_backup.conf" ]; then
cp "./host_backup.conf" "/etc/$PROGRAM/host_backup.conf.example"
fi
if [ -f ./exlude.list.example ]; then
cp ./exclude.list.example /etc/$PROGRAM
if [ -f "./exlude.list.example" ]; then
cp "./exclude.list.example" "/etc/$PROGRAM"
fi
cp ./$PROGRAM_BINARY "$BIN_DIR"
cp "./$PROGRAM_BINARY" "$BIN_DIR"
if [ $? != 0 ]; then
echo "Cannot copy $PROGRAM_BINARY to [$BIN_DIR]."
else
echo "Copied $PROGRAM_BINARY to [$BIN_DIR]."
fi
cp ./$PROGRAM_BATCH /usr/local/bin
cp "./$PROGRAM_BATCH" "/usr/local/bin"
if [ $? != 0 ]; then
echo "Cannot copy $PROGRAM_BATCH to [$BIN_DIR]."
else
echo "Copied $PROGRAM_BATCH to [$BIN_DIR]."
fi
cp ./ssh_filter.sh /usr/local/bin
cp "./ssh_filter.sh" "/usr/local/bin"
if [ $? != 0 ]; then
echo "Cannot copy ssh_filter.sh to [$BIN_DIR]."
else
echo "Copied ssh_filter.sh to [$BIN_DIR]."
fi
if [ -f ./osync-srv ]; then
cp ./osync-srv "$SERVICE_DIR"
if [ -f "./osync-srv" ]; then
cp "./osync-srv" "$SERVICE_DIR"
if [ $? != 0 ]; then
echo "Cannot copy osync-srv to [$SERVICE_DIR]."
else
echo "Created osync-srv service in [$SERVICE_DIR]."
chmod 755 /etc/init.d/osync-srv
chmod 755 "/etc/init.d/osync-srv"
fi
fi
chmod 755 /usr/local/bin/$PROGRAM_BINARY
chmod 755 /usr/local/bin/$PROGRAM_BATCH
chmod 755 /usr/local/bin/ssh_filter.sh
chown root:root /usr/local/bin/ssh_filter.sh
chmod 755 "/usr/local/bin/$PROGRAM_BINARY"
chmod 755 "/usr/local/bin/$PROGRAM_BATCH"
chmod 755 "/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
SUBPROGRAM=obackup
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"
PROGRAM_BUILD=2015111801
PROGRAM_BUILD=2016031301
## Runs an osync /obackup instance for every conf file found
## If an instance fails, run it again if time permits
@ -43,10 +43,8 @@ function Logger {
if [ "$level" == "CRITICAL" ]; then
_logger "$prefix\e[41m$value\e[0m"
ERROR_ALERT=1
elif [ "$level" == "ERROR" ]; then
_logger "$prefix\e[91m$value\e[0m"
ERROR_ALERT=1
elif [ "$level" == "WARN" ]; then
_logger "$prefix\e[93m$value\e[0m"
elif [ "$level" == "NOTICE" ]; then
@ -85,7 +83,7 @@ function CheckEnvironment {
function Batch {
## Get list of .conf files
for i in $(ls $CONF_FILE_PATH/*.conf)
for i in $CONF_FILE_PATH/*.conf
do
if [ "$RUN" == "" ]; then
RUN="$i"
@ -104,7 +102,7 @@ function Batch {
wait $!
if [ $? != 0 ]; then
Logger "Run instance $(basename $i) failed" "ERROR"
if [ "RUN_AGAIN" == "" ]; then
if [ "$RUN_AGAIN" == "" ]; then
RUN_AGAIN="$i"
else
RUN_AGAIN=$RUN_AGAIN" $i"
@ -138,23 +136,17 @@ function Usage {
exit 128
}
_SILENT=0
_DRY=0
_VERBOSE=0
opts=""
for i in "$@"
do
case $i in
--silent)
_SILENT=1
opts=$opts" --silent"
;;
--dry)
_DRY=1
opts=$opts" --dry"
;;
--verbose)
_VERBOSE=1
opts=$opts" --verbose"
;;
--no-maxtime)

View File

@ -1,21 +1,22 @@
#!/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
##### It will filter the commands that can be run remotely via ssh.
##### Please chmod 755 and chown root:root this file
##### Obackup needed commands: rsync find du mysql mysqldump (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.
SUDO_EXEC=yes
## Paranoia option. Don't change this unless you read the documentation and still feel concerned about security issues.
RSYNC_EXECUTABLE=rsync
## Enable other commands, useful for remote execution hooks like remotely creating snapshots.
CMD1=
CMD2=
CMD3=
CMD1=""
CMD2=""
CMD3=""
LOG_FILE=~/.ssh/ssh_filter.log
@ -25,7 +26,7 @@ function Log {
}
function Go {
eval $SSH_ORIGINAL_COMMAND
eval "$SSH_ORIGINAL_COMMAND"
}
case ${SSH_ORIGINAL_COMMAND%% *} in
@ -47,16 +48,19 @@ case ${SSH_ORIGINAL_COMMAND%% *} in
Go ;;
"$CMD1")
if [ "$CMD1" != "" ]; then
Go ;;
Go
fi
;;
"$CMD2")
if [ "$CMD2" != "" ]; then
Go ;;
Go
fi
;;
"$CMD3")
if [ "$CMD3" != "" ]; then
Go ;;
Go
fi
;;
"sudo")
if [ "$SUDO_EXEC" == "yes" ]; then
if [[ "$SSH_ORIGINAL_COMMAND" == "sudo $RSYNC_EXECUTABLE"* ]]; then
@ -65,20 +69,15 @@ case ${SSH_ORIGINAL_COMMAND%% *} in
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo find"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mkdir"* ]]
then
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mkdir"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo rm"* ]]
then
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo rm"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo echo"* ]]
then
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo echo"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo df"* ]]
then
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo df"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mv"* ]]
then
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo mv"* ]]; then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD1"* ]]; then
if [ "$CMD1" != "" ]; then