Add a timeout on winexe call so the pre-backup commands cannot hang indefinitely. The version of timeout is only included on RHEL 5 because in EL6, coreutils provides one

tags/BackupPC-server-scripts-0.1.3-0.beta1
Daniel Berteaud 12 years ago
parent bb3a753f67
commit c4f6c63b5a
  1. 8
      BackupPC-server-scripts.spec
  2. 53
      scripts/timeout
  3. 7
      scripts/win-post-backup
  4. 7
      scripts/win-pre-backup

@ -35,7 +35,13 @@ Like pre-backup scripts for Windows boxes
# Install backup script # Install backup script
%{__mkdir_p} $RPM_BUILD_ROOT%{_bindir}/ %{__mkdir_p} $RPM_BUILD_ROOT%{_bindir}/
%{__install} -m 0755 scripts/* $RPM_BUILD_ROOT%{_bindir}/ %{__install} -m 0755 scripts/win-* $RPM_BUILD_ROOT%{_bindir}/
# coreutils doesn't provides a timeout command in EL5
# So include the bash one
%if 0%{?rhel} == 5
%{__install} -m 0755 scripts/timeout $RPM_BUILD_ROOT%{_bindir}/
%endif
# Install conf # Install conf
%{__mkdir_p} $RPM_BUILD_ROOT%{_sysconfdir}/BackupPC %{__mkdir_p} $RPM_BUILD_ROOT%{_sysconfdir}/BackupPC

@ -0,0 +1,53 @@
#Newsgroups: comp.unix.admin,comp.unix.solaris,comp.unix.shell
#From: gwc@root.co.uk (Geoff Clare)
#Subject: Re: timeout -t <sec> <unix command> (Re: How to give rsh a shorter timeout?)
#Message-ID: <EoBxrs.223@root.co.uk>
#Date: Fri, 13 Feb 1998 18:23:52 GMT
#
# Conversion to bash v2 syntax done by Chet Ramey <chet@po.cwru.edu
# UNTESTED
#
prog=${0##*/}
usage="usage: $prog [-signal] [timeout] [:interval] [+delay] [--] <command>"
SIG=-TERM # default signal sent to the process when the timer expires
timeout=60 # default timeout
interval=15 # default interval between checks if the process is still alive
delay=2 # default delay between posting the given signal and
# destroying the process (kill -KILL)
while :
do
case $1 in
--) shift; break ;;
-*) SIG=$1 ;;
[0-9]*) timeout=$1 ;;
:*) EXPR='..\(.*\)' ; interval=`expr x"$1" : "$EXPR"` ;;
+*) EXPR='..\(.*\)' ; delay=`expr x"$1" : "$EXPR"` ;;
*) break ;;
esac
shift
done
case $# in
0) echo "$prog: $usage" >&2 ; exit 2 ;;
esac
(
for t in $timeout $delay
do
while (( $t > $interval ))
do
sleep $interval
kill -0 $$ || exit
t=$(( $t - $interval ))
done
sleep $t
kill $SIG $$ && kill -0 $$ || exit
SIG=-KILL
done
) 2> /dev/null &
exec "$@"

@ -9,11 +9,14 @@ if [ ! -z $3 ]; then
PASS=$3 PASS=$3
fi fi
# Timeout after 5 minutes
TIMEOUT=300
BOX=$1 BOX=$1
if [[ ! -z $UNAME && ! -z $PASS ]]; then if [[ ! -z $UNAME && ! -z $PASS ]]; then
$WINEXE -s /dev/null -U $UNAME --password=$PASS //$BOX 'cmd /c echo '1' > c:\backuppc\wake.up' <&- /usr/bin/timeout $TIMEOUT $WINEXE -s /dev/null -U $UNAME --password=$PASS //$BOX 'cmd /c echo '1' > c:\backuppc\wake.up' <&-
else else
$WINEXE -s /dev/null --authentication-file=/etc/BackupPC/win.conf //$BOX 'cmd /c echo '1' > c:\backuppc\wake.up' <&- /usr/bin/timeout $TIMEOUT $WINEXE -s /dev/null --authentication-file=/etc/BackupPC/win.conf //$BOX 'cmd /c echo '1' > c:\backuppc\wake.up' <&-
fi fi
echo "Rsync and shadow copy unloaded" echo "Rsync and shadow copy unloaded"

@ -7,12 +7,15 @@ if [ ! -z $3 ]; then
PASS=$3 PASS=$3
fi fi
# Timeout after 5 minutes
TIMEOUT=300
BOX=$1 BOX=$1
if [[ ! -z $UNAME && ! -z $PASS ]]; then if [[ ! -z $UNAME && ! -z $PASS ]]; then
/usr/bin/winexe -s /dev/null --interactive=0 -U $UNAME --password=$PASS //$BOX 'cmd /c c:\backuppc\pre-exec.cmd' <&- || exit 255 /usr/bin/timeout $TIMEOUT /usr/bin/winexe -s /dev/null --interactive=0 -U $UNAME --password=$PASS //$BOX 'cmd /c c:\backuppc\pre-exec.cmd' <&- || exit 255
else else
/usr/bin/winexe -s /dev/null --interactive=0 --authentication-file=/etc/BackupPC/win.conf //$BOX 'cmd /c c:\backuppc\pre-exec.cmd' <&- || exit 255 /usr/bin/timeout $TIMEOUT /usr/bin/winexe -s /dev/null --interactive=0 --authentication-file=/etc/BackupPC/win.conf //$BOX 'cmd /c c:\backuppc\pre-exec.cmd' <&- || exit 255
fi fi
sleep 5 sleep 5
echo "Rsync and shadow copy loaded" echo "Rsync and shadow copy loaded"

Loading…
Cancel
Save