Nxdomain due to partial tinydns data file published to secondary
I publish my domains from a central server via http and grab the file via wget. Well, that turned out to be a problem when the vps host for one of my off network dns's had a network hick-up during the transfer, and wget happily wrote the partial file and the script happily regenerated the data.cdb.
To fix this I reworked the script and added a checksum to verify the that the file was the same. If the checksum doesn't match, the tinydns cdb file is not regenerated.
#!/bin/sh
DATAFILE="data"
DATAFILE_TEMP="data.temp"
FILENAME_MD5="datacheck.md5"
HOST="example.com"
HOST_DIR="" #I have my data file on a completely different server than tinydns
USER=""
#Make temp backup copy
cp data data.backup
cp data.cdb data.cdb.backup
#scp data file
scp $USER@$HOST:/$HOST_DIR/$DATAFILE $DATAFILE_TEMP
#verify checksum
#datacheck.php is a simple script to display a md5sum of the data file
curl http://$HOST/$HOSTDIR/datacheck.php -o $FILENAME_MD5
LOCAL_MD5=`md5sum $DATAFILE_TEMP | cut -d" " -f1`
REMOTE_MD5=`cat $FILENAME_MD5`
#if matches then transfer is ok so we can mv the file and make to rebuild the cdb
if [ $LOCAL_MD5 = $REMOTE_MD5 ]; then
mv -f $DATAFILE_TEMP $DATAFILE
make
else
echo "Failed md5 sum (L:R) $LOCAL_MD5:$REMOTE_MD5 on " `date +%Y%m%d%N` >> log
fi
Since this uses scp you will need to create your public/private keys to log in without a password. Of course you should use a non-root account for that part.
I couldn't find a way to use regexp's in this script. Oh well, maybe next time.
That is all. Have fun.
- pat's blog
- Login to post comments
