Here it is, I am ashamed to admit it but a couple of days again it was amateur hour over here! I logged into my FreeNAS server and initiated a “simple” upgrade to go from 9.10 to 9.10.1 and it just went downhill from there! Simply put, the OS crashed and would not boot up to a point where I could figure out what was broken. Eventually after spending a couple hours working on it, I realized that fastest way to bring it back online would be to rebuild my server. I knew that the data in the volumes would be good but OS needed to be blow away and reinstalled

No big deal… right?! I have a recent config backup and should be able to import it in and be up and running in no time… well here’s the amateur part, it would have behooved me to check how recent my latest config backup was! It was months old and a lot has changed since that backup and was just not worth the effort.

So after a few more hour, I rebuilt the server from scratch and imported my volumes back and were back online again. Well I thought to myself, I will not let this happen again and will look for an automatic config backup option in FreeNAS. To my surprise, there is no automatic config backup option, just a manual one (WebGUI > System > General > Save Config).

So someone most have already come up with a fix, right? A little Google search later and I have a hit that looks like it from the FreeNAS forums that also has a FreeNAS bug report on it.

Only thing is that it seems it only works on FreeNAS 9.3.0 (possibly 9.3.1) and below and I am now running 9.10.1. But basically it’s a Cron job that executes a copy command with some fancy renaming for the destination file to append both a date and version in the file name.

cp /data/freenas-v1.db /mnt/tank/`date \+%Y\%m\%d`_`cat /etc/version | cut -d'-' -f2`_`cat /etc/version | cut -d'-' -f4`.db

So after realizing that the current FreeNAS config is stored at /data/freenas-v1.db , it was game on. I decided to revise the above code to swap out cut for awk and remove all of the escapes. The below code has been tested to work in 9.10 and above.

cp /data/freenas-v1.db /mnt/volume/backups/config-`hostname`-`cat /etc/version | awk -F'[- ]' '{print $2 "_" $3}'`-`date "+%Y%m%d%H%M"`.db

Which should output a config backup with the following naming,

If you would like a config backup without the FQDN and just the hostname, use instead hostname -s switch like below.

cp /data/freenas-v1.db /mnt/volume/backups/config-`hostname -s`-`cat /etc/version | awk -F'[- ]' '{print $2 "_" $3}'`-`date "+%Y%m%d%H%M"`.db

Which should now output a config backup with the following naming structure,

Now to step it up, with either of the above Cron scripts running at whatever increments, you’re just going to have a backup folder buildup with an indefinite number of configs. So let’s manage this a little better by using find /mnt/volume/backups/* -mtime +90 -type f -delete, which will allow us to only keep the last 90 days worth of configs.

Now taking my first revised script and applying this 90 date retention to it, we will get the following code.

cp /data/freenas-v1.db /mnt/volume/backups/config-`hostname`-`cat /etc/version | awk -F'[- ]' '{print $2 "_" $3}'`-`date "+%Y%m%d%H%M"`.db && find /mnt/volume/backups/* -mtime +90 -type f -delete

Finally once you have decided which script works best for your needs, setup a new Cron job within the FreeNAS WebGUI (WebGUI > Tasks > Cron Jobs > Add Cron Job) to utilize it.

Hopefully with this post, I can help prevent another amateur hour/day from happening!