addArgument('config', InputArgument::OPTIONAL, 'Configuration file', "config.yml"); } protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $io->title('Start backup process'); try { $app = new App($input->getArgument('config')); } catch (\Throwable $e) { $io->error('Unable to parse the YAML string: '. $e->getMessage()); return Command::FAILURE; } $rclone = new Rclone\Rclone(); $rclone->setLogger($app->getLogger()->withName('rclone')); $ntfy = new Ntfy\Ntfy($app->getConfig()['notification']['domain']); $ntfy->setLogger($app->getLogger()->withName('notification')); $loader = new ArrayLoader($app->getConfig()['templates']); $twig = new Environment($loader); $twig->addExtension(new Twig\AppExtension()); foreach ($io->progressIterate($app->getConfig()['backup']) as $conf) { try { $template = array(); $template['config'] = $conf; $template['start'] = new DateTime(); $template['source_size'] = $rclone->getSize($conf['source']); $template['destination_size_before'] = $rclone->getSize($conf['destination']); $rclone->copy($conf['source'], $conf['destination'], "6M"); $template['destination_size_after'] = $rclone->getSize($conf['destination']); $template['end'] = new DateTime(); $message = $twig->render('notify', $template); } catch (\Throwable $e) { $message = $e->getMessage(); } $ntfy->send($app->getConfig()['notification']['topic'], $conf['title'], $message); } $io->success("Complete"); return Command::SUCCESS; } }