Commit 5c8411fa authored by Ad Schellevis's avatar Ad Schellevis

add backup to cron

parent 5f2014cc
......@@ -225,6 +225,12 @@ function write_config($desc = 'Unknown', $backup = true)
session_write_close();
}
if (!isset($config['version'])) {
// Examine config.xml, if for some strange reason the content is unexpected : exit directly.
log_error(gettext("WARNING: Corrupt config!"));
return -1;
}
$cnf = OPNsense\Core\Config::getInstance();
$cnf->fromArray($config);
$revision_info = make_config_revision_entry($desc);
......
......@@ -2308,6 +2308,19 @@ function upnp_start() {
}
}
/**
* check if cron exists
*/
function cron_job_exists($command) {
global $config;
foreach($config['cron']['item'] as $item) {
if(strstr($item['command'], $command)) {
return true;
}
}
return false;
}
function install_cron_job($command, $active=false, $minute="0", $hour="*", $monthday="*", $month="*", $weekday="*", $who="root") {
global $config, $g;
......
......@@ -41,6 +41,8 @@ require_once("guiconfig.inc");
require_once("functions.inc");
require_once("filter.inc");
require_once("shaper.inc");
require_once("services.inc");
require_once("util.inc");
$rrddbpath = '/var/db/rrd';
$rrdtool = '/usr/local/bin/rrdtool';
......@@ -508,6 +510,11 @@ if ($_POST) {
// test / perform backup
try {
$filesInBackup = backup_to_google_drive() ;
$cron_job = "/usr/local/opnsense/scripts/remote_backup.php";
if (!cron_job_exists($cron_job)) {
// initial cron job install
install_cron_job($cron_job,true,0,1);
}
} catch (Exception $e) {
$filesInBackup = array() ;
}
......
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