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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.