mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-18 18:44:44 +00:00
backup: reworked stategies; closes #909
This commit is contained in:
parent
80541e5eee
commit
1586ee02ff
@ -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,12 +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 RRDDBPATH='{$rrddbpath}' CF_CONF_PATH='/conf' /usr/local/etc/rc.backup_rrd");
|
||||
if (file_exists("/var/run/booting")) {
|
||||
echo "Updating configuration...";
|
||||
}
|
||||
}
|
||||
|
||||
function upgrade_055_to_056() {
|
||||
@ -2787,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 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);
|
||||
}
|
||||
|
||||
@ -3093,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 RRDDBPATH='{$rrddbpath}' CF_CONF_PATH='/conf' /usr/local/etc/rc.backup_rrd");
|
||||
}
|
||||
|
||||
function upgrade_096_to_097()
|
||||
|
||||
@ -185,7 +185,9 @@ echo "done."
|
||||
/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..."
|
||||
|
||||
@ -1,6 +1,14 @@
|
||||
#!/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
|
||||
|
||||
@ -1,14 +1,26 @@
|
||||
#!/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
|
||||
rm -f "${BACKUPDIR}"/*.xml
|
||||
tar -C / -xzf "${BACKUPFILE}"
|
||||
for XML in "${BACKUPDIR}"/*.xml; do
|
||||
RRD="${XML%.xml}.rrd"
|
||||
rm -f "${RRD}"
|
||||
/usr/local/bin/rrdtool restore -f "${XML}" "${RRD}"
|
||||
done
|
||||
rm -f "${BACKUPDIR}"/*.xml
|
||||
fi
|
||||
else
|
||||
if [ -d "${BACKUPDIR}" ]; then
|
||||
for RRD in "${BACKUPDIR}"/*.rrd; do
|
||||
XML="${RRD%.rrd}.xml"
|
||||
/usr/local/bin/rrdtool dump "${RRD}" "${XML}"
|
||||
done
|
||||
tar -C / -czf "${BACKUPFILE}" "${BACKUPDIR}"/*.xml
|
||||
rm -f "${BACKUPDIR}"/*.xml
|
||||
fi
|
||||
fi
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user