import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { api, type CurrentUser, type IntegrationSummary, type PbsDatastore, type PbsDatastoresResponse, type PbsNodeStatus, } from "../api/client"; import { useSortable } from "../hooks/useSortable"; import SortableTh from "../components/SortableTh"; import { downloadCsv } from "../utils/csv"; import IntegrationPageTitle from "../components/IntegrationPageTitle"; import { ErrorNotice } from "../components/Notice"; function formatBytes(bytes: number | null): string { if (bytes === null) return "—"; const units = ["B", "KB", "MB", "GB", "TB", "PB"]; let value = bytes; let unit = 0; while (value >= 1024 && unit < units.length - 1) { value /= 1024; unit++; } return `${value.toFixed(1)} ${units[unit]}`; } function formatDate(unixSeconds: number | null): string { if (unixSeconds === null) return "—"; return new Date(unixSeconds * 1000).toLocaleString(); } function formatUptime(seconds: number | null): string { if (seconds === null) return "—"; const days = Math.floor(seconds / 86400); const hours = Math.floor((seconds % 86400) / 3600); const minutes = Math.floor((seconds % 3600) / 60); const parts: string[] = []; if (days) parts.push(`${days}d`); if (days || hours) parts.push(`${hours}h`); parts.push(`${minutes}m`); return parts.join(" "); } function verificationBadge(d: PbsDatastore) { if (d.error) return Unreadable; if (d.failedCount > 0) return {d.failedCount} failed; if (d.unverifiedCount > 0) return {d.unverifiedCount} unverified; return All verified; } export default function PbsBackup({ user: _user }: { user: CurrentUser }) { const [integrations, setIntegrations] = useState(null); const [selectedId, setSelectedId] = useState(null); const [error, setError] = useState(null); const [data, setData] = useState(null); const [loading, setLoading] = useState(false); const [status, setStatus] = useState(null); const [statusError, setStatusError] = useState(null); const [loadingStatus, setLoadingStatus] = useState(false); useEffect(() => { api.integrations .list() .then((res) => { const pbsIntegrations = res.integrations.filter((i) => i.type === "pbs"); setIntegrations(pbsIntegrations); if (!selectedId && pbsIntegrations.length > 0) setSelectedId(pbsIntegrations[0].id); }) .catch((err) => setError(err instanceof Error ? err.message : String(err))); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const selected = integrations?.find((i) => i.id === selectedId) ?? null; function loadDatastores(id: number) { setLoading(true); setError(null); api.integrations.pbs .datastores(id) .then((res) => setData(res)) .catch((err) => setError(err instanceof Error ? err.message : String(err))) .finally(() => setLoading(false)); } function loadStatus(id: number) { setLoadingStatus(true); setStatusError(null); api.integrations.pbs .status(id) .then((res) => setStatus(res)) .catch((err) => setStatusError(err instanceof Error ? err.message : String(err))) .finally(() => setLoadingStatus(false)); } useEffect(() => { if (selected?.enabled) { loadDatastores(selected.id); loadStatus(selected.id); } else { setData(null); setStatus(null); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [selectedId]); const { sorted: sortedDatastores, sortKey, sortDir, requestSort } = useSortable(data?.datastores); function exportCsv() { if (!sortedDatastores) return; downloadCsv( "pbs-datastores.csv", ["Datastore", "Used", "Total", "Snapshots", "Failed", "Unverified", "Latest snapshot"], sortedDatastores.map((d) => [ d.name, formatBytes(d.usedBytes), formatBytes(d.totalBytes), d.snapshotCount, d.failedCount, d.unverifiedCount, formatDate(d.latestSnapshotAt), ]), ); } return ( <> {integrations?.length === 0 ? (
No Proxmox Backup Server integration configured yet. Add one under Integrations.
) : ( <> {integrations && integrations.length > 1 && (
)} {selected && !selected.enabled ? (
"{selected.name}" is disabled. Enable it under Integrations → Manage integrations to see its datastores.
) : (

Node

{statusError ? (
{statusError}
) : (
Uptime
{formatUptime(status?.uptime ?? null)}
CPU
{status?.cpuUsagePercent !== null && status?.cpuUsagePercent !== undefined ? `${status.cpuUsagePercent.toFixed(0)}%` : "—"} {status?.cpuCores ? ({status.cpuCores} cores) : null}
Memory
{formatBytes(status?.memUsedBytes ?? null)} / {formatBytes(status?.memTotalBytes ?? null)}
Root filesystem
{formatBytes(status?.rootfsUsedBytes ?? null)} / {formatBytes(status?.rootfsTotalBytes ?? null)}
)}

Datastores

label="Datastore" sortKeyName="name" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> label="Used" sortKeyName="usedBytes" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> label="Snapshots" sortKeyName="snapshotCount" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> label="Latest snapshot" sortKeyName="latestSnapshotAt" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> label="Verification" sortKeyName="failedCount" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> {sortedDatastores?.map((d) => ( ))} {sortedDatastores?.length === 0 && ( )}
{d.name} {d.comment &&
{d.comment}
}
{formatBytes(d.usedBytes)} / {formatBytes(d.totalBytes)} {d.snapshotCount} {formatDate(d.latestSnapshotAt)} {verificationBadge(d)}
No datastores found.
{sortedDatastores?.some((d) => d.recentFailures.length > 0) && (

Recent verification failures

{sortedDatastores .flatMap((d) => d.recentFailures.map((f) => ({ datastore: d.name, ...f }))) .map((f, idx) => ( ))}
Datastore Backup When
{f.datastore} {f.backupType}/{f.backupId} {formatDate(f.backupTime)}
)}
)} )} ); }