WDef
Group: Members
Posts: 798
Joined: Sep. 2005 |
|
Posted: July 13 2006,10:35 |
|
'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.
|