Cron job for saving RRD graph data on embedded installs



  • Related topic: http://forum.pfsense.org/index.php?topic=10629

    Summary: pfSense embedded installs only save RRD graph data on shutdown or reboot (via /etc/rc.shutdown and /etc/rc.reboot). If it suffers a non-graceful reboot, all RRD data since the last graceful shutdown or reboot will be lost. The solution is to add a cron job which saves this data to the /cf partition, making it persistent. I recently ran into this issue on my embedded pfSense deployment, and lost 6 months of logs. So, I found the above thread discussing the solution, however I had to update a couple things to work with version 2.0. I figured I'd share it here in the hopes it will help someone else.

    Solution: You'll need to save your pfSense config to an XML file, add the following entry to the <cron>section (make sure to preserve the XML file format), and re-upload it to your system. It will reboot automatically and apply the changes. You can then log in via shell or console and look in /etc/crontab to make sure the entry got added, or check your System Log for log entries indicating that it has run on schedule.

    Here is my config.xml cron entry:

     <minute>0</minute>
            <hour>0</hour>
            <mday>*</mday>
            <month>*</month>
            <wday>*</wday>
            <who>root</who>
            <command></command> 
    
    

    Which results in this entry in /etc/crontab:

    0	0	*	*	*	root	echo "RRD backup starting" |logger; /usr/bin/nice -n20 /etc/rc.backup_rrd.sh && echo "RRD backup complete" |logger || echo "RRD backup ERROR" |logger
    

    A few items of note:

    • Runs at midnight every day; change to suit your needs.

    • Calls /etc/rc.backup_rrd.sh which is the script which handles mounting /cf as read-write or read-only (previously the commands were placed directly in cron, presumably this script is new for 2.0).

    • The <command></command>value is encapsulated with CDATA, which is necessary to preserve the non XML friendly characters like ampersands in the command string.

    • Will log the start and subsequent success or failure of the backup script in the pfSense system log.

    • This does increase filesystem writes (although not by very much), so be aware of this depending on the flash storage you are using.

    Hope this helps someone!</cron>


  • Rebel Alliance Developer Netgate

    On Diag > NanoBSD, you can already set an RRD backup or DHCP leases backup frequency, which automatically adds a cron job for you.



  • Wow, I sure went about it the hard way!  :o

    Thanks for your reply. When was that feature added?


  • Rebel Alliance Developer Netgate

    August 9, 2010. :-)


Log in to reply