Netgate m1n1wall

Author Topic: Cron job for saving RRD graph data on embedded installs  (Read 2734 times)

0 Members and 1 Guest are viewing this topic.

Offline xak

  • Newbie
  • *
  • Posts: 2
  • Linux Sysadmin
    • View Profile
Cron job for saving RRD graph data on embedded installs
« on: June 19, 2012, 06:31:49 pm »
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:
Code: [Select]
<item>
        <minute>0</minute>
        <hour>0</hour>
        <mday>*</mday>
        <month>*</month>
        <wday>*</wday>
        <who>root</who>
        <command><![CDATA[echo "RRD backup starting" |logger; /usr/bin/nice -n20 /etc/rc.backup_rrd.sh && echo "RRD backup complete" |logger || echo "RRD backup ERROR" |logger]]></command>
</item>

Which results in this entry in /etc/crontab:
Code: [Select]
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> 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!
Morex 3688B
Phylon 7F2WE-2G (2GHz Via C7, 1GB DDR2 533MHz)
AD3INLANG 3x 1Gb Intel
4GB USB thumbdrive on USB header adapter
pfSense-2.0.2-RELEASE-4g-i386-nanobsd_vga

Offline jimp

  • Administrator
  • Hero Member
  • *****
  • Posts: 14935
    • View Profile
Re: Cron job for saving RRD graph data on embedded installs
« Reply #1 on: June 24, 2012, 12:53:40 pm »
On Diag > NanoBSD, you can already set an RRD backup or DHCP leases backup frequency, which automatically adds a cron job for you.
Need help fast? Commercial Support!

Co-Author of pfSense: The Definitive Guide. - Check the Doc Wiki for FAQs.

Do not PM for help!

Offline xak

  • Newbie
  • *
  • Posts: 2
  • Linux Sysadmin
    • View Profile
Re: Cron job for saving RRD graph data on embedded installs
« Reply #2 on: June 28, 2012, 12:07:05 am »
Wow, I sure went about it the hard way!  :o

Thanks for your reply. When was that feature added?
Morex 3688B
Phylon 7F2WE-2G (2GHz Via C7, 1GB DDR2 533MHz)
AD3INLANG 3x 1Gb Intel
4GB USB thumbdrive on USB header adapter
pfSense-2.0.2-RELEASE-4g-i386-nanobsd_vga

Offline jimp

  • Administrator
  • Hero Member
  • *****
  • Posts: 14935
    • View Profile
Re: Cron job for saving RRD graph data on embedded installs
« Reply #3 on: June 28, 2012, 12:11:21 am »
August 9, 2010. :-)
Need help fast? Commercial Support!

Co-Author of pfSense: The Definitive Guide. - Check the Doc Wiki for FAQs.

Do not PM for help!