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