193f65940b
Both live in the catalog on the location, so a new server sees them; the database holds a local copy for the lists. The retention policy leaves a pinned restore point alone and does not count it. Available on the restore page and as occ backup:pin and backup:note.
54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
// SPDX-FileCopyrightText: 2026 Dillard Blom
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
namespace OCA\NgBackup\Command;
|
|
|
|
use OCA\NgBackup\Db\SnapshotMapper;
|
|
use OCA\NgBackup\Format;
|
|
use OCA\NgBackup\Service\Schedule;
|
|
use OCA\NgBackup\Service\TargetService;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Helper\Table;
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
final class ListSnapshots extends Command {
|
|
public function __construct(
|
|
private TargetService $targets,
|
|
private SnapshotMapper $snapshots,
|
|
private Schedule $schedule,
|
|
) {
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function configure(): void {
|
|
$this->setName('backup:list')
|
|
->setDescription('List the snapshots (restore points) on a location')
|
|
->addArgument('target', InputArgument::OPTIONAL, 'Location name or id (default: all)');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
|
$name = $input->getArgument('target');
|
|
$targets = $name === null ? $this->targets->list() : [$this->targets->get($name)];
|
|
$zone = $this->schedule->get()['timezone'];
|
|
$rows = [];
|
|
foreach ($targets as $t) {
|
|
foreach ($this->snapshots->findForTarget($t->getId()) as $s) {
|
|
$rows[] = [$t->getName(), $s->getSnapshotId(), Format::time($s->getCreatedAt(), $zone), $s->getKind(),
|
|
$s->getFiles(), sprintf('%.1f GiB', ($s->getBytes() ?? 0) / 1073741824), $s->getPinned() ? 'yes' : '', $s->getLabel() ?? '', $s->getNote() ?? ''];
|
|
}
|
|
}
|
|
if ($rows === []) {
|
|
$output->writeln('No snapshots yet (occ backup:run).');
|
|
return 0;
|
|
}
|
|
(new Table($output))->setHeaders(['location', 'snapshot', "date ($zone)", 'kind', 'files', 'size', 'pinned', 'label', 'note'])->setRows($rows)->render();
|
|
return 0;
|
|
}
|
|
}
|