Fixed df commands on Busybox.

Also replaced some spaces with tabs, as per the general coding style,
and replaced the remaining xargs instances.
This commit is contained in:
koroshiya 2015-11-10 12:58:40 +11:00
parent 4b43fd4fb1
commit 7d3c0e21d8
1 changed files with 101 additions and 59 deletions

View File

@ -923,7 +923,15 @@ function _CheckDiskSpaceLocal {
Logger "Checking minimum disk space in [$replica_path]." "NOTICE"
local initiator_space=$(df -P "$replica_path" | tail -1 | awk '{print $4}')
local isbusybox=$(ls --help 2>&1 | grep BusyBox)
local pFlag=""
if [[ $isbusybox != *"BusyBox"* ]]; then
pFlag="-P "
fi
local initiator_space=$(df $pFlag"$replica_path" | tail -1 | awk '{print $4}')
initiator_space=$(GetSpace "$initiator_space")
if [ $initiator_space -lt $MINIMUM_SPACE ]; then
Logger "There is not enough free space on initiator [$initiator_space KB]." "WARN"
fi
@ -938,7 +946,13 @@ function _CheckDiskSpaceRemote {
CheckConnectivity3rdPartyHosts
CheckConnectivityRemoteHost
cmd=$SSH_CMD' "'$COMMAND_SUDO' df -P \"'$replica_path'\"" > "'$RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID'" 2>&1'
local isbusybox=$(echo "ls --help 2>&1 | grep BusyBox" | $SSH_CMD)
local pFlag=""
if [[ $isbusybox != *"BusyBox"* ]]; then
pFlag="-P "
fi
cmd=$SSH_CMD' "'$COMMAND_SUDO' df $pFlag\"'$replica_path'\"" > "'$RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID'" 2>&1'
Logger "cmd: $cmd" "DEBUG"
eval "$cmd" &
WaitForTaskCompletion $! 0 1800 $FUNCNAME
@ -947,6 +961,8 @@ function _CheckDiskSpaceRemote {
Logger "Command output:\n$(cat $RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID)" "NOTICE"
else
local target_space=$(cat $RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID | tail -1 | awk '{print $4}')
target_space=$(GetSpace "$target_space")
if [ $target_space -lt $MINIMUM_SPACE ]; then
Logger "There is not enough free space on target [$replica_path]." "WARN"
fi
@ -1751,13 +1767,12 @@ function _SoftDeleteLocal {
Logger "Removing files older than $change_time days on $replica_type replica." "NOTICE"
fi
if [ $_VERBOSE -eq 1 ]; then
# Cannot launch log function from xargs, ugly hack
$FIND_CMD "$replica_deletion_path/" -type f -mtime +$change_time -print0 | while read filename; do Logger "Command output:\nWill delete file $filename" "NOTICE"; done
$FIND_CMD "$replica_deletion_path/" -type d -empty -mtime +$change_time -print0 | while read filename; do Logger "Command output:\nWill delete directory $filename" "NOTICE"; done
fi
if [ $_DRYRUN -ne 1 ]; then
$FIND_CMD "$replica_deletion_path/" -type f -mtime +$change_time -print0 | while read filename; do rm -f "$filename" > "$RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID" 2>&1 &; done
$FIND_CMD "$replica_deletion_path/" -type d -empty -mtime +$change_time -print0 | while read filename; do rm -rf "$filename" > "$RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID" 2>&1 &; done
$FIND_CMD "$replica_deletion_path/" -type f -mtime +$change_time -print0 | while read filename; do rm -f "$filename" > "$RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID" 2>&1 & done
$FIND_CMD "$replica_deletion_path/" -type d -empty -mtime +$change_time -print0 | while read filename; do rm -rf "$filename" > "$RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID" 2>&1 & done
else
Dummy &
fi
@ -1790,15 +1805,14 @@ function _SoftDeleteRemote {
fi
if [ $_VERBOSE -eq 1 ]; then
# Cannot launch log function from xargs, ugly hack
cmd=$SSH_CMD' "if [ -w \"'$replica_deletion_path'\" ]; then '$COMMAND_SUDO' '$REMOTE_FIND_CMD' \"'$replica_deletion_path'/\" -type f -mtime +'$change_time' -print0 | xargs -0 -I {} echo Will delete file {} && '$REMOTE_FIND_CMD' \"'$replica_deletion_path'/\" -type d -empty -mtime '$change_time' -print0 | xargs -0 -I {} echo Will delete directory {}; fi" > "'$RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID'" 2>&1'
cmd=$SSH_CMD' "if [ -w \"'$replica_deletion_path'\" ]; then '$COMMAND_SUDO' '$REMOTE_FIND_CMD' \"'$replica_deletion_path'/\" -type f -mtime +'$change_time' -print0 | while read filename; do echo Will delete file $filename; done && '$REMOTE_FIND_CMD' \"'$replica_deletion_path'/\" -type d -empty -mtime '$change_time' -print0 | while read filename; do echo Will delete directory $filename; done; fi" > "'$RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID'" 2>&1'
Logger "cmd: $cmd" "DEBUG"
eval "$cmd" &
Logger "Command output:\n$(cat $RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID)" "NOTICE"
fi
if [ $_DRYRUN -ne 1 ]; then
cmd=$SSH_CMD' "if [ -w \"'$replica_deletion_path'\" ]; then '$COMMAND_SUDO' '$REMOTE_FIND_CMD' \"'$replica_deletion_path'/\" -type f -mtime +'$change_time' -print0 | xargs -0 -I {} rm -f \"{}\" && '$REMOTE_FIND_CMD' \"'$replica_deletion_path'/\" -type d -empty -mtime '$change_time' -print0 | xargs -0 -I {} rm -rf \"{}\"; fi" > "'$RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID'" 2>&1'
cmd=$SSH_CMD' "if [ -w \"'$replica_deletion_path'\" ]; then '$COMMAND_SUDO' '$REMOTE_FIND_CMD' \"'$replica_deletion_path'/\" -type f -mtime +'$change_time' -print0 | while read filename; do rm -f \"$filename\"; done && '$REMOTE_FIND_CMD' \"'$replica_deletion_path'/\" -type d -empty -mtime '$change_time' -print0 | while read filename; do rm -rf \"$filename\"; done; fi" > "'$RUN_DIR/osync.$FUNCNAME.$SCRIPT_PID'" 2>&1'
Logger "cmd: $cmd" "DEBUG"
eval "$cmd" &
else
@ -2200,6 +2214,34 @@ function SyncOnChanges {
}
#Floating point sizes may not be 100% accurate, as Busybox may round the number
function GetSpace {
__CheckArguments 0 $# $FUNCNAME "$*" #__WITH_PARANOIA_DEBUG
local num=$1
local unit="${num: -1}"
local size="${num:0:-1}"
case $unit in
"K")
awk -v size="$size" 'BEGIN{printf "%.0f", size * 1024}'
;;
"M")
awk -v size="$size" 'BEGIN{printf "%.0f", size * 1024 * 1024}'
;;
"G")
awk -v size="$size" 'BEGIN{printf "%.0f", size * 1024 * 1024 * 1024}'
;;
"T")
awk -v size="$size" 'BEGIN{printf "%.0f", size * 1024 * 1024 * 1024 * 1024}'
;;
*)
echo $num
;;
esac
return 1
}
# Comand line argument flags
_DRYRUN=0
_SILENT=0