diff options
author | Darren Embry <dse@webonastick.com> | 2012-04-12 19:10:42 -0400 |
---|---|---|
committer | Darren Embry <dse@webonastick.com> | 2012-04-12 19:11:18 -0400 |
commit | 8bdb687946ddb997beb07caccfef61b961f4507e (patch) | |
tree | 7a055925c49eedd3ebbcf67e272ddd9a40cc85f7 /etc/inc | |
parent | 0d0cb04730eba406da9e2a063da636dd6d4f9208 (diff) | |
download | pfsense-8bdb687946ddb997beb07caccfef61b961f4507e.zip pfsense-8bdb687946ddb997beb07caccfef61b961f4507e.tar.gz |
Feature #2123 Backup RRD files using the xml dump and restore from RRD tools
http://redmine.pfsense.org/issues/2123
Diffstat (limited to 'etc/inc')
-rw-r--r-- | etc/inc/rrd.inc | 39 | ||||
-rw-r--r-- | etc/inc/upgrade_config.inc | 8 |
2 files changed, 30 insertions, 17 deletions
diff --git a/etc/inc/rrd.inc b/etc/inc/rrd.inc index e24f30c..5294075 100644 --- a/etc/inc/rrd.inc +++ b/etc/inc/rrd.inc @@ -47,6 +47,33 @@ function dump_rrd_to_xml($rrddatabase, $xmldumpfile) { return($dumpret); } +function restore_rrd() { + global $g; + + $rrddbpath = "/var/db/rrd/"; + $rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool"; + + $rrdrestore = ""; + $rrdreturn = ""; + if (file_exists("{$g['cf_conf_path']}/rrd.tgz")) { + foreach (glob("{$rrddbpath}/*.xml") as $xml_file) { + unlink($xml_file); + } + exec("cd /;LANG=C /usr/bin/tar -xzf {$g['cf_conf_path']}/rrd.tgz 2>&1", $rrdrestore, $rrdreturn); + $rrdrestore = implode(" ", $rrdrestore); + if($rrdreturn != 0) { + log_error("RRD restore failed exited with $rrdreturn, the error is: $rrdrestore\n"); + } + foreach (glob("{$rrddbpath}/*.xml") as $xml_file) { + $rrd_file = preg_replace('/\.xml$/', ".rrd", $xml_file); + exec("$rrdtool restore '{$xml_file}' '{$rrd_file}'"); + unlink($xml_file); + } + return true; + } + return false; +} + function create_new_rrd($rrdcreatecmd) { $rrdcreateoutput = array(); $rrdcreatereturn = 0; @@ -226,9 +253,6 @@ function enable_rrd_graphing() { /* read the shaper config */ read_altq_config(); - $rrdrestore = ""; - $rrdreturn = ""; - if (isset ($config['rrd']['enable'])) { /* create directory if needed */ @@ -239,14 +263,7 @@ function enable_rrd_graphing() { if ($g['booting']) { if ($g['platform'] != "pfSense") { - /* restore the databases, if we have one */ - if (file_exists("{$g['cf_conf_path']}/rrd.tgz")) { - exec("cd /;LANG=C /usr/bin/tar -xzf {$g['cf_conf_path']}/rrd.tgz 2>&1", $rrdrestore, $rrdreturn); - $rrdrestore = implode(" ", $rrdrestore); - if($rrdreturn <> 0) { - log_error(sprintf(gettext('RRD restore failed exited with %1$s, the error is: %2$s%3$s'), $rrdreturn, $rrdrestore, "\n")); - } - } + restore_rrd(); } } diff --git a/etc/inc/upgrade_config.inc b/etc/inc/upgrade_config.inc index 140f22d..42396f5 100644 --- a/etc/inc/upgrade_config.inc +++ b/etc/inc/upgrade_config.inc @@ -1986,11 +1986,7 @@ function upgrade_054_to_055() { $rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool"; if ($g['platform'] != "pfSense") { /* restore the databases, if we have one */ - if (file_exists("{$g['cf_conf_path']}/rrd.tgz")) { - exec("cd /;LANG=C /usr/bin/tar -xzf {$g['cf_conf_path']}/rrd.tgz 2>&1", $rrdrestore, $rrdreturn); $rrdrestore = implode(" ", $rrdrestore); - if($rrdreturn <> 0) { - log_error("RRD restore failed exited with $rrdreturn, the error is: $rrdrestore\n"); - } + if (restore_rrd()) { /* Make sure to move the rrd backup out of the way. We will make a new one after converting. */ exec("/bin/mv {$g['cf_conf_path']}/rrd.tgz {$g['cf_conf_path']}/backup"); } @@ -2111,7 +2107,7 @@ function upgrade_054_to_055() { enable_rrd_graphing(); /* Let's save the RRD graphs after we run enable RRD graphing */ /* The function will restore the rrd.tgz so we will save it after */ - exec("cd /;LANG=C /usr/bin/tar -czf {$g['cf_conf_path']}/rrd.tgz -C / var/db/rrd/*.rrd"); + exec("cd /; LANG=C NO_REMOUNT=1 RRDDBPATH='{$rrddbpath}' CF_CONF_PATH='{$g['cf_conf_path']}' /etc/rc.backup_rrd.sh"); if ($g['booting']) echo "Updating configuration..."; } |