1
0
mirror of https://github.com/deajan/obackup.git synced 2026-02-12 01:50:55 +01:00

8 Commits

Author SHA1 Message Date
deajan
775bd031ef Rebuilt targets 2016-08-16 23:24:54 +02:00
deajan
47e2b54117 Bumped version 2016-08-16 23:24:29 +02:00
deajan
52262f0cfc Updated changelog 2016-08-16 23:23:37 +02:00
deajan
a70b167c42 Fixed double RunAfterHook execution 2016-08-16 23:22:38 +02:00
Orsiris de Jong
41a903e74f Update README.md 2016-08-09 15:42:35 +02:00
Orsiris de Jong
7f52618b77 Update CHANGELOG.md 2016-08-08 00:28:57 +02:00
deajan
e0ebd12742 Fixed wrong ofunctions ver 2016-08-07 23:21:58 +02:00
deajan
63b82025ff Rebuilt target 2016-08-06 16:18:43 +02:00
7 changed files with 50 additions and 195 deletions

View File

@@ -4,13 +4,15 @@ KNOWN ISSUES
- Backup size check does not honor rsync exclude patterns
- Bandwidth parameter is ignored for SQL backups
- Missing symlink support when run from MSYS environment
- Mysqldump errors aren't taken in account
CHANGELOG
---------
README: FreeBSD execution needs mailer (not found), sudo missing, bash needed, sed missing (see if StripQuotes mandatory)
XX xxx 2016: obackup v2.0.1 released
- Fixed double RunAfterHook launch
06 Aug 2016: obackup v2.0 released
- Made logging begin before remote checks for sanity purposes
- RunAfterCommands can get executed when trapquit

View File

@@ -34,7 +34,7 @@ You may disable this behavior in the config file.
You can download the latest obackup script from authors website.
You may also clone the following git which will maybe have some more recent builds.
$ git clone -b "v2.0" git://github.com/deajan/obackup.git
$ git clone -b "v2.0-maint" git://github.com/deajan/obackup.git
$ cd obackup
$ ./install.sh

View File

