From 041cf134f666d776817eb05d050f851715c2c7b7 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Wed, 29 Nov 2023 18:05:58 +0100 Subject: [PATCH] system - remote backup / add an optional random delay before executing remote backups, 3600 seconds max when executed automatically in the nighly run. ref https://github.com/opnsense/plugins/pull/3689 --- src/etc/inc/plugins.inc.d/core.inc | 2 +- src/opnsense/scripts/system/remote_backup.php | 6 ++++++ src/opnsense/service/conf/actions.d/actions_system.conf | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/etc/inc/plugins.inc.d/core.inc b/src/etc/inc/plugins.inc.d/core.inc index a35ec3243..f3c57f811 100644 --- a/src/etc/inc/plugins.inc.d/core.inc +++ b/src/etc/inc/plugins.inc.d/core.inc @@ -329,7 +329,7 @@ function core_cron() foreach ((new OPNsense\Backup\BackupFactory())->listProviders() as $classname => $provider) { if ($provider['handle']->isEnabled()) { - $jobs[]['autocron'] = array('/usr/local/sbin/configctl -d system remote backup', 0, 1); + $jobs[]['autocron'] = array('/usr/local/sbin/configctl -d system remote backup 3600', 0, 1); break; } } diff --git a/src/opnsense/scripts/system/remote_backup.php b/src/opnsense/scripts/system/remote_backup.php index 14f6ba81e..c88d9d93f 100755 --- a/src/opnsense/scripts/system/remote_backup.php +++ b/src/opnsense/scripts/system/remote_backup.php @@ -5,6 +5,12 @@ require_once('script/load_phalcon.php'); use OPNsense\Backup\BackupFactory; +/* add random delay in seconds */ +$random_delay = !empty($argv[1]) ? $argv[1] : null; +if (!empty($random_delay)) { + sleep(rand(0, $random_delay)); +} + $backupFact = new BackupFactory(); foreach ($backupFact->listProviders() as $classname => $provider) { if ($provider['handle']->isEnabled()) { diff --git a/src/opnsense/service/conf/actions.d/actions_system.conf b/src/opnsense/service/conf/actions.d/actions_system.conf index f9fc64191..36d49782e 100644 --- a/src/opnsense/service/conf/actions.d/actions_system.conf +++ b/src/opnsense/service/conf/actions.d/actions_system.conf @@ -42,7 +42,7 @@ message:List SSL ciphers [remote.backup] command:/usr/local/opnsense/scripts/system/remote_backup.php -parameters: +parameters: %s type:script message:Performing remote backup description:Remote backup