Updated ssh filter and obackup ssh command output logging.

This commit is contained in:
deajan 2013-06-23 22:53:47 +02:00
parent 9741cd3b9e
commit 9e4c2ebb21
3 changed files with 63 additions and 10 deletions

View File

@ -1,5 +1,8 @@
## Latest changelog ## Latest changelog
- Updated obackup to log failed ssh command results
- Updated ssh command filter to log failed commands
- Updated ssh command filter to accept personalized commands
- 23/06/2013 v 1.84 RC1 approaching - 23/06/2013 v 1.84 RC1 approaching
- Added ssh commands filter, updated documentation - Added ssh commands filter, updated documentation
- Rewrote local space check function - Rewrote local space check function

View File

@ -2,7 +2,8 @@
###### Remote (or local) backup script for files & databases ###### Remote (or local) backup script for files & databases
###### (L) 2013 by Ozy de Jong (www.badministrateur.com) ###### (L) 2013 by Ozy de Jong (www.badministrateur.com)
OBACKUP_VERSION=1.83 #### Build 2206201301 OBACKUP_VERSION=1.83
OBACKUP_BUILD=2306201301
DEBUG=no DEBUG=no
SCRIPT_PID=$$ SCRIPT_PID=$$
@ -300,8 +301,10 @@ function RunRemoteCommand
LogError "Running command [$1] failed." LogError "Running command [$1] failed."
fi fi
Log "Command output:" if [ -f /dev/shm/obackup_run_remote_$SCRIPT_PID ]
Log "$(cat /dev/shm/obackup_run_remote_$SCRIPT_PID)" then
Log "Command output: $(cat /dev/shm/obackup_run_remote_$SCRIPT_PID)"
fi
fi fi
} }
@ -537,6 +540,10 @@ function ListDatabases
Log "Listing databases succeeded." Log "Listing databases succeeded."
else else
LogError "Listing databases failed." LogError "Listing databases failed."
if [ -f /dev/shm/obackup_dblist_$SCRIPT_PID ]
then
LogError "Command output: $(cat /dev/shm/obackup_dblist_$SCRIPT_PID)"
fi
return $retval return $retval
fi fi
@ -663,6 +670,10 @@ function ListDirectories
if [ $retval != 0 ] if [ $retval != 0 ]
then then
LogError "Could not enumerate recursive directories in $i." LogError "Could not enumerate recursive directories in $i."
if [ -f /dev/shm/obackup_dirs_recurse_list_$SCRIPT_PID ]
then
LogError "Command output: $(cat /dev/shm/obackup_dirs_recurse_list_$SCRIPT_PID)"
fi
return 1 return 1
else else
Log "Listing of recursive directories succeeded for $i." Log "Listing of recursive directories succeeded for $i."
@ -733,6 +744,10 @@ function GetDirectoriesSize
if [ $retval != 0 ] if [ $retval != 0 ]
then then
LogError "Could not get files size." LogError "Could not get files size."
if [ -f /dev/shm/obackup_fsize_$SCRIPT_PID ]
then
LogError "Command output: $(cat /dev/shm/obackup_fsize_$SCRIPT_PID)"
fi
return 1 return 1
else else
Log "File size fetched successfully." Log "File size fetched successfully."
@ -992,7 +1007,7 @@ function Main
function Usage function Usage
{ {
echo "Obackup $OBACKUP_VERSION" echo "Obackup $OBACKUP_VERSION $OBACKUP_BUILD"
echo "" echo ""
echo "usage: obackup backup_name [--dry] [--silent]" echo "usage: obackup backup_name [--dry] [--silent]"
echo "" echo ""

View File

@ -1,11 +1,30 @@
#!/bin/bash #!/bin/bash
##### Obackup ssh command filter ##### Obackup ssh command filter build 2306201301
##### This script should be located in /usr/local/bin in the remote system that will be backed up
##### It will filter the commands that can be run remotely via ssh.
##### Please chmod 755 and chown root:root this file
## 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.
CMD1=
CMD2=
CMD3=
LOG_FILE=/var/log/obackup_ssh_filter.log
function Log
{
DATE=$(date)
if [ "$2" != "1" ]
then
echo "$1"
fi
echo "$DATE - $1" >> $LOG_FILE
}
function Go function Go
{ {
@ -21,6 +40,12 @@ case ${SSH_ORIGINAL_COMMAND%% *} in
Go ;; Go ;;
"du") "du")
Go ;; Go ;;
"$CMD1")
Go ;;
"$CMD2")
Go ;;
"$CMD3")
Go ;;
"sudo") "sudo")
if [ "$SUDO_EXEC" == "yes" ] if [ "$SUDO_EXEC" == "yes" ]
then then
@ -31,17 +56,27 @@ case ${SSH_ORIGINAL_COMMAND%% *} in
then then
Go Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo find"* ]] elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo find"* ]]
then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD1"* ]]
then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD2"* ]]
then
Go
elif [[ "$SSH_ORIGINAL_COMMAND" == "sudo $CMD3"* ]]
then then
Go Go
else else
echo "Sudo command not allowed." Log "Sudo command not allowed."
Log "$SSH_ORIGINAL_COMMAND" 1
fi fi
else else
echo "Sudo command not enabled." Log "Sudo command not enabled."
Log "$SSH_ORIGINAL_COMMAND" 1
fi fi
;; ;;
*) *)
echo "Not allowed." Log "Not allowed."
Log "$SSH_ORIGINAL_COMMAND" 1
esac esac