Commit ad413528 authored by Franco Fichtner's avatar Franco Fichtner

backup: reworked stategies; closes #909

(cherry picked from commit ce4bb4e7)
(cherry picked from commit 1586ee02)
(cherry picked from commit 58c923b7)
parent 37076ca9
......@@ -26,46 +26,8 @@
POSSIBILITY OF SUCH DAMAGE.
*/
function restore_rrd()
function create_new_rrd($rrdcreatecmd)
{
global $config;
$rrddbpath = '/var/db/rrd/';
$rrdtool = '/usr/local/bin/rrdtool';
$rrdrestore = "";
$rrdreturn = "";
if (file_exists('/conf/rrd.tgz')) {
foreach (glob("{$rrddbpath}/*.xml") as $xml_file) {
@unlink($xml_file);
}
$_gb = exec('cd /;LANG=C /usr/bin/tar -xzf /conf/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");
}
unset($rrdrestore);
foreach (glob("{$rrddbpath}/*.xml") as $xml_file) {
$rrd_file = preg_replace('/\.xml$/', ".rrd", $xml_file);
if (file_exists("{$rrd_file}")) {
@unlink($rrd_file);
}
$output = array();
$status = null;
$_gb = exec("$rrdtool restore -f '{$xml_file}' '{$rrd_file}'", $output, $status);
if ($status) {
log_error("rrdtool restore -f '{$xml_file}' '{$rrd_file}' failed returning {$status}.");
continue;
}
unset($output);
@unlink($xml_file);
}
return true;
}
return false;
}
function create_new_rrd($rrdcreatecmd) {
$rrdcreateoutput = array();
$rrdcreatereturn = 0;
$_gb = exec("$rrdcreatecmd 2>&1", $rrdcreateoutput, $rrdcreatereturn);
......@@ -77,7 +39,6 @@ function create_new_rrd($rrdcreatecmd) {
return $rrdcreatereturn;
}
function enable_rrd_graphing()
{
global $config;
......@@ -149,10 +110,6 @@ function enable_rrd_graphing()
}
chown($rrddbpath, "nobody");
if (file_exists("/var/run/booting")) {
restore_rrd();
}
/* db update script */
$rrdupdatesh = "#!/bin/sh\n";
$rrdupdatesh .= "\n";
......
......@@ -443,19 +443,6 @@ function services_dhcpdv4_configure()
return 0;
}
if (file_exists("/var/run/booting")) {
/* restore the leases, if we have them */
if (file_exists('/conf/dhcpleases.tgz')) {
$dhcprestore = '';
$dhcpreturn = '';
exec('cd /;LANG=C /usr/bin/tar -xzf /conf/dhcpleases.tgz 2>&1', $dhcprestore, $dhcpreturn);
$dhcprestore = implode(' ', $dhcprestore);
if ($dhcpreturn <> 0) {
log_error(sprintf(gettext('DHCP leases restore failed exited with %s, the error is: %s'), $dhcpreturn, $dhcprestore));
}
}
}
/* Only consider DNS servers with IPv4 addresses for the IPv4 DHCP server. */
$dns_arrv4 = array();
if (!empty($config['system']['dnsserver'])) {
......
......@@ -2123,13 +2123,6 @@ function upgrade_054_to_055()
unset($rrdxmlarray);
}
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 NO_REMOUNT=1 RRDDBPATH='{$rrddbpath}' CF_CONF_PATH='/conf' /usr/local/etc/rc.backup_rrd");
mwexec('/bin/rm /var/db/rrd/*.xml');
if (file_exists("/var/run/booting")) {
echo "Updating configuration...";
}
}
function upgrade_055_to_056() {
......@@ -2788,15 +2781,12 @@ function upgrade_080_to_081()
@unlink("/tmp/{$xmldumpnew}");
}
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 NO_REMOUNT=1 RRDDBPATH='{$rrddbpath}' CF_CONF_PATH='/conf' /usr/local/etc/rc.backup_rrd");
if (file_exists("/var/run/booting"))
echo "Updating configuration...";
foreach($config['filter']['rule'] as & $rule) {
if (isset($rule['protocol']) && !empty($rule['protocol']))
$rule['protocol'] = strtolower($rule['protocol']);
}
unset($rule);
}
......@@ -3094,9 +3084,6 @@ function upgrade_095_to_096()
}
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 NO_REMOUNT=1 RRDDBPATH='{$rrddbpath}' CF_CONF_PATH='/conf' /usr/local/etc/rc.backup_rrd");
}
function upgrade_096_to_097()
......
......@@ -181,6 +181,11 @@ echo "done."
# Execute the early syshook / plugin commands
/usr/local/etc/rc.syshook early
# Restore backups from previous shutdown (if any)
/usr/local/etc/rc.backup_dhcpleases restore
/usr/local/etc/rc.backup_netflow restore
/usr/local/etc/rc.backup_rrd restore
# let the PHP-based configuration subsystem set up the system now
echo -n "Launching the init system..."
rm -f /root/lighttpd*
......
#!/bin/sh
# Save the DHCP lease database to the config path.
if [ -d "/var/dhcpd/var/db" ]; then
cd / && tar -czf /conf/dhcpleases.tgz -C / var/dhcpd/var/db/
BACKUPFILE="/conf/dhcpleases.tgz"
BACKUPDIR="/var/dhcpd/var/db"
if [ "${1}" == "restore" ]; then
if [ -f "${BACKUPFILE}" ]; then
tar -C / -xzf "${BACKUPFILE}"
fi
else
if [ -d "${BACKUPDIR}" ]; then
tar -C / -czf "${BACKUPFILE}" "${BACKUPDIR}"
fi
fi
#!/bin/sh
BACKUPFILE="/conf/netflow.tgz"
BACKUPDIR="/var/netflow"
if [ "${1}" == "restore" ]; then
if [ -f "${BACKUPFILE}" ]; then
tar -C / -xzf "${BACKUPFILE}"
fi
else
if [ -d "${BACKUPDIR}" ]; then
tar -C / -czf "${BACKUPFILE}" "${BACKUPDIR}"
fi
fi
#!/bin/sh
: ${RRDDBPATH:=/var/db/rrd}
: ${CF_CONF_PATH:=/conf}
BACKUPDIR="/var/db/rrd"
BACKUPFILE="/conf/rrd.tgz"
# Save the rrd databases to the config path.
if [ -d "${RRDDBPATH}" ]; then
for rrdfile in "${RRDDBPATH}"/*.rrd ; do
xmlfile="${rrdfile%.rrd}.xml"
/usr/local/bin/rrdtool dump "$rrdfile" "$xmlfile"
done
cd / && tar -czf "${CF_CONF_PATH}"/rrd.tgz -C / "${RRDDBPATH#/}"/*.xml
rm "${RRDDBPATH}"/*.xml
if [ "${1}" == "restore" ]; then
if [ -f "${BACKUPFILE}" ]; then
tar -C / -xzf "${BACKUPFILE}"
fi
else
if [ -d "${BACKUPDIR}" ]; then
tar -C / -czf "${BACKUPFILE}" "${BACKUPDIR}"
fi
fi
......@@ -11,6 +11,7 @@
# backup volatile internals
/usr/local/etc/rc.backup_dhcpleases
/usr/local/etc/rc.backup_netflow
/usr/local/etc/rc.backup_rrd
# wait for config lock to release
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment