mirror of
https://github.com/Sebclem/hassio-nextcloud-backup.git
synced 2024-11-21 16:52:58 +01:00
🔨 Add custom cron setting #78
This commit is contained in:
parent
c9b4b71e85
commit
f2c9561d9b
@ -64,6 +64,10 @@ class CronContainer {
|
||||
cronStr = "" + splited[1] + " " + splited[0] + " " + settings.cron_month_day + " * *";
|
||||
break;
|
||||
}
|
||||
case "4": {
|
||||
cronStr = settings.cron_custom;
|
||||
break;
|
||||
}
|
||||
}
|
||||
logger.info("Starting Cron...");
|
||||
this.cronJob = new CronJob(cronStr, this._createBackup, null, false, Intl.DateTimeFormat().resolvedOptions().timeZone);
|
||||
|
@ -1,6 +1,7 @@
|
||||
const fs = require("fs");
|
||||
const logger = require("../config/winston");
|
||||
const moment = require("moment");
|
||||
const CronJob = require("cron").CronJob;
|
||||
|
||||
const settingsPath = "/data/backup_conf.json";
|
||||
|
||||
@ -20,6 +21,17 @@ function check_cron(conf) {
|
||||
return conf.cron_month_day != null && conf.cron_month_day >= 1 && conf.cron_month_day <= 28;
|
||||
}
|
||||
|
||||
if (conf.cron_base === "4") {
|
||||
if (conf.cron_custom != null) {
|
||||
try {
|
||||
new CronJob(conf.cron_custom, () => {});
|
||||
return true;
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
}else return false;
|
||||
}
|
||||
|
||||
if (conf.cron_base === "0") return true;
|
||||
} else return false;
|
||||
|
||||
@ -35,6 +47,7 @@ function check(conf, fallback = false) {
|
||||
conf.cron_hour = "00:00";
|
||||
conf.cron_weekday = "0";
|
||||
conf.cron_month_day = "1";
|
||||
conf.cron_custom = "5 4 * * *";
|
||||
} else {
|
||||
logger.error("Bad value for cron settings");
|
||||
return [false, "Bad cron settings"];
|
||||
|
@ -88,6 +88,7 @@
|
||||
<option value="1">Daily</option>
|
||||
<option value="2">Weekly</option>
|
||||
<option value="3">Monthly</option>
|
||||
<option value="4">Custom</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@ -120,6 +121,21 @@
|
||||
<input type="number" class="form-control" id="cron-drop-day-month" min="1" max="28">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row d-none mt-2">
|
||||
<div class="col-12 col-lg-10 offset-lg-1">
|
||||
<label for="cron-drop-custom" class="form-label">Custom Cron Pattern</label>
|
||||
<input type="text" class="form-control" id="cron-drop-custom">
|
||||
<span id="help-cron-custom"" class="form-text">
|
||||
Only '*', ranges (1-3,5), steps (*/2) are allowed.
|
||||
<a target="_blank"
|
||||
href="https://crontab.guru/">
|
||||
Generator
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row my-3">
|
||||
<div class="col-12 text-center border-secondary border"></div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user