The step asked one question — pick a destination, or "not now" — while the
system underneath already had a full location model: eight backend types, per
location engine, path mode, credentials and retention, and a generated
locations.json carrying all of it. None of that was reachable during setup, so a
second destination, or even seeing where the first one points, meant finding the
Backup page afterwards.
Now it mirrors the Storage step — the choice above, the list below:
Backups Automatic — daily, on a schedule | Manual
Destinations Local disk [default] /libreportal-backups/1 [Edit]
+ Add destination
Automatic/Manual needed a setting, because there was no off switch:
crontabSetupBackupScheduler installed the entry unconditionally. CFG_BACKUP_MODE
is explicit rather than overloading "empty schedule", so it reads properly in
the config editor too, and Manual REMOVES an entry that is already installed
rather than merely declining to add one — otherwise answering Manual changes
nothing. The schedule itself is left alone, so switching back restores the time
the user picked.
Destinations are seeded from locations.json, so the default one is shown and
editable instead of being discovered later, and only entries the user actually
added or changed are submitted. A destination on the same disk as the app data
says so on the card rather than in a paragraph under the step.
Remote destinations are what the secret channel was for. The wizard payload is
base64'd into a task's command string and tasks are recorded world-readable, so
a password is POSTed to /api/setup/secret, which writes it where only the
manager can read it and returns an opaque reference; the reference travels in
the payload and setup_apply redeems it once, at the write. A reference that
cannot be redeemed leaves the password alone and says so, rather than blanking
it.
Verified in the browser on a clean install: the step renders both modes, lists
the existing destination at its resolved path, and the add dialog swaps between
local and remote fields. scripts/dev/lp-backup-setup-test covers the apply side,
including that what reaches the config is the secret and never the reference.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
43 lines
1.9 KiB
Bash
43 lines
1.9 KiB
Bash
#!/bin/bash
|
|
|
|
# Install (or refresh) the single daily crontab entry that drives application
|
|
# backups. The entry runs `libreportal backup scheduled`, which enqueues a
|
|
# backup task per enabled app for the processor to drain serially.
|
|
crontabSetupBackupScheduler()
|
|
{
|
|
local ISCRON=$( (runAsManager crontab -l) 2>/dev/null )
|
|
|
|
if [[ "$ISCRON" == *"command not found"* ]]; then
|
|
isNotice "Crontab is not found. Unable to set up the backup scheduler."
|
|
return 0
|
|
fi
|
|
|
|
if ! runAsManager crontab -l 2>/dev/null | grep -q "cron is set up for $sudo_user_name"; then
|
|
isNotice "Crontab is not set up, skipping backup scheduler until it's found."
|
|
return 0
|
|
fi
|
|
|
|
local marker="# CRONTAB BACKUP SCHEDULER"
|
|
local scheduler_entry="$CFG_BACKUP_CRONTAB_APP libreportal backup scheduled $marker"
|
|
|
|
# Drop any previous scheduler entry first. This happens whichever mode we
|
|
# are in, and it is what makes Manual actually take effect: switching to
|
|
# Manual has to REMOVE an entry that is already installed, not merely
|
|
# decline to add one.
|
|
local result; result=$(runAsManager crontab -l 2>/dev/null | grep -v "$marker" | runAsManager crontab -)
|
|
|
|
# Manual: the user starts backups themselves from the Backup page. The
|
|
# schedule below is left in the config untouched, so switching back to
|
|
# Automatic restores the time they had chosen rather than a default.
|
|
if [[ "${CFG_BACKUP_MODE:-automatic}" == "manual" ]]; then
|
|
isNotice "Backups are set to Manual — no schedule installed. Start them from the Backup page."
|
|
return 0
|
|
fi
|
|
|
|
local result; result=$( (runAsManager crontab -l 2>/dev/null; echo "$scheduler_entry") | runAsManager crontab - )
|
|
checkSuccess "Installing the daily backup scheduler entry"
|
|
|
|
local schedule_time=$(echo "$CFG_BACKUP_CRONTAB_APP" | cut -d' ' -f2)
|
|
isSuccessful "Enabled apps will be queued for backup daily at ${schedule_time}:00"
|
|
}
|