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(); $rclone->setLogger($app->getLogger()->withName('rclone')); $server = new Server($app->getConfig()['notification']['domain']); $client = new Client($server); $loader = new ArrayLoader($app->getConfig()['templates']); $twig = new Environment($loader); $twig->addExtension(new Twig\AppExtension()); foreach ($sio->progressIterate($app->getConfig()['backup']) as $conf) { $message = new Message(); $message->topic($app->getConfig()['notification']['topic']); $message->title($conf['title']); 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->body($twig->render('notify', $template)); } catch (\Throwable $e) { $message->body($e->getMessage()); $message->tags(["warning"]); } $client->send($message); } $sio->success("Complete"); return Command::SUCCESS; } }