Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (2) </ 1 [2] >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Improving DSL fallover recover, My suggestion< Next Oldest | Next Newest >
WDef Offline





Group: Members
Posts: 798
Joined: Sep. 2005
Posted: July 09 2006,13:02 QUOTE

Here's some rough notes towards implementing the above, *untested*.  (I have no idea as yet, for example, about possible effects of calling shutdown -c )

Function check_sufficient_space could be called in filetool.sh right after 'if [ $1 == "backup" ] ; then'

Code Sample
check_sufficient_space(){

TARERR=/tmp/tarerr.$$

tar -C / -T $HOME/.filetool.lst -X $HOME/.xfiletool.lst --totals -cf - 1>/dev/null 2>${TARERR}

ARCHSIZE=$(awk '/Total bytes written/{print $4}' ${TARERR} )
[ -z "$ARCHSIZE" ] && echo "Nothing to backup?"
rm -f ${TARERR}

(( ARCHK=ARCHSIZE/1000 )) # want kB
(( ARCHSIZEK = ARCHK + 1 )) # round upwards

FREESPACE=$(df -k $MOUNTPOINT | awk '/dev/{print $4}')

echo "Max upper bound on backup size = $ARCHSIZEK kB"
echo "Available space on $MOUNTPOINT = $FREESPACE kB"

if [ "$ARCHSIZEK" -ge "$FREESPACE" ]; then
   # Needs a flua gui or something here
   echo "WARNING: there may be insufficient space on $MOUNTPOINT for backup."
  while true; do
  echo "Proceed anyway? (y/n)"
  read ANS
     case $ANS in
     n|N|n*|N*) echo "Aborting backup/shutdown .."
        sudo shutdown -c
        if [ $MOUNTED == "no" ]; then
              sudo umount $MOUNTPOINT
        fi
        exit 1;;
     y|Y|y*|Y*) break;;
     *) echo "Invalid response.";;
     esac
  done
fi
}
Back to top
Profile PM 
WDef Offline





Group: Members
Posts: 798
Joined: Sep. 2005
Posted: July 09 2006,20:57 QUOTE

After a little testing, first problem:

'shutdown -c' doesn't abort the shutdown running from this script, it can't find a pid for the running shutdown.  One for tomorrow.
Back to top
Profile PM 
WDef Offline





Group: Members
Posts: 798
Joined: Sep. 2005
Posted: July 13 2006,10:35 QUOTE

'shutdown' isn't running by that stage, init 0 has already been called (doh). Can get out of shutdown by changing runlevels (see below).

A flag could be set somewhere (eg /etc/sysconfig) to prevent a restore from occuring when runlevel 5 starts up again, otherwise some files which were changed during the session might get overwritten by the restore.

Function call:
Code Sample
.
(snip)
trap failed SIGTERM

if [ $1 == "backup" ]; then
 check_sufficient_space
(snip)


Skip restore if backup had been aborted:
Code Sample
(snip)
if [ $1 == "restore" ]; then
 if [ -e /etc/sysconfig/abortedbackup ]; then
     sudo rm -f /etc/sysconfig/abortedbackup
 else
 if [ -f /etc/sysconfig/des ]; then
    TARGETFILE="backup.des"
(snip)
.
.
(snip)
   echo "${BLUE}Done.${NORMAL}"
 fi
 fi
 clean_up 0
fi
echo "I don't understand the command line parameter: $1"
(snip)


Function:
Code Sample

check_sufficient_space(){

TARERR=/tmp/tarerr.$$
tar -C / -T $HOME/.filetool.lst -X $HOME/.xfiletool.lst --totals -cf - 1>/dev/null 2>${TARERR}
ARCHSIZE=$(awk '/Total bytes written/{print $4}' ${TARERR} )
rm -rf ${TARERR}

if [ $ARCHSIZE -eq 0 ]; then echo "Nothing to backup?"; clean_up; fi

(( ARCHK=ARCHSIZE/1000 )) # want kB
(( ARCHSIZEK = ARCHK + 1 )) # round upwards

FREESPACE=$(df -k $MOUNTPOINT | awk '/dev/{print $4}')

echo "Max upper bound on backup size = $ARCHSIZEK kB"
echo "Available space on $MOUNTPOINT = $FREESPACE kB"

if [ $ARCHSIZEK -ge $FREESPACE ]; then
  a=$(runlevel)
  if [ ${a#*[ ]} -eq 5 ]; then
  # Backing up from gui
  :
  # ------- eg flua GUI goes here which just exits script if user aborts backup -------------
  else
  # We are in shutdown/reboot
     echo "WARNING: there may be insufficient space on $MOUNTPOINT for backup."
     while true; do
     echo -n "Proceed anyway? (y/n) "
     read ANS
     case $ANS in
        n|N|n*|N*) echo "Aborting backup/shutdown .."
          if [ $MOUNTED == "no" ]; then
               sudo umount $MOUNTPOINT
          fi
          sudo touch /etc/sysconfig/abortedbackup
           exec >/dev/null               # prevents trapped "failed" message when init kills this script
           sudo telinit ${a%[ ]*};;         # back to previous runlevel (normally  5 )
        y|Y|y*|Y*) break;;
        *) echo "Invalid response.";;
     esac
     done
  fi
fi
}


If anyone feels like testing the above that might be useful.

Another method (if switching runlevels about turns out to have problems) might be to move backup/restore out of the shutdown scripts altogether, and instead run filetool.sh from exitcheck.sh, before shutdown is called. However this means that (for eg) if a shutdown is initiated by some means other than the menu (eg CNTRL-ALT-DEL), a backup will not occur at all, so imho this is not preferable.
Back to top
Profile PM 
7 replies since July 07 2006,11:43 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (2) </ 1 [2] >/
reply to topic new topic new poll
Quick Reply: Improving DSL fallover recover

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code