Note: This is a repost since I accidentally deleted the thread instead of a few posts.. whoops!
So I've noticed a lot of people having corruption problems with their FreeNAS configuration file as of late. And It gave me an idea. Since it's simply an sql database, why not do an integrity check as part of a daily routine? Who wants to use a corrupted configuration file for days or weeks only to learn their backups are corrupt. So here's how you do it!
Edit: If you want to run the command locally or from ssh, the command is (and the quotations are supposed to be there!)
NOTE: You can even run this command against backup copies of your database file!
1. Create a .sh file, call it whatever you want, and put it wherever you want(preferably on your zpool in a safe place). Make sure it has execute permissions for root!!!
2. Create a cronjob that points to the file:
User: root
Command : /whereveryouputthescript/scriptname.sh
Short Description: Daily database check
All of the date/time options: However you want to set them. I do nightly at 2330.
Redirect Stdout: Checked
Redirect Stderr: Checked
Enabled: What do you think? If you don't know, stop using FreeNAS right now...
Here's the script:
If you like this idea, don't forget to read my thread on how to backup your config file to your pool automatically every night here.
If you want to do backups AND config checks, you can change the cronjob to instead be something like: /mnt/tank/chkconfig.sh && /mnt/tank/bkpconfig.sh
With that command, if the chkconfig fails then the backup doesn't happen.(Thanks Neil Whitworth for the idea!)
Good luck and happy NASing!
So I've noticed a lot of people having corruption problems with their FreeNAS configuration file as of late. And It gave me an idea. Since it's simply an sql database, why not do an integrity check as part of a daily routine? Who wants to use a corrupted configuration file for days or weeks only to learn their backups are corrupt. So here's how you do it!
Edit: If you want to run the command locally or from ssh, the command is (and the quotations are supposed to be there!)
sqlite3 /data/freenas-v1.db "pragma integrity_check"
If it returns "ok" then all is good.NOTE: You can even run this command against backup copies of your database file!
1. Create a .sh file, call it whatever you want, and put it wherever you want(preferably on your zpool in a safe place). Make sure it has execute permissions for root!!!
2. Create a cronjob that points to the file:
User: root
Command : /whereveryouputthescript/scriptname.sh
Short Description: Daily database check
All of the date/time options: However you want to set them. I do nightly at 2330.
Redirect Stdout: Checked
Redirect Stderr: Checked
Enabled: What do you think? If you don't know, stop using FreeNAS right now...
Here's the script:
Code:
#!/bin/sh # This file runs a database integrity check and emails you in the event that # your database is corrupt. This file requires you to have *properly* setup # emailing from the FreeNAS GUI. The following variables are available for # you to use: # # YourEmail: The email address you want to send the email to if your database # is found to be corrupt. Multiple email addresses are supported if separated # by a space. YourEmail="youremail@server.com" # ServerName: How you want your server's name to appear in the email in the # event that the database is corrupt. ServerName=YourServerNameHere # TempLocation: Location for the temp file for the email. Default is /tmp TempLocation=/tmp # Scroll down to edit the email as you see fit. The default setup is recommended # since it works and conveys a simple email to let you know what the problem # is and that you need to take action. # If you want to test this to ensure it works, simply rename the line with # freenas-v1.db to pointto a file that doesn't exist. It will error, and you will get # an email. if [ -f "$TempLocation"/badconfig.txt ]; then rm "$TempLocation"/badconfig.txt fi if [ "$( sqlite3 /data/freenas-v1.db "pragma integrity_check;" )" == "ok" ]; then #echo "Database is ok." #bail out with zero (all o.k.) status exit 0 else # The following lines are the email that will be sent in the event that errors # are found. Change it however you wish, just make sure the general format # is protected. echo "To: $YourEmail" >> $TempLocation/badconfig.txt echo "Subject: ERROR: Database corrupt on server $ServerName" >> $TempLocation/badconfig.txt echo "Your server, $ServerName, has been found to have a corrupt FreeNAS config." >> $TempLocation/badconfig.txt echo " " >> $TempLocation/badconfig.txt echo "It is recommended you troubleshoot and correct the problem as soon as possible. Just because the server is operating fine does not mean you can ignore this message." >> $TempLocation/badconfig.txt echo "$TempLocation"/badconfig.txt sendmail -t < "$TempLocation"/badconfig.txt rm "$TempLocation"/badconfig.txt fi exit 1
If you like this idea, don't forget to read my thread on how to backup your config file to your pool automatically every night here.
If you want to do backups AND config checks, you can change the cronjob to instead be something like: /mnt/tank/chkconfig.sh && /mnt/tank/bkpconfig.sh
With that command, if the chkconfig fails then the backup doesn't happen.(Thanks Neil Whitworth for the idea!)
Good luck and happy NASing!