I have a nightly cron job that backs up the configuration to a file with the date in the name. Over time this has naturally created a lot of redundant files, so I hacked together this bash script which will only backup the configuration if it is different than the newest file in the bkpfolder.
Code:
#!/bin/sh
bkpfolder='/mnt/tank/bkpconfig'
fc="`find $bkpfolder -maxdepth 1 -type f | wc -l | tr -d '[:space:]'`"
if [ $fc -eq 0 ]
then
cp /data/freenas-v1.db $bkpfolder/`date +%Y%m%d`.db
else
find $bkpfolder -maxdepth 1 -type f -exec stat -f "%m%t%N" {} + | sort | tail -1 | cut -f 2 | xargs cmp /data/freenas-v1.db
if [ $? -ne 0 ]
then
cp /data/freenas-v1.db $bkpfolder/`date +%Y%m%d`.db
fi
fi