date=`date +%Y.%m.%d_%H:%M:%S` datefile=backup/run/$date backup_file=/backup/bad/${date}.force.cpio md5_file=/backup/md5/${date}.force.cpio backup_done=/backup/files/${date}.force.cpio last_file=/backup/date/lastforce 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' # 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 \( ! -type d -print0 \) # printing dirs separately emulates the -depth option but # allows pruning to take place properly. find $backupdirs -type d -print0 \( -regex 'home/hakhavan/catalogs/[^/]*/(session)' -o -regex 'home/hakhavan/catalogs/[^/]*/tmp' \) -prune ) | nice cpio -o --verbose --reset-access-time --null --format=crc -B > $backup_file then ln -f $datefile $lastfile mv $backup_file $backup_done mv $datefile backup/date/. md5sum $backup_done > $md5_file true else rm $datefile false # return with non-zero result code fi