@@ -4,11 +4,11 @@
PROGRAM="obackup"
AUTHOR="(C) 2013-2016 by Orsiris de Jong"
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
PROGRAM_VERSION=2.0
PROGRAM_BUILD=2016080601
PROGRAM_VERSION=2.0.1
PROGRAM_BUILD=2016081601
IS_STABLE=yes
## FUNC_BUILD=2016072703
## FUNC_BUILD=2016071902-b
## 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
@@ -48,7 +48,7 @@ fi #__WITH_PARANOIA_DEBUG
## allow debugging from command line with _DEBUG=yes
if [ ! "$_DEBUG" == "yes" ]; then
_DEBUG=no
SLEEP_TIME=.001 # Tested under linux and FreeBSD bash, #TODO tests on cygwin / msys
SLEEP_TIME=.1
_VERBOSE=0
else
SLEEP_TIME=1
@@ -730,41 +730,13 @@ function GetRemoteOS {
fi
}
function WaitForPids {
# Takes a list of pids separated by space as argument, and waits until all pids are finished
local errors=0
while [ "$#" -gt 0 ]; do
for pid in "$@"; do
shift
if kill -0 "$pid" > /dev/null 2>&1; then
Logger "[$pid] is alive." "DEBUG"
set -- "$@" "$pid"
else
wait "$pid"
result=$?
if [ $result -eq 0 ]; then
Logger "[$pid] exited okay with [$result]" "DEBUG"
else
errors=$((errors+1))
Logger "[$pid] exited with bad status [$result]." "WARN"
fi
fi
done
sleep $SLEEP_TIME
done
return $errors
}
function WaitForTaskCompletion {
local pids="${1}" # list of pids to wait for, separated by a semicolon
local pid="${1}" # pid to wait for
local soft_max_time="${2}" # If program with pid $pid takes longer than $soft_max_time seconds, will log a warning, unless $soft_max_time equals 0.
local hard_max_time="${3}" # If program with pid $pid takes longer than $hard_max_time seconds, will stop execution, unless $hard_max_time equals 0.
local caller_name="${4}" # Who called this function
local should_exit="${5}" # If true, the function exits on failure
Logger "${FUNCNAME[0]} called by [$caller_name]." "PARANOIA_DEBUG" #__WITH_PARANOIA_DEBUG
#__CheckArguments 4 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
__CheckArguments 4 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
local soft_alert=0 # Does a soft alert need to be triggered, if yes, send an alert once
local log_ttime=0 # local time instance for comparaison
@@ -774,56 +746,7 @@ function WaitForTaskCompletion {
local retval=0 # return value of monitored pid process
local pid
local new_pids
local result
IFS=';' read -r -a pidarray <<< "$pids"
while [ ${#pidarray[@]} -gt 0 ]; do
newarray=""
for index in ${!pidarray[@]}; do
pid="${pidarray[index]}"
echo "run for $pid"
if kill -0 $pid > /dev/null 2>&1; then
echo "pid [$pid] is running."
newarray+=$pid
else
wait "$pid"
result=$?
echo $result
if [ $result -eq 0 ]; then
echo "pid [$pid] is finished with exit code 0."
else
echo "pid [$pid] is finished with exit code $result."
fi
fi
done
pidarray=$newarray
sleep .05
done
}
sleep 1 &
pids=$!
sleep 5 &
pids="$pids;$!"
echo "Waiting for pid $pids"
#sleep 5 &
#pids="$pids;$!"
WaitForTaskCompletion $pids 0 0 "caller" 1
echo "done"
exit
function old {
#TODO: test on FreeBSD, MacOS X and msys / cygwin
while kill -0 "$pid" > /dev/null 2>&1
while eval "$PROCESS_TEST_CMD" > /dev/null
do
Spinner
exec_time=$(($SECONDS - $seconds_begin))
@@ -875,8 +798,7 @@ function WaitForCompletion {
local retval=0 # return value of monitored pid process
#TODO: test on FreeBSD, MacOS X and msys / cygwin
while kill -0 "$pid" > /dev/null 2>&1
while eval "$PROCESS_TEST_CMD" > /dev/null
do
Spinner
if [ $((($SECONDS + 1) % $KEEP_LOGGING)) -eq 0 ]; then
@@ -1120,8 +1042,6 @@ function RsyncPatternsFromAdd {
local pattern_from="${2}"
__CheckArguments 2 $# ${FUNCNAME[0]} "$@" #__WITH_PARANOIA_DEBUG
local pattern_from=
## Check if the exclude list has a full path, and if not, add the config file path if there is one
if [ "$(basename $pattern_from)" == "$pattern_from" ]; then
pattern_from="$(dirname $CONFIG_FILE)/$pattern_from"
@@ -1290,7 +1210,6 @@ function InitLocalOSSettings {
FIND_CMD=$(dirname $BASH)/find
# PROCESS_TEST_CMD assumes there is a variable $pid
# Tested on MSYS and cygwin
#TODO: remove PROCESS_TEST_CMD if kill -0 works
PROCESS_TEST_CMD='ps -a | awk "{\$1=\$1}\$1" | awk "{print \$1}" | grep $pid'
PING_CMD='$SYSTEMROOT\system32\ping -n 2'
else
@@ -2724,4 +2643,3 @@ fi
RunBeforeHook
Main
RunAfterHook

View File

@@ -1,26 +1,38 @@
#!/usr/bin/env bash
## Merges ofunctions.sh and n_osync.sh into osync.sh
## MERGE 2016080601
## Merges ofunctions.sh and n_program.sh into program.sh
## Adds installer
PROGRAM=obackup
VERSION=$(grep "PROGRAM_VERSION=" n_$PROGRAM.sh)
VERSION=${VERSION#*=}
FUNC_PATH=/home/git/common
PARANOIA_DEBUG_LINE="__WITH_PARANOIA_DEBUG"
PARANOIA_DEBUG_BEGIN="#__BEGIN_WITH_PARANOIA_DEBUG"
PARANOIA_DEBUG_END="#__END_WITH_PARANOIA_DEBUG"
MINIMUM_FUNCTION_BEGIN="#### MINIMAL-FUNCTION-SET BEGIN ####"
MINIMUM_FUNCTION_END="#### MINIMAL-FUNCTION-SET END ####"
function Unexpand {
unexpand n_$PROGRAM.sh > tmp_$PROGRAM.sh
}
function Merge {
function MergeAll {
sed "/source \"\.\/ofunctions.sh\"/r /home/git/common/ofunctions.sh" tmp_$PROGRAM.sh | grep -v 'source "./ofunctions.sh"' > debug_$PROGRAM.sh
sed "/source \"\.\/ofunctions.sh\"/r ofunctions.sh" tmp_$PROGRAM.sh | grep -v 'source "./ofunctions.sh"' > debug_$PROGRAM.sh
chmod +x debug_$PROGRAM.sh
}
function MergeMinimum {
sed -n "/$MINIMUM_FUNCTION_BEGIN/,/$MINIMUM_FUNCTION_END/p" ofunctions.sh > tmp_minimal.sh
sed "/source \"\.\/ofunctions.sh\"/r tmp_minimal.sh" tmp_$PROGRAM.sh | grep -v 'source "./ofunctions.sh"' | grep -v "$PARANOIA_DEBUG_LINE" > debug_$PROGRAM.sh
rm -f tmp_minimal.sh
chmod +x debug_$PROGRAM.sh
}
function CleanDebug {
# sed explanation
@@ -38,16 +50,22 @@ function CleanDebug {
}
function CopyCommons {
sed "s/\[prgname\]/$PROGRAM/g" /home/git/common/common_install.sh > ../tmp_install.sh
sed "s/\[prgname\]/$PROGRAM/g" common_install.sh > ../tmp_install.sh
sed "s/\[version\]/$VERSION/g" ../tmp_install.sh > ../install.sh
sed "s/\[prgname\]/$PROGRAM/g" /home/git/common/common_batch.sh > ../$PROGRAM-batch.sh
if [ -f "common_batch.sh" ]; then
sed "s/\[prgname\]/$PROGRAM/g" common_batch.sh > ../$PROGRAM-batch.sh
fi
chmod +x ../install.sh
chmod +x ../obackup-batch.sh
chmod +x ../$PROGRAM-batch.sh
rm -f ../tmp_install.sh
}
Unexpand
Merge
if [ "$PROGRAM" == "osync" ] || [ "$PROGRAM" == "obackup" ]; then
MergeAll
else
MergeMinimum
fi
CleanDebug
rm -f tmp_$PROGRAM.sh
rm -f ../tmp_install.sh
CopyCommons
rm -f tmp_$PROGRAM.sh

View File

@@ -4,8 +4,8 @@
PROGRAM="obackup"
AUTHOR="(C) 2013-2016 by Orsiris de Jong"
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
PROGRAM_VERSION=2.0
PROGRAM_BUILD=2016080601
PROGRAM_VERSION=2.0.1
PROGRAM_BUILD=2016081601
IS_STABLE=yes
source "./ofunctions.sh"
@@ -1397,4 +1397,3 @@ fi
RunBeforeHook
Main
RunAfterHook

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash
PROGRAM=obackup
PROGRAM_VERSION=2.0-RC1
PROGRAM_VERSION=2.0.1
PROGRAM_BINARY=$PROGRAM".sh"
PROGRAM_BATCH=$PROGRAM"-batch.sh"
SCRIPT_BUILD=2016052601

View File

@@ -4,11 +4,11 @@
PROGRAM="obackup"
AUTHOR="(C) 2013-2016 by Orsiris de Jong"
CONTACT="http://www.netpower.fr/obackup - ozy@netpower.fr"
PROGRAM_VERSION=2.0
PROGRAM_BUILD=2016080601
PROGRAM_VERSION=2.0.1
PROGRAM_BUILD=2016081601
IS_STABLE=yes
## FUNC_BUILD=2016072703
## FUNC_BUILD=2016071902-b
## 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
@@ -44,7 +44,7 @@ WARN_ALERT=0
## allow debugging from command line with _DEBUG=yes
if [ ! "$_DEBUG" == "yes" ]; then
_DEBUG=no
SLEEP_TIME=.001 # Tested under linux and FreeBSD bash, #TODO tests on cygwin / msys
SLEEP_TIME=.1
_VERBOSE=0
else
SLEEP_TIME=1
@@ -713,39 +713,11 @@ function GetRemoteOS {
fi
}
function WaitForPids {
# Takes a list of pids separated by space as argument, and waits until all pids are finished
local errors=0
while [ "$#" -gt 0 ]; do
for pid in "$@"; do
shift
if kill -0 "$pid" > /dev/null 2>&1; then
Logger "[$pid] is alive." "DEBUG"
set -- "$@" "$pid"
else
wait "$pid"
result=$?
if [ $result -eq 0 ]; then
Logger "[$pid] exited okay with [$result]" "DEBUG"
else
errors=$((errors+1))
Logger "[$pid] exited with bad status [$result]." "WARN"
fi
fi
done
sleep $SLEEP_TIME
done
return $errors
}
function WaitForTaskCompletion {
local pids="${1}" # list of pids to wait for, separated by a semicolon
local pid="${1}" # pid to wait for
local soft_max_time="${2}" # If program with pid $pid takes longer than $soft_max_time seconds, will log a warning, unless $soft_max_time equals 0.
local hard_max_time="${3}" # If program with pid $pid takes longer than $hard_max_time seconds, will stop execution, unless $hard_max_time equals 0.
local caller_name="${4}" # Who called this function
local should_exit="${5}" # If true, the function exits on failure
local soft_alert=0 # Does a soft alert need to be triggered, if yes, send an alert once
local log_ttime=0 # local time instance for comparaison
@@ -755,56 +727,7 @@ function WaitForTaskCompletion {
local retval=0 # return value of monitored pid process
local pid
local new_pids
local result
IFS=';' read -r -a pidarray <<< "$pids"
while [ ${#pidarray[@]} -gt 0 ]; do
newarray=""
for index in ${!pidarray[@]}; do
pid="${pidarray[index]}"
echo "run for $pid"
if kill -0 $pid > /dev/null 2>&1; then
echo "pid [$pid] is running."
newarray+=$pid
else
wait "$pid"
result=$?
echo $result
if [ $result -eq 0 ]; then
echo "pid [$pid] is finished with exit code 0."
else
echo "pid [$pid] is finished with exit code $result."
fi
fi
done
pidarray=$newarray
sleep .05
done
}
sleep 1 &
pids=$!
sleep 5 &
pids="$pids;$!"
echo "Waiting for pid $pids"
#sleep 5 &
#pids="$pids;$!"
WaitForTaskCompletion $pids 0 0 "caller" 1
echo "done"
exit
function old {
#TODO: test on FreeBSD, MacOS X and msys / cygwin
while kill -0 "$pid" > /dev/null 2>&1
while eval "$PROCESS_TEST_CMD" > /dev/null
do
Spinner
exec_time=$(($SECONDS - $seconds_begin))
@@ -853,8 +776,7 @@ function WaitForCompletion {
local retval=0 # return value of monitored pid process
#TODO: test on FreeBSD, MacOS X and msys / cygwin
while kill -0 "$pid" > /dev/null 2>&1
while eval "$PROCESS_TEST_CMD" > /dev/null
do
Spinner
if [ $((($SECONDS + 1) % $KEEP_LOGGING)) -eq 0 ]; then
@@ -1051,8 +973,6 @@ function RsyncPatternsFromAdd {
local pattern_type="${1}"
local pattern_from="${2}"
local pattern_from=
## Check if the exclude list has a full path, and if not, add the config file path if there is one
if [ "$(basename $pattern_from)" == "$pattern_from" ]; then
pattern_from="$(dirname $CONFIG_FILE)/$pattern_from"
@@ -1217,7 +1137,6 @@ function InitLocalOSSettings {
FIND_CMD=$(dirname $BASH)/find
# PROCESS_TEST_CMD assumes there is a variable $pid
# Tested on MSYS and cygwin
#TODO: remove PROCESS_TEST_CMD if kill -0 works
PROCESS_TEST_CMD='ps -a | awk "{\$1=\$1}\$1" | awk "{print \$1}" | grep $pid'
PING_CMD='$SYSTEMROOT\system32\ping -n 2'
else
@@ -2612,4 +2531,3 @@ fi
RunBeforeHook
Main
RunAfterHook