Add 'gniza schedule run <name>' 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 <noreply@anthropic.com>
This commit is contained in:
35
bin/gniza
35
bin/gniza
@@ -959,13 +959,18 @@ cmd_schedule() {
|
|||||||
[[ -z "$name" ]] && die "Usage: gniza schedule delete <name>"
|
[[ -z "$name" ]] && die "Usage: gniza schedule delete <name>"
|
||||||
_schedule_delete "$name"
|
_schedule_delete "$name"
|
||||||
;;
|
;;
|
||||||
|
run)
|
||||||
|
local name="${1:-}"
|
||||||
|
[[ -z "$name" ]] && die "Usage: gniza schedule run <name>"
|
||||||
|
_schedule_run "$name"
|
||||||
|
;;
|
||||||
list|ls)
|
list|ls)
|
||||||
_schedule_list
|
_schedule_list
|
||||||
;;
|
;;
|
||||||
install) install_schedules ;;
|
install) install_schedules ;;
|
||||||
show) show_schedules ;;
|
show) show_schedules ;;
|
||||||
remove) remove_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
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1077,6 +1082,33 @@ _schedule_delete() {
|
|||||||
echo "Run 'gniza schedule install' to update cron entries."
|
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() {
|
_schedule_list() {
|
||||||
if ! has_schedules; then
|
if ! has_schedules; then
|
||||||
echo "No schedules configured."
|
echo "No schedules configured."
|
||||||
@@ -1500,6 +1532,7 @@ ${C_BOLD}Commands:${C_RESET}
|
|||||||
remote delete <name> Remove a remote destination
|
remote delete <name> Remove a remote destination
|
||||||
schedule add <name> Create a backup schedule
|
schedule add <name> Create a backup schedule
|
||||||
schedule delete <name> Remove a schedule
|
schedule delete <name> Remove a schedule
|
||||||
|
schedule run <name> Run a schedule now
|
||||||
schedule list Show configured schedules
|
schedule list Show configured schedules
|
||||||
schedule {install|show|remove} Manage cron entries
|
schedule {install|show|remove} Manage cron entries
|
||||||
init Setup config + first remote
|
init Setup config + first remote
|
||||||
|
|||||||
@@ -371,6 +371,9 @@ sub handle_run_now {
|
|||||||
if ($remotes ne '') {
|
if ($remotes ne '') {
|
||||||
push @cmd, "--remote=$remotes";
|
push @cmd, "--remote=$remotes";
|
||||||
}
|
}
|
||||||
|
if (($conf->{SYSBACKUP} // '') eq 'yes') {
|
||||||
|
push @cmd, '--sysbackup';
|
||||||
|
}
|
||||||
|
|
||||||
my $log_file = "/var/log/gniza/cron-${name}.log";
|
my $log_file = "/var/log/gniza/cron-${name}.log";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user