I've created a cron job that will automatically backup your config every night(or whenever you want).
Here's how I did it: (the name of my zpool is tank, yours may vary so you will need to adjust the following accordingly)
I created a file on my zpool at /mnt/tank/bkpconfig.sh. It has one line:
cp /data/freenas-v1.db /mnt/tank/`date +%Y%m%d`.db
Edit:
-----------------------------------------------
If you want the config file to append the version of FreeNAS you are using, you can use this command:
cp /data/freenas-v1.db /mnt/tank/.scripts/ConfigBackups/`date +%Y%m%d`_`cat /etc/version | cut -d'-' -f2`_`cat /etc/version | cut -d'-' -f4`.db
You'll get filenames that are "20150125_9.3_201501241715" where the last characters tell you the build date/time you were using.
-----------------------------------------------
Another edit for 9.3.0 (but not 9.3.1 users) users (see https://bugs.freenas.org/issues/9091):
If you want to do these commands as tasks that run from cron directly, you'll want to use the following commands, correcting for your locations as appropriate:
cp /data/freenas-v1.db "/mnt/tank/`date \+%Y\%m\%d`.db"
- or -
cp /data/freenas-v1.db /mnt/tank/`date \+%Y\%m\%d`_`cat /etc/version | cut -d'-' -f2`_`cat /etc/version | cut -d'-' -f4`.db
-----------------------------------------------
Note that the ` is the top left key on the keyboard, not the typical apostrophe symbol. You can change the location of the db to anything you want, but you should keep it on your zpool or another location that is NOT on your USB key. Also you may not want to put the backup config anywhere that is shared. You wouldn't want anyone to have access to the database or delete them on accident.
Then log into the FreeNAS UI.
Expand "System", then expand Cron Jobs and then click "Add Cron Job".
For User set it to root.
For command use sh /mnt/tank/bkpconfig.sh or whatever location your bkpconfig.sh file is located at.
For short description enter something that makes sense to you. I put "Daily Backup of Config".
I chose to do the backup at 23:55 every day of the week. I figured that would allow me to backup the file as an "end of the day" routine while also doing the backup at an odd time so that other nightly tasks won't interfere.
For minute I chose the "Each selected minute" tab and chose 55.
For hour I chose the "Each selected hour" tab and then chose 23.
For Day of month I did "Every N day of the month" tab and set it to 1.
For Month I checked every month(default)
For Day of week I checked every day(default)
I left "Redirect Stdout" checked, "Redirect Stderr" unchecked and "Enabled" checked(all defaults).
Click "OK" and you should see the job be created.
If you have emails for root setup and your cron job fails you will get an email of the error.
My config file is only 207kb. I'd expect that regardless of your configuration your file isn't going to be big enough to worry about the lost space storing the config files. Plenty of people have been posting in the forums lately that didn't have a backup at all or had an old backup. With this you will have many copies of the config. This may be handy if the database gets corrupted since you have a backup history you can use.
Keep in mind that while the config file is safe on your zpool or elsewhere, you will need to copy the database file to your desktop to upload the config file. I just auto-imported my zpool and created a quick FTP server using anonymous access and was able to do a recovery in about 5 minutes. If you are really motivated you could create an FTP script in windows/linux/whatever that would auto-download your config files every time you logged into windows.
Here's how I did it: (the name of my zpool is tank, yours may vary so you will need to adjust the following accordingly)
I created a file on my zpool at /mnt/tank/bkpconfig.sh. It has one line:
cp /data/freenas-v1.db /mnt/tank/`date +%Y%m%d`.db
Edit:
-----------------------------------------------
If you want the config file to append the version of FreeNAS you are using, you can use this command:
cp /data/freenas-v1.db /mnt/tank/.scripts/ConfigBackups/`date +%Y%m%d`_`cat /etc/version | cut -d'-' -f2`_`cat /etc/version | cut -d'-' -f4`.db
You'll get filenames that are "20150125_9.3_201501241715" where the last characters tell you the build date/time you were using.
-----------------------------------------------
Another edit for 9.3.0 (but not 9.3.1 users) users (see https://bugs.freenas.org/issues/9091):
If you want to do these commands as tasks that run from cron directly, you'll want to use the following commands, correcting for your locations as appropriate:
cp /data/freenas-v1.db "/mnt/tank/`date \+%Y\%m\%d`.db"
- or -
cp /data/freenas-v1.db /mnt/tank/`date \+%Y\%m\%d`_`cat /etc/version | cut -d'-' -f2`_`cat /etc/version | cut -d'-' -f4`.db
-----------------------------------------------
Note that the ` is the top left key on the keyboard, not the typical apostrophe symbol. You can change the location of the db to anything you want, but you should keep it on your zpool or another location that is NOT on your USB key. Also you may not want to put the backup config anywhere that is shared. You wouldn't want anyone to have access to the database or delete them on accident.
Then log into the FreeNAS UI.
Expand "System", then expand Cron Jobs and then click "Add Cron Job".
For User set it to root.
For command use sh /mnt/tank/bkpconfig.sh or whatever location your bkpconfig.sh file is located at.
For short description enter something that makes sense to you. I put "Daily Backup of Config".
I chose to do the backup at 23:55 every day of the week. I figured that would allow me to backup the file as an "end of the day" routine while also doing the backup at an odd time so that other nightly tasks won't interfere.
For minute I chose the "Each selected minute" tab and chose 55.
For hour I chose the "Each selected hour" tab and then chose 23.
For Day of month I did "Every N day of the month" tab and set it to 1.
For Month I checked every month(default)
For Day of week I checked every day(default)
I left "Redirect Stdout" checked, "Redirect Stderr" unchecked and "Enabled" checked(all defaults).
Click "OK" and you should see the job be created.
If you have emails for root setup and your cron job fails you will get an email of the error.
My config file is only 207kb. I'd expect that regardless of your configuration your file isn't going to be big enough to worry about the lost space storing the config files. Plenty of people have been posting in the forums lately that didn't have a backup at all or had an old backup. With this you will have many copies of the config. This may be handy if the database gets corrupted since you have a backup history you can use.
Keep in mind that while the config file is safe on your zpool or elsewhere, you will need to copy the database file to your desktop to upload the config file. I just auto-imported my zpool and created a quick FTP server using anonymous access and was able to do a recovery in about 5 minutes. If you are really motivated you could create an FTP script in windows/linux/whatever that would auto-download your config files every time you logged into windows.
Last edited: