feat: Minstrel backs itself up nightly to a folder or an S3 bucket, off until an admin switches it on (#6773)
release / web (push) Failing after 15s
release / govulncheck (push) Successful in 16s
release / go (push) Failing after 41s
release / integration (push) Failing after 3m29s
release / android (push) Successful in 4m7s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 5m34s
release / web (push) Failing after 15s
release / govulncheck (push) Successful in 16s
release / go (push) Failing after 41s
release / integration (push) Failing after 3m29s
release / android (push) Successful in 4m7s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 5m34s
Admin › Backups shows a verdict first (off, not set up, waiting, backed up, overdue, failing since when), Back up now, Test destination and the latest runs, with the settings beside them. - backup.Service: one run at a time, bounded at 30 minutes; the schedule ticks every 5 minutes, catches up a slot missed while the server was down, and retries a failure after an hour and then after as long as it has been failing. Runs are recorded in backup_runs, pruned after 90 days; a run cut off by a shutdown is marked failed at the next start. - A folder destination writes database/minstrel-<UTC stamp>.tar and refuses a folder that isn't there. An S3 destination stages the file, hashes it, and uploads it under database/ through a throttled reader (4 MiB/s by default, 0 for no limit). - Test destination checks the form as typed and only lists. - The bucket secret is sealed like every stored credential; backup_settings and backup_runs are left out of the backup itself. - The panel polls only while a run is going, capped at the run limit plus five minutes. The music switch named in the task is left to #6774, so no control ships that does nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,183 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
saveBackups,
|
||||
testBackups,
|
||||
type BackupConfig,
|
||||
type BackupDestination,
|
||||
type BackupStatus,
|
||||
type BackupTestResult,
|
||||
type BackupUpdate
|
||||
} from '#lib/api/admin.js';
|
||||
import { errMessage } from '#lib/api/errors.js';
|
||||
import { pushToast } from '#lib/stores/toast.svelte.js';
|
||||
import SettingsGroup from '#lib/components/settings/SettingsGroup.svelte';
|
||||
import SettingRow from '#lib/components/settings/SettingRow.svelte';
|
||||
import Segmented from '#lib/components/settings/Segmented.svelte';
|
||||
import { hourLabel, when } from './backupTime.js';
|
||||
|
||||
// Where the nightly backup goes and when. The form keeps its own drafts,
|
||||
// filled from the server on load and after each save, so a status poll
|
||||
// never overwrites what is being typed.
|
||||
|
||||
let { config, onsaved }: { config: BackupConfig; onsaved: (s: BackupStatus) => void } = $props();
|
||||
|
||||
// svelte-ignore state_referenced_locally
|
||||
let draft = $state(fromConfig(config));
|
||||
// Empty means "keep the stored key". The key itself never comes back.
|
||||
let secretKey = $state('');
|
||||
let saving = $state(false);
|
||||
let testing = $state(false);
|
||||
let check = $state<BackupTestResult | null>(null);
|
||||
let testError = $state('');
|
||||
|
||||
function fromConfig(c: BackupConfig) {
|
||||
return {
|
||||
enabled: c.enabled,
|
||||
destination: c.destination,
|
||||
folder: c.folder,
|
||||
endpoint: c.endpoint,
|
||||
bucket: c.bucket,
|
||||
access_key: c.access_key,
|
||||
run_hour: c.run_hour,
|
||||
upload_limit_kib: c.upload_limit_kib
|
||||
};
|
||||
}
|
||||
|
||||
const update = (): BackupUpdate => ({ ...draft, secret_key: secretKey.trim() });
|
||||
|
||||
const dirty = $derived(
|
||||
secretKey.trim() !== '' || JSON.stringify(draft) !== JSON.stringify(fromConfig(config))
|
||||
);
|
||||
|
||||
async function save() {
|
||||
saving = true;
|
||||
try {
|
||||
const s = await saveBackups(update());
|
||||
secretKey = '';
|
||||
draft = fromConfig(s.config);
|
||||
check = null;
|
||||
onsaved(s);
|
||||
pushToast('Backup settings saved.');
|
||||
} catch (e) {
|
||||
pushToast(errMessage(e), 'error');
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function test() {
|
||||
testing = true;
|
||||
check = null;
|
||||
testError = '';
|
||||
try {
|
||||
check = await testBackups(update());
|
||||
} catch (e) {
|
||||
testError = errMessage(e);
|
||||
} finally {
|
||||
testing = false;
|
||||
}
|
||||
}
|
||||
|
||||
const destinations: { value: BackupDestination; label: string }[] = [
|
||||
{ value: 's3', label: 'S3 bucket' },
|
||||
{ value: 'folder', label: 'Folder' }
|
||||
];
|
||||
const hours = Array.from({ length: 24 }, (_, h) => h);
|
||||
|
||||
const button =
|
||||
'rounded-md border border-border px-3 py-1.5 text-sm text-text-secondary hover:bg-surface-hover hover:text-text-primary disabled:opacity-50';
|
||||
const field = 'rounded-md border border-border bg-background px-3 py-1.5 text-sm';
|
||||
</script>
|
||||
|
||||
<SettingsGroup
|
||||
title="Backup settings"
|
||||
id="backup-settings"
|
||||
hint="Minstrel only ever adds backups. Thin out old ones with the destination's own retention."
|
||||
>
|
||||
<SettingRow label="Back up every night" for="backup-enabled" hint="Off until you switch it on.">
|
||||
<input
|
||||
id="backup-enabled"
|
||||
type="checkbox"
|
||||
role="switch"
|
||||
aria-checked={draft.enabled}
|
||||
bind:checked={draft.enabled}
|
||||
class="h-4 w-4 cursor-pointer accent-accent"
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow label="Destination">
|
||||
<Segmented
|
||||
name="backup-destination"
|
||||
label="Destination"
|
||||
options={destinations}
|
||||
value={draft.destination}
|
||||
onchange={(v) => (draft.destination = v)}
|
||||
/>
|
||||
</SettingRow>
|
||||
|
||||
{#if draft.destination === 'folder'}
|
||||
<SettingRow label="Folder" for="backup-folder" hint="A full path on the server, such as a mounted volume.">
|
||||
<input id="backup-folder" bind:value={draft.folder} placeholder="/backups" autocomplete="off" spellcheck="false" class="{field} w-56 font-mono" />
|
||||
</SettingRow>
|
||||
{:else}
|
||||
<SettingRow label="Endpoint" for="backup-endpoint" hint="The bucket's server, path-style.">
|
||||
<input
|
||||
id="backup-endpoint"
|
||||
bind:value={draft.endpoint}
|
||||
placeholder="https://s3.example.com"
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
class="{field} w-56"
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow label="Bucket" for="backup-bucket">
|
||||
<input id="backup-bucket" bind:value={draft.bucket} placeholder="minstrel" autocomplete="off" spellcheck="false" class="{field} w-56" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Access key" for="backup-access-key">
|
||||
<input id="backup-access-key" bind:value={draft.access_key} autocomplete="off" spellcheck="false" class="{field} w-56 font-mono" />
|
||||
</SettingRow>
|
||||
<SettingRow label="Secret key" for="backup-secret-key" hint="Kept encrypted on the server.">
|
||||
<input
|
||||
id="backup-secret-key"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
bind:value={secretKey}
|
||||
placeholder={config.has_secret_key ? 'Key saved' : 'Paste key'}
|
||||
class="{field} w-56 font-mono"
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow label="Upload limit" for="backup-limit" hint="KiB a second, so an upload leaves room on the connection. 0 is no limit.">
|
||||
<input id="backup-limit" type="number" min="0" step="256" bind:value={draft.upload_limit_kib} class="{field} w-28" />
|
||||
</SettingRow>
|
||||
{/if}
|
||||
|
||||
<SettingRow label="Time of day" for="backup-hour" hint="On your clock.">
|
||||
<select id="backup-hour" bind:value={draft.run_hour} class={field}>
|
||||
{#each hours as h (h)}
|
||||
<option value={h}>{hourLabel(h)}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</SettingRow>
|
||||
|
||||
<div class="space-y-2 px-4 py-3">
|
||||
<div class="flex flex-wrap items-center justify-end gap-2">
|
||||
<button type="button" class={button} disabled={testing} onclick={test}>
|
||||
{testing ? 'Testing…' : 'Test destination'}
|
||||
</button>
|
||||
<button type="button" class={button} disabled={!dirty || saving} onclick={save}>
|
||||
{saving ? 'Saving…' : 'Save'}
|
||||
</button>
|
||||
</div>
|
||||
{#if testError}
|
||||
<p class="text-sm text-error-fg" role="alert" data-testid="backup-test">{testError}</p>
|
||||
{:else if check}
|
||||
<p class="text-sm text-success-fg" role="status" data-testid="backup-test">
|
||||
Reached it.
|
||||
{#if check.backups === 0}
|
||||
No backups there yet.
|
||||
{:else}
|
||||
{check.backups} {check.backups === 1 ? 'backup' : 'backups'} there, the newest from {when(check.latest!)}.
|
||||
{/if}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
</SettingsGroup>
|
||||
Reference in New Issue
Block a user