import type { Backup } from './api.ts' import { bytes, when } from './format.ts' /** The labels of the backup targets. */ export const TARGET_LABELS: Record = { local: 'Local folder', pbs: 'Proxmox Backup Server' } /** The schedule, the next run (as systemd shows it) and the last run of the server's backups, as rows of Pairs. */ export function backupRows(backup: Backup): [string, string][] { const { settings, state } = backup const rows: [string, string][] = [ ['Backups', settings.enabled ? `${settings.schedule}, to ${TARGET_LABELS[settings.target] ?? settings.target}` : 'off'], ['Next run', backup.next ?? '-'], ] if (!state) { return [...rows, ['Last run', 'none']] } rows.push( ['Last run', `${when(state.started)}${state.finished ? ` to ${new Date(state.finished).toLocaleTimeString()}` : ''}`], ['Last result', state.result], ) if (state.archive ?? state.snapshot) { rows.push(['Last backup', `${state.archive ?? state.snapshot}${state.size === null ? '' : `, ${bytes(state.size)}`}`]) } if (state.cloud) { rows.push(['Cloud copy', `${state.cloud.mode} to ${state.cloud.remote}: ${state.cloud.error ?? state.cloud.result}`]) } if (state.error) { rows.push(['Error', state.error]) } return rows }