setName('backup:cancel') ->setDescription('Stop a running backup') ->addArgument('run', InputArgument::REQUIRED, 'Run number, as shown by backup:status') ->setHelp("No new step of the run starts; the step in progress finishes first (usually within a " . "minute), so a backup that is just being completed is not cut off. The process working on the " . "run (occ backup:run, or cron) then stops. A backup started by an earlier version is marked " . "cancelled after two minutes and stops at the end of its step. What it already stored is " . "removed by the next cleanup."); } protected function execute(InputInterface $input, OutputInterface $output): int { $id = (string)$input->getArgument('run'); if (!ctype_digit($id)) { $output->writeln('Give the run number, as shown by backup:status.'); return 1; } try { $run = $this->runs->find((int)$id); } catch (DoesNotExistException) { $output->writeln("There is no run $id."); return 1; } if ($run->getKind() !== BackupService::KIND_FULL) { $output->writeln("Run $id is not a backup; only backups can be cancelled."); return 1; } if ($run->getStatus() === Run::RUNNING) { $output->writeln("Waiting for the current step of run $id to finish..."); } try { $run = $this->backups->cancel($run); } catch (\RuntimeException $e) { $output->writeln('' . $e->getMessage() . ''); return 1; } if ($run->getStatus() !== Run::CANCELLED) { $output->writeln("Run $id is not running (status: {$run->getStatus()}); nothing to cancel."); return 0; } $output->writeln("Run $id is cancelled."); return 0; } }