feat: sicherungsstatus im admin-bereich, readme zu backup und restore
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7fd699c6af
commit
50cf1a8492
6 files changed
+191
-12
No files matched your search
@@ -112,3 +112,14 @@ export interface CreatedApiToken extends ApiToken {
|
||||
/** The secret itself; only returned once */
|
||||
token: string
|
||||
}
|
||||
|
||||
export interface BackupStatus {
|
||||
enabled: boolean
|
||||
/** Local hour of the daily backup */
|
||||
hour: number
|
||||
latest: { name: string; size: number; created_at: string } | null
|
||||
count: number
|
||||
/** No backup within the last day */
|
||||
stale: boolean
|
||||
last_error: string | null
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import type { BackupStatus as Status } from '@/api/types'
|
||||
|
||||
import BackupStatus from './BackupStatus.vue'
|
||||
|
||||
const ok: Status = {
|
||||
enabled: true,
|
||||
hour: 3,
|
||||
latest: { name: 'app-2026-10-25.db.gz', size: 1536, created_at: '2026-10-25T02:00:00Z' },
|
||||
count: 5,
|
||||
stale: false,
|
||||
last_error: null,
|
||||
}
|
||||
|
||||
async function render(status: Status) {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn(async () => new Response(JSON.stringify(status), { status: 200 })),
|
||||
)
|
||||
const wrapper = mount(BackupStatus)
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
describe('BackupStatus', () => {
|
||||
afterEach(() => vi.unstubAllGlobals())
|
||||
|
||||
it('shows the latest backup', async () => {
|
||||
const wrapper = await render(ok)
|
||||
expect(wrapper.text()).toContain('1,5 KB')
|
||||
expect(wrapper.text()).toContain('täglich 03:00 Uhr')
|
||||
expect(wrapper.text()).toContain('5 Sicherungen')
|
||||
expect(wrapper.classes()).not.toContain('problem')
|
||||
})
|
||||
|
||||
it('warns when no backup ran for a day', async () => {
|
||||
const wrapper = await render({ ...ok, stale: true })
|
||||
expect(wrapper.classes()).toContain('problem')
|
||||
expect(wrapper.find('[role=alert]').text()).toContain('Seit über einem Tag')
|
||||
})
|
||||
|
||||
it('shows the last error', async () => {
|
||||
const wrapper = await render({ ...ok, last_error: '25.10.2026 03:00: disk full' })
|
||||
expect(wrapper.find('[role=alert]').text()).toContain('disk full')
|
||||
})
|
||||
|
||||
it('a disabled backup is not a problem', async () => {
|
||||
const wrapper = await render({ ...ok, enabled: false, stale: true, latest: null, count: 0 })
|
||||
expect(wrapper.classes()).not.toContain('problem')
|
||||
expect(wrapper.text()).toContain('ausgeschaltet')
|
||||
expect(wrapper.find('[role=alert]').exists()).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,91 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
|
||||
import { api } from '@/api/client'
|
||||
import type { BackupStatus } from '@/api/types'
|
||||
import { formatBytes, formatDateTime } from '@/utils/format'
|
||||
|
||||
const status = ref<BackupStatus | null>(null)
|
||||
const error = ref<string | null>(null)
|
||||
|
||||
// Disabled is a choice, not a problem; a missing or failed backup while enabled is
|
||||
const problem = computed(
|
||||
() =>
|
||||
status.value !== null &&
|
||||
status.value.enabled &&
|
||||
(status.value.stale || !!status.value.last_error),
|
||||
)
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
status.value = await api.get<BackupStatus>('/admin/backup')
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : String(e)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="card" :class="{ problem }">
|
||||
<h2>Datensicherung</h2>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<template v-else-if="status">
|
||||
<p v-if="!status.enabled" class="muted">
|
||||
Automatische Sicherung ist ausgeschaltet (<code>BACKUP_ENABLED=false</code>).
|
||||
</p>
|
||||
<dl>
|
||||
<dt>Letzte Sicherung</dt>
|
||||
<dd :class="{ error: status.enabled && status.stale }">
|
||||
<template v-if="status.latest">
|
||||
{{ formatDateTime(status.latest.created_at) }} · {{ formatBytes(status.latest.size) }}
|
||||
</template>
|
||||
<template v-else>noch keine</template>
|
||||
</dd>
|
||||
<dt>Zeitplan</dt>
|
||||
<dd>täglich {{ String(status.hour).padStart(2, '0') }}:00 Uhr</dd>
|
||||
<dt>Vorhanden</dt>
|
||||
<dd>{{ status.count }} {{ status.count === 1 ? 'Sicherung' : 'Sicherungen' }}</dd>
|
||||
</dl>
|
||||
<p v-if="status.last_error" class="error" role="alert">
|
||||
Letzter Versuch fehlgeschlagen: {{ status.last_error }}
|
||||
</p>
|
||||
<p v-else-if="status.enabled && status.stale" class="error" role="alert">
|
||||
Seit über einem Tag keine Sicherung. Log prüfen:
|
||||
<code>docker compose logs app | grep -i backup</code>
|
||||
</p>
|
||||
<p class="muted small">
|
||||
Ablage unter <code>data/backups/</code>. Manuell sichern:
|
||||
<code>docker exec -u app lan-clipboard lc-admin backup</code>
|
||||
</p>
|
||||
</template>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.problem {
|
||||
border-color: var(--error);
|
||||
}
|
||||
|
||||
dl {
|
||||
display: grid;
|
||||
grid-template-columns: max-content 1fr;
|
||||
gap: 0.25rem 1rem;
|
||||
margin: 0 0 1rem;
|
||||
}
|
||||
|
||||
dt {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
dd {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
code {
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.small {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
</style>
|
||||
@@ -3,6 +3,7 @@ import { onMounted, ref } from 'vue'
|
||||
|
||||
import { api } from '@/api/client'
|
||||
import type { Role, User } from '@/api/types'
|
||||
import BackupStatus from '@/components/BackupStatus.vue'
|
||||
import SystemStatus from '@/components/SystemStatus.vue'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { formatDateTime } from '@/utils/format'
|
||||
@@ -158,6 +159,7 @@ onMounted(load)
|
||||
</section>
|
||||
|
||||
<SystemStatus />
|
||||
<BackupStatus />
|
||||
</main>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in new issue
Block a user