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 } |
Code Sample |
. (snip) trap failed SIGTERM if [ $1 == "backup" ]; then check_sufficient_space (snip) |
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) |
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 } |