mirror of
https://github.com/deajan/obackup.git
synced 2025-02-05 19:03:50 +01:00
Minor portability improvements
This commit is contained in:
parent
6a96e92a11
commit
0d8a2fbb0c
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
## Latest changelog
|
## Latest changelog
|
||||||
|
|
||||||
|
- Added local and remote OS detection
|
||||||
|
- Fixed ping arguments for FreeBSD compatibility
|
||||||
- Added MSYS (MinGW minimal system) bash compatibility under Windows
|
- Added MSYS (MinGW minimal system) bash compatibility under Windows
|
||||||
- Added check for /var/log directory
|
- Added check for /var/log directory
|
||||||
- Added check for shared memory directory
|
- Added check for shared memory directory
|
||||||
|
@ -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).
|
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
|
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.
|
Currently, Obackup also runs on FreeBSD and Windows MSYS environment, altough it is not fully tested yet.
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
Feel free to drop me a mail for limited support in my free time.
|
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
|
$ git clone git://github.com/deajan/obackup.git
|
||||||
$ chmod +x ./obackup.sh
|
$ 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.
|
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.
|
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.
|
||||||
|
|
||||||
|
64
obackup.sh
64
obackup.sh
@ -3,7 +3,7 @@
|
|||||||
###### Remote (or local) backup script for files & databases
|
###### Remote (or local) backup script for files & databases
|
||||||
###### (L) 2013 by Orsiris "Ozy" de Jong (www.netpower.fr)
|
###### (L) 2013 by Orsiris "Ozy" de Jong (www.netpower.fr)
|
||||||
OBACKUP_VERSION=1.84preRC3-MSYS-compatible
|
OBACKUP_VERSION=1.84preRC3-MSYS-compatible
|
||||||
OBACKUP_BUILD=1010201301
|
OBACKUP_BUILD=1110201301
|
||||||
|
|
||||||
DEBUG=no
|
DEBUG=no
|
||||||
SCRIPT_PID=$$
|
SCRIPT_PID=$$
|
||||||
@ -93,7 +93,7 @@ function TrapQuit
|
|||||||
if type -p pkill > /dev/null 2>&1
|
if type -p pkill > /dev/null 2>&1
|
||||||
then
|
then
|
||||||
pkill -TERM -P $$
|
pkill -TERM -P $$
|
||||||
elif [ "$OSTYPE" == "msys" ]
|
elif [ "$LOCAL_OS" == "msys" ]
|
||||||
then
|
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
|
## 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)
|
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" ]
|
if [ "$DEBUG" != "yes" ]
|
||||||
then
|
then
|
||||||
|
rm -f "$RUN_DIR/obackup_remote_os_$SCRIPT_PID"
|
||||||
rm -f "$RUN_DIR/obackup_dblist_$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_sql_storage_$SCRIPT_PID"
|
||||||
rm -f "$RUN_DIR/obackup_local_file_storage_$SCRIPT_PID"
|
rm -f "$RUN_DIR/obackup_local_file_storage_$SCRIPT_PID"
|
||||||
@ -283,12 +284,55 @@ function CheckEnvironment
|
|||||||
fi
|
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.
|
# 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
|
function WaitForTaskCompletion
|
||||||
{
|
{
|
||||||
soft_alert=0
|
soft_alert=0
|
||||||
SECONDS_BEGIN=$SECONDS
|
SECONDS_BEGIN=$SECONDS
|
||||||
if [ "$OSTYPE" == "msys" ]
|
if [ "$LOCAL_OS" == "msys" ]
|
||||||
then
|
then
|
||||||
PROCESS_TEST="ps -a | awk '{\$1=\$1}\$1' | awk '{print \$1}' | grep $1"
|
PROCESS_TEST="ps -a | awk '{\$1=\$1}\$1' | awk '{print \$1}' | grep $1"
|
||||||
else
|
else
|
||||||
@ -534,11 +578,11 @@ function CheckConnectivityRemoteHost
|
|||||||
{
|
{
|
||||||
if [ "$REMOTE_HOST_PING" != "no" ] && [ "$REMOTE_BACKUP" != "no" ]
|
if [ "$REMOTE_HOST_PING" != "no" ] && [ "$REMOTE_BACKUP" != "no" ]
|
||||||
then
|
then
|
||||||
if [ "$OSTYPE" == "msys" ]
|
if [ "$LOCAL_OS" == "msys" ]
|
||||||
then
|
then
|
||||||
ping $REMOTE_HOST -n 2 > /dev/null 2>&1
|
ping -n 2 $REMOTE_HOST > /dev/null 2>&1
|
||||||
else
|
else
|
||||||
ping $REMOTE_HOST -c 2 > /dev/null 2>&1
|
ping -c 2 $REMOTE_HOST > /dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
if [ $? != 0 ]
|
if [ $? != 0 ]
|
||||||
then
|
then
|
||||||
@ -557,11 +601,11 @@ function CheckConnectivity3rdPartyHosts
|
|||||||
IFS=$' \t\n'
|
IFS=$' \t\n'
|
||||||
for i in $REMOTE_3RD_PARTY_HOSTS
|
for i in $REMOTE_3RD_PARTY_HOSTS
|
||||||
do
|
do
|
||||||
if [ "$OSTYPE" == "msys" ]
|
if [ "$LOCAL_OS" == "msys" ]
|
||||||
then
|
then
|
||||||
ping $i -n 2 > /dev/null 2>&1
|
ping -n 2 $i > /dev/null 2>&1
|
||||||
else
|
else
|
||||||
ping $i -c 2 > /dev/null 2>&1
|
ping -c 2 $i > /dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
if [ $? != 0 ]
|
if [ $? != 0 ]
|
||||||
then
|
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."
|
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 running Msys, find command of windows is used instead of msys one
|
||||||
if [ "$OSTYPE" == "msys" ]
|
if [ "$LOCAL_OS" == "msys" ]
|
||||||
then
|
then
|
||||||
FIND_CMD=$(dirname $BASH)/find
|
FIND_CMD=$(dirname $BASH)/find
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user