From 543b38bd53c0cec093baa4485ae9500ddea984d0 Mon Sep 17 00:00:00 2001 From: shuki Date: Wed, 4 Mar 2026 17:46:26 +0200 Subject: [PATCH] Add 'gniza schedule run ' command Runs a schedule's backup immediately with the correct --remote and --sysbackup flags from the schedule config. Also fixes WHM Run Now button to include --sysbackup when enabled. Co-Authored-By: Claude Opus 4.6 --- bin/gniza | 35 ++++++++++++++++++++++++++++++++++- whm/gniza-whm/schedules.cgi | 3 +++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/bin/gniza b/bin/gniza index ee71026..d49c693 100755 --- a/bin/gniza +++ b/bin/gniza @@ -959,13 +959,18 @@ cmd_schedule() { [[ -z "$name" ]] && die "Usage: gniza schedule delete " _schedule_delete "$name" ;; + run) + local name="${1:-}" + [[ -z "$name" ]] && die "Usage: gniza schedule run " + _schedule_run "$name" + ;; list|ls) _schedule_list ;; install) install_schedules ;; show) show_schedules ;; remove) remove_schedules ;; - *) die "Unknown schedule subcommand: $subcommand"$'\n'"Usage: gniza schedule {add|delete|list|install|show|remove}" ;; + *) die "Unknown schedule subcommand: $subcommand"$'\n'"Usage: gniza schedule {add|delete|run|list|install|show|remove}" ;; esac } @@ -1077,6 +1082,33 @@ _schedule_delete() { echo "Run 'gniza schedule install' to update cron entries." } +_schedule_run() { + local name="$1" + local config_file="$SCHEDULES_DIR/${name}.conf" + + if [[ ! -f "$config_file" ]]; then + die "Schedule not found: $name (expected $config_file)" + fi + + load_schedule "$name" + + local args=() + if [[ -n "${SCHEDULE_REMOTES:-}" ]]; then + args+=(--remote="$SCHEDULE_REMOTES") + fi + if [[ "${SCHEDULE_SYSBACKUP:-}" == "yes" ]]; then + args+=(--sysbackup) + fi + + echo "Running schedule '$name'..." + echo " Remotes: ${SCHEDULE_REMOTES:-(all)}" + echo " Sysbackup: ${SCHEDULE_SYSBACKUP:-no}" + echo "" + + # Exec replaces this process with the backup command + exec /usr/local/bin/gniza backup "${args[@]}" +} + _schedule_list() { if ! has_schedules; then echo "No schedules configured." @@ -1500,6 +1532,7 @@ ${C_BOLD}Commands:${C_RESET} remote delete Remove a remote destination schedule add Create a backup schedule schedule delete Remove a schedule + schedule run Run a schedule now schedule list Show configured schedules schedule {install|show|remove} Manage cron entries init Setup config + first remote diff --git a/whm/gniza-whm/schedules.cgi b/whm/gniza-whm/schedules.cgi index e1845d0..0447e4b 100644 --- a/whm/gniza-whm/schedules.cgi +++ b/whm/gniza-whm/schedules.cgi @@ -371,6 +371,9 @@ sub handle_run_now { if ($remotes ne '') { push @cmd, "--remote=$remotes"; } + if (($conf->{SYSBACKUP} // '') eq 'yes') { + push @cmd, '--sysbackup'; + } my $log_file = "/var/log/gniza/cron-${name}.log";