Backup script not working properly

Fredrik Persson freppe78@hotmail.com
Wed Oct 13 10:46:00 GMT 2004


I have used a very nice backup script i Linux which i now want to use in 
cygwin. 

--------------------------------------------------------------------------
#!/bin/sh
# for FULL backups
# this backs up the important stuffs listed in ${lists} to ${BKPDIR}
# the lists *should* be in ${BKPDIR} and named <whatever>.lst
# the resulting backups will be <whatever>.<timestamp>.tgz
#
# notes:
# - assumes ${BKPDIR} is unmounted and has an /etc/fstab entry
# - assumes /boot is unmounted and has an /etc/fstab entry
# - variables in CAPS are ok for you to set... change the other
#   vars if you know what you're doing
# - you can get fancy in the lists... think xargs *wink*, but
#   you can't use thes spanning feature to break up an
#   archive to smaller pieces of arbitrary size
# - follow your security policy when setting perms on ${BKPDIR}
#
# written by razamatan
#
# DISCLAIMER: razamatan didn't write this if something goes wrong
BKPDIR=/cygdrive/d/backup	# where the backups go
#BOOT=sys			# list that has /boot
NUMBKPS=4			# how many backups to keep
if [ ! -d ${BKPDIR} ] ; then
    echo ${BKPDIR} is not a valid directory or does not exist
fi
#mount ${BKPDIR}		# i have my backup directory on a seperate 
partition
lists=${BKPDIR}/*.lst
ext=tgz
for list in `ls ${lists}`; do
    type=`basename ${list} .lst`
#    if [ ${type} = ${BOOT} ] ; then mount /boot ; fi
    cat ${list} | xargs tar zlcf \
	${BKPDIR}/${type}.`date +%Y-%m-%d-%H%M`.${ext} > /dev/null 2>&1
#    if [ ${type} = ${BOOT} ] ; then umount /boot ; fi
    num=${NUMBKPS}
    for evict in `ls -t ${BKPDIR}/${type}.*.${ext}`; do
        echo ${evict}
	if [ ${num} -le 0 ] ; then rm -f ${evict}
	else num=$((${num}-1)) ; fi
    done
done
#umount ${BKPDIR}	# and i like to keep it unmounted
--------------------------------------------------------------------------

All works but for the last for-loop which is responsible for deleting old 
backups such that only NUMBKPS=4 of the last backups are stored.

The problem is in 'if [ ${num} -le 0 ]' and 'else num=$((${num}-1))'. It seems 
like the num-variable can't be used as an integer. Any suggestions how to fix 
this???



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list