date=`date +%Y.%m.%d_%H:%M:%S` datefile=/backup/run/$date.inc backup_file=/backup/bad/${date}.inc.cpio md5_file=/backup/md5/${date}.inc.cpio backup_done=/backup/files/${date}.inc.cpio lastback=/backup/date/lastfull lastfile=/backup/date/lastinc backupdirs="home/hakhavan var/lib/mysql var/qmail var/vpopmail " cd / trap " mv $backup_file backup/bad/.; rm $datefile; exit 1 " 1 2 3 15 touch $datefile if ( echo -ne $datefile'\00' echo -ne $lastback'\00' sleep 1 # Print files first then directories... # prun two undwanted directories find $backupdirs \( \( -name core -o -regex 'home/hakhavan/misc' -o -regex 'home/hakhavan/catalogs/[^/]*/(session|logs/usertrack)' -o -regex 'home/hakhavan/catalogs/[^/]*/tmp' -o -regex 'home/hakhavan/catalogs/[^/]*/error.log' \) -prune \) -o \( -newer $lastback ! -type d -print0 \) # printing dirs separately emulates the -depth option but # allows pruning to take place properly. find $backupdirs \( \( -regex 'home/hakhavan/catalogs/[^/]*/tmp' -0 -regex 'home/hakhavan/catalogs/[^/]*/(session)' \) -print0 -prune \) -o \( -newer $lastback -type d -print0 \) ) | nice cpio -o --verbose --reset-access-time --null --format=crc -B > $backup_file then ln -f $datefile $lastfile mv $datefile backup/date/. mv $backup_file $backup_done md5sum $backup_done > $md5_file true else rm $datefile false # return with non-zero result code fi