Minor portability improvements

This commit is contained in:
deajan 2013-10-12 19:12:15 +02:00
parent 6a96e92a11
commit 0d8a2fbb0c
3 changed files with 60 additions and 15 deletions

View File

@ -12,6 +12,8 @@
## Latest changelog
- Added local and remote OS detection
- Fixed ping arguments for FreeBSD compatibility
- Added MSYS (MinGW minimal system) bash compatibility under Windows
- Added check for /var/log directory
- Added check for shared memory directory

View File

@ -25,10 +25,8 @@ In case you don't work with one of these, it may also rotate backups for you.
Obackup can execute local and remote commands before and after backup execution, thus providing possibilites to handle snapshots (see https://github.com/deajan/zsnap for a zfs snapshot management script).
As of today, obackup has been tested successfully on RHEL / CentOS 5, CentOS 6, Debian 6.0.7 and Linux Mint 14
but should basically run on your favorite linux flavor. It relies on well known programs like rsync, ssh, mysqldump along with other great GNU coreutils.
Project is customizable, and one can easily modify its code as it weights only 1 KLOC. Obackup is distributed under BSD Licence which gives most freedom to include it in your own code.
As of today, obackup has been tested successfully on RHEL / CentOS 5, CentOS 6, Debian 6.0.7 and Linux Mint 14.
Currently, Obackup also runs on FreeBSD and Windows MSYS environment, altough it is not fully tested yet.
Feel free to drop me a mail for limited support in my free time.
@ -39,7 +37,8 @@ You may also clone this git which will maybe have some more recent build.
$ git clone git://github.com/deajan/obackup.git
$ chmod +x ./obackup.sh
Obackup needs to run with bash shell, using any other shell will most probably fail.
Once you have grabbed a copy of Obackup, just edit the config file with your favorite text editor to setup your environment and you're ready to run. A detailled documentation can be found in the DOCUMENTATION.md file.
You can run multiple instances of obackup scripts with different backup environments. Just create another configuration file, edit it's environment and you're ready to run concurrently.

View File

@ -3,7 +3,7 @@
###### Remote (or local) backup script for files & databases
###### (L) 2013 by Orsiris "Ozy" de Jong (www.netpower.fr)
OBACKUP_VERSION=1.84preRC3-MSYS-compatible
OBACKUP_BUILD=1010201301
OBACKUP_BUILD=1110201301
DEBUG=no
SCRIPT_PID=$$
@ -93,7 +93,7 @@ function TrapQuit
if type -p pkill > /dev/null 2>&1
then
pkill -TERM -P $$
elif [ "$OSTYPE" == "msys" ]
elif [ "$LOCAL_OS" == "msys" ]
then
## This is not really a clean way to get child process pids, especially the tail -n +2 which resolves a strange char apparition in msys bash
for pid in $(ps -a | awk '{$1=$1}$1' | awk '{print $1" "$2}' | grep " $$$" | awk '{print $1}' | tail -n +2)
@ -174,6 +174,7 @@ function CleanUp
{
if [ "$DEBUG" != "yes" ]
then
rm -f "$RUN_DIR/obackup_remote_os_$SCRIPT_PID"
rm -f "$RUN_DIR/obackup_dblist_$SCRIPT_PID"
rm -f "$RUN_DIR/obackup_local_sql_storage_$SCRIPT_PID"
rm -f "$RUN_DIR/obackup_local_file_storage_$SCRIPT_PID"
@ -283,12 +284,55 @@ function CheckEnvironment
fi
}
function GetOperatingSystem
{
LOCAL_OS_VAR=$(uname -spio)
if [ "$REMOTE_SYNC" == "yes" ]
then
eval "$SSH_CMD uname -spio > $RUN_DIR/obackup_remote_os_$SCRIPT_PID 2>&1 &"
REMOTE_OS_VAR=$(cat $RUN_DIR/obackup_remote_os_$SCRIPT_PID)
fi
case $LOCAL_OS_VAR in
"Linux"*)
LOCAL_OS="Linux"
;;
"FreeBSD"*)
LOCAL_OS="FreeBSD"
;;
"MINGW32"*)
LOCAL_OS="msys"
;;
*)
LogError "Running on >> $LOCAL_OS_VAR << not supported. Please report to the author."
exit 1
;;
esac
case $REMOTE_OS_VAR in
"Linux"*)
REMOTE_OS="Linux"
;;
"FreeBSD"*)
REMOTE_OS="FreeBSD"
;;
"MINGW32"*)
REMOTE_OS="msys"
;;
"")
;;
*)
LogError "Running on remote >> $REMOTE_OS_VAR << not supported. Please report to the author."
exit 1
esac
}
# Waits for pid $1 to complete. Will log an alert if $2 seconds exec time exceeded unless $2 equals 0. Will stop task and log alert if $3 seconds exec time exceeded.
function WaitForTaskCompletion
{
soft_alert=0
SECONDS_BEGIN=$SECONDS
if [ "$OSTYPE" == "msys" ]
if [ "$LOCAL_OS" == "msys" ]
then
PROCESS_TEST="ps -a | awk '{\$1=\$1}\$1' | awk '{print \$1}' | grep $1"
else
@ -534,11 +578,11 @@ function CheckConnectivityRemoteHost
{
if [ "$REMOTE_HOST_PING" != "no" ] && [ "$REMOTE_BACKUP" != "no" ]
then
if [ "$OSTYPE" == "msys" ]
if [ "$LOCAL_OS" == "msys" ]
then
ping $REMOTE_HOST -n 2 > /dev/null 2>&1
ping -n 2 $REMOTE_HOST > /dev/null 2>&1
else
ping $REMOTE_HOST -c 2 > /dev/null 2>&1
ping -c 2 $REMOTE_HOST > /dev/null 2>&1
fi
if [ $? != 0 ]
then
@ -557,11 +601,11 @@ function CheckConnectivity3rdPartyHosts
IFS=$' \t\n'
for i in $REMOTE_3RD_PARTY_HOSTS
do
if [ "$OSTYPE" == "msys" ]
if [ "$LOCAL_OS" == "msys" ]
then
ping $i -n 2 > /dev/null 2>&1
ping -n 2 $i > /dev/null 2>&1
else
ping $i -c 2 > /dev/null 2>&1
ping -c 2 $i > /dev/null 2>&1
fi
if [ $? != 0 ]
then
@ -1003,7 +1047,7 @@ function Init
MAIL_ALERT_MSG="Warning: Execution of obackup instance $BACKUP_ID (pid $SCRIPT_PID) as $LOCAL_USER@$LOCAL_HOST produced errors."
## If running Msys, find command of windows is used instead of msys one
if [ "$OSTYPE" == "msys" ]
if [ "$LOCAL_OS" == "msys" ]
then
FIND_CMD=$(dirname $BASH)/find
else