setName("backup") ->addArgument( 'destination', InputArgument::OPTIONAL, 'Where to store the backup (/backup is default)' ) ->setDescription("Creates a backup of the Grav instance") ->setHelp('The backup creates a zipped backup. Optionally can be saved in a different destination.'); $this->source = getcwd(); } /** * @return int|null|void */ protected function serve() { $this->progress = new ProgressBar($this->output); $this->progress->setFormat('Archiving %current% files [%bar%] %elapsed:6s% %memory:6s%'); Grav::instance()['config']->init(); $destination = ($this->input->getArgument('destination')) ? $this->input->getArgument('destination') : null; $log = JsonFile::instance(Grav::instance()['locator']->findResource("log://backup.log", true, true)); $backup = ZipBackup::backup($destination, [$this, 'output']); $log->content([ 'time' => time(), 'location' => $backup ]); $log->save(); $this->output->writeln(''); $this->output->writeln(''); } /** * @param $args */ public function output($args) { switch ($args['type']) { case 'message': $this->output->writeln($args['message']); break; case 'progress': if ($args['complete']) { $this->progress->finish(); } else { $this->progress->advance(); } break; } } }