202 lines
11 KiB
PHP
202 lines
11 KiB
PHP
|
|
<?php
|
|||
|
|
/** @var list<array{name: string, size: int, created_at: string, reason: string, rows: ?int, files: ?int, files_bytes: ?int, manual: bool}> $backups */
|
|||
|
|
/** @var int $keep */
|
|||
|
|
/** @var array<string, string> $errors */
|
|||
|
|
/** @var array{archive: string, statements: int, rows_before: int, files: int, safety: ?string, warnings: list<string>}|null $restoreResult */
|
|||
|
|
/** @var string $directory */
|
|||
|
|
/** @var int $maxMb */
|
|||
|
|
/** @var bool $available */
|
|||
|
|
$error = static fn (string $key): string => (string) ($errors[$key] ?? '');
|
|||
|
|
$totalSize = 0;
|
|||
|
|
foreach ($backups as $item) {
|
|||
|
|
$totalSize += $item['size'];
|
|||
|
|
}
|
|||
|
|
?>
|
|||
|
|
<div class="page-head page-head--compact">
|
|||
|
|
<div>
|
|||
|
|
<p class="eyebrow">Verwaltung</p>
|
|||
|
|
<h1>Sicherungen</h1>
|
|||
|
|
<p class="page-head__lede">Eine Sicherung enthält die komplette Datenbank und alle abgelegten
|
|||
|
|
Dateien (Buchungsunterlagen, Unterschriften) in einem Archiv. Sie können sie hier
|
|||
|
|
herunterladen, eine fremde Sicherung hochladen und den Stand wieder einspielen.</p>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<?php require __DIR__ . '/_admin_nav.php'; ?>
|
|||
|
|
|
|||
|
|
<?php if ($error('general') !== ''): ?>
|
|||
|
|
<div class="alert alert--error" role="alert">
|
|||
|
|
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
|||
|
|
<div><strong>Das hat nicht geklappt.</strong><p><?= e($error('general')) ?></p></div>
|
|||
|
|
</div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
|
|||
|
|
<?php if (!$available): ?>
|
|||
|
|
<div class="alert alert--error" role="alert">
|
|||
|
|
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
|
|||
|
|
<div><strong>Die PHP-Erweiterung <code>Phar</code> fehlt.</strong>
|
|||
|
|
<p>Ohne sie lassen sich keine Archive schreiben oder lesen. Sicherungen sind deshalb
|
|||
|
|
gesperrt; bitte beim Hoster prüfen.</p>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
|
|||
|
|
<?php if ($restoreResult !== null): ?>
|
|||
|
|
<section class="panel">
|
|||
|
|
<div class="panel__head">
|
|||
|
|
<div>
|
|||
|
|
<h2>Wiederherstellung abgeschlossen</h2>
|
|||
|
|
<p>Aus <code><?= e($restoreResult['archive']) ?></code> wurden
|
|||
|
|
<?= (int) $restoreResult['statements'] ?> SQL-Anweisungen ausgeführt und
|
|||
|
|
<?= (int) $restoreResult['files'] ?> Dateien übernommen.</p>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
<p class="muted small">Vor dem Einspielen wurde automatisch eine Sicherheitskopie angelegt<?= $restoreResult['safety'] !== null ? ' (<code>' . e((string) $restoreResult['safety']) . '</code>)' : '' ?>.
|
|||
|
|
Falls die Anmeldung nicht mehr gilt, hat sich der Benutzerstand geändert – dann bitte neu anmelden.</p>
|
|||
|
|
<?php foreach ($restoreResult['warnings'] as $warning): ?>
|
|||
|
|
<p class="muted small">Hinweis: <?= e($warning) ?></p>
|
|||
|
|
<?php endforeach; ?>
|
|||
|
|
</section>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
|
|||
|
|
<section class="panel">
|
|||
|
|
<div class="panel__head">
|
|||
|
|
<div>
|
|||
|
|
<h2>Neue Sicherung</h2>
|
|||
|
|
<p>Läuft im Hintergrund des Aufrufs und dauert je nach Datenmenge einige Sekunden.
|
|||
|
|
Die letzten <?= (int) $keep ?> Sicherungen bleiben erhalten<?= $keep === 0 ? ' (Aufräumen ist ausgeschaltet)' : '' ?>.</p>
|
|||
|
|
</div>
|
|||
|
|
<div class="panel__actions">
|
|||
|
|
<form method="post" action="<?= e(url('/admin/backups')) ?>">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="action" value="create">
|
|||
|
|
<button class="btn primary" type="submit"<?= $available ? '' : ' disabled' ?>>
|
|||
|
|
<svg class="ico" aria-hidden="true"><use href="#i-download"/></svg> Sicherung jetzt erstellen
|
|||
|
|
</button>
|
|||
|
|
</form>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
<p class="muted small">Ablage: <code><?= e($directory) ?></code> ·
|
|||
|
|
<?= count($backups) ?> Archiv<?= count($backups) === 1 ? '' : 'e' ?> ·
|
|||
|
|
<?= e(backup_human_size($totalSize)) ?> belegt</p>
|
|||
|
|
|
|||
|
|
<details class="create-trailer">
|
|||
|
|
<summary class="btn small create-trailer__summary">
|
|||
|
|
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Sicherung hochladen
|
|||
|
|
</summary>
|
|||
|
|
<div class="create-trailer__body">
|
|||
|
|
<p class="muted small">Ein Archiv aus dieser Anwendung (<code>*.tar.gz</code>, höchstens
|
|||
|
|
<?= (int) $maxMb ?> MB). Die Prüfsumme des Datenbank-Dumps wird beim Hochladen geprüft.</p>
|
|||
|
|
<form method="post" action="<?= e(url('/admin/backups')) ?>" enctype="multipart/form-data" class="form-grid">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="action" value="upload">
|
|||
|
|
<label class="field field--full">
|
|||
|
|
<span>Archiv</span>
|
|||
|
|
<input type="file" name="archive" accept=".gz,.tar.gz,application/gzip" required>
|
|||
|
|
</label>
|
|||
|
|
<div class="form-actions field--full">
|
|||
|
|
<button class="btn" type="submit"<?= $available ? '' : ' disabled' ?>>Hochladen</button>
|
|||
|
|
</div>
|
|||
|
|
</form>
|
|||
|
|
</div>
|
|||
|
|
</details>
|
|||
|
|
</section>
|
|||
|
|
|
|||
|
|
<section class="panel">
|
|||
|
|
<div class="panel__head">
|
|||
|
|
<div>
|
|||
|
|
<h2>Vorhandene Sicherungen</h2>
|
|||
|
|
<p>Neueste zuerst. Herunterladen zur Aufbewahrung außerhalb des Servers ist empfohlen –
|
|||
|
|
ein Archiv enthält personenbezogene Daten.</p>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<?php if ($backups === []): ?>
|
|||
|
|
<p class="muted">Noch keine Sicherung vorhanden.</p>
|
|||
|
|
<?php else: ?>
|
|||
|
|
<div class="table-wrap">
|
|||
|
|
<table class="data-table">
|
|||
|
|
<thead>
|
|||
|
|
<tr>
|
|||
|
|
<th>Archiv</th>
|
|||
|
|
<th>Stand</th>
|
|||
|
|
<th>Inhalt</th>
|
|||
|
|
<th>Größe</th>
|
|||
|
|
<th class="ta-right">Aktionen</th>
|
|||
|
|
</tr>
|
|||
|
|
</thead>
|
|||
|
|
<tbody>
|
|||
|
|
<?php foreach ($backups as $item): ?>
|
|||
|
|
<tr>
|
|||
|
|
<td>
|
|||
|
|
<strong><?= e($item['name']) ?></strong>
|
|||
|
|
<?php if ($item['reason'] !== ''): ?>
|
|||
|
|
<small class="muted">
|
|||
|
|
<?= $item['reason'] === 'vor-restore' ? 'Sicherheitskopie vor Wiederherstellung' : ($item['reason'] === 'cron' ? 'automatisch (Cron)' : e($item['reason'])) ?>
|
|||
|
|
</small>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
</td>
|
|||
|
|
<td><?= e(fmt_datetime($item['created_at'])) ?></td>
|
|||
|
|
<td class="small">
|
|||
|
|
<?php if ($item['rows'] === null): ?>
|
|||
|
|
<span class="muted">keine Angaben</span>
|
|||
|
|
<?php else: ?>
|
|||
|
|
<?= (int) $item['rows'] ?> Zeilen ·
|
|||
|
|
<?= (int) ($item['files'] ?? 0) ?> Dateien
|
|||
|
|
<?php endif; ?>
|
|||
|
|
</td>
|
|||
|
|
<td><?= e(backup_human_size($item['size'])) ?></td>
|
|||
|
|
<td class="ta-right">
|
|||
|
|
<div class="danger-actions">
|
|||
|
|
<a class="btn small" href="<?= e(url('/admin/backups/' . rawurlencode($item['name']) . '/download')) ?>">
|
|||
|
|
<svg class="ico" aria-hidden="true"><use href="#i-download"/></svg> Herunterladen
|
|||
|
|
</a>
|
|||
|
|
<details>
|
|||
|
|
<summary class="btn small">Einspielen…</summary>
|
|||
|
|
<form method="post" action="<?= e(url('/admin/backups')) ?>"
|
|||
|
|
class="stack"
|
|||
|
|
data-confirm="Sicherung „<?= e($item['name']) ?>“ wirklich einspielen? Der aktuelle Stand wird dabei überschrieben.">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="action" value="restore">
|
|||
|
|
<input type="hidden" name="name" value="<?= e_attr($item['name']) ?>">
|
|||
|
|
<label class="check">
|
|||
|
|
<input type="checkbox" name="restore_database" value="1" checked>
|
|||
|
|
<span>Datenbank</span>
|
|||
|
|
</label>
|
|||
|
|
<label class="check">
|
|||
|
|
<input type="checkbox" name="restore_files" value="1" checked>
|
|||
|
|
<span>Dateien</span>
|
|||
|
|
</label>
|
|||
|
|
<label class="field">
|
|||
|
|
<span>Zur Bestätigung <code>WIEDERHERSTELLEN</code> eingeben</span>
|
|||
|
|
<input type="text" name="confirm" value="" autocomplete="off" required>
|
|||
|
|
</label>
|
|||
|
|
<button class="btn small danger" type="submit">
|
|||
|
|
<svg class="ico" aria-hidden="true"><use href="#i-return"/></svg> Jetzt einspielen
|
|||
|
|
</button>
|
|||
|
|
<p class="muted small">Vorher wird automatisch eine Sicherheitskopie des
|
|||
|
|
aktuellen Stands angelegt.</p>
|
|||
|
|
</form>
|
|||
|
|
</details>
|
|||
|
|
<form method="post" action="<?= e(url('/admin/backups')) ?>"
|
|||
|
|
data-confirm="Sicherung „<?= e($item['name']) ?>“ endgültig löschen?">
|
|||
|
|
<?= csrf_field() ?>
|
|||
|
|
<input type="hidden" name="action" value="delete">
|
|||
|
|
<input type="hidden" name="name" value="<?= e_attr($item['name']) ?>">
|
|||
|
|
<button class="btn small danger-ghost" type="submit">
|
|||
|
|
<svg class="ico" aria-hidden="true"><use href="#i-trash"/></svg> Löschen
|
|||
|
|
</button>
|
|||
|
|
</form>
|
|||
|
|
</div>
|
|||
|
|
</td>
|
|||
|
|
</tr>
|
|||
|
|
<?php endforeach; ?>
|
|||
|
|
</tbody>
|
|||
|
|
</table>
|
|||
|
|
</div>
|
|||
|
|
<?php endif; ?>
|
|||
|
|
|
|||
|
|
<p class="muted small">Auf der Kommandozeile: <code>php tools/backup.php create</code> ·
|
|||
|
|
Automatisch per Cron: <code>/cron/backup?token=…</code> mit <code>app.cron_token</code>.</p>
|
|||
|
|
</section>
|