public function postRestore() { // validasi $input = Input::all(); $rules = array('sql' => 'required|sql'); $validasi = Validator::make(Input::all(), $rules); // tidak valid if ($validasi->fails()) { // pesan $sql = $validasi->messages()->first('sql') ?: ''; return Response::json(compact('sql')); // valid } else { // ada sql if (Input::hasFile('sql')) { // nama sql $sql = date('dmYHis') . '.sql'; // unggah sql ke dir "app/storage/restores" Input::file('sql')->move(storage_path() . '/restores/', $sql); // path file $file = storage_path() . '/restores/' . $sql; // dump database $dump = new Dump(); $dump->file($file)->dsn($this->dsn)->user($this->user)->pass($this->pass); new Import($dump); // hapus file restore unlink($file); // tidak ada sql } else { // pesan $sql = 'Sql gagal diunggah.'; return Response::json(compact('sql')); } } }
public function dumpMysqlDatabase($config, $filename) { $service = App::make('Tee\\Backup\\Services\\BackupService'); $username = $config['username']; $password = $config['password']; $database = $config['database']; $host = $config['host']; $dump = new Dump(); $dump->file($filename)->dsn("mysql:dbname={$database};host={$host}")->user($username)->pass($password)->tmp($service->getTemporaryDirectory()); new Export($dump); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $database = wire('config')->dbName; $host = wire('config')->dbHost; $user = wire('config')->dbUser; $pass = wire('config')->dbPass; $filename = $input->getOption('filename') ? $input->getOption('filename') . '.sql' : 'dump-' . date("Y-m-d-H-i-s") . '.sql'; try { $dump = new Dump(); $dump->file($filename)->dsn("mysql:dbname={$database};host={$host}")->user($user)->pass($pass)->tmp(getcwd() . 'site/assets/tmp'); new Export($dump); } catch (Exception $e) { echo 'Export failed with message: ' . $e->getMessage(); } $output->writeln("<info>Dumped database into {$filename} successfully.</info>"); }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { parent::bootstrapProcessWire($output); $config = \ProcessWire\wire('config'); $database = $config->dbName; $host = $config->dbHost; $user = $config->dbUser; $pass = $config->dbPass; $filename = $input->getOption('filename') ? $input->getOption('filename') . '.sql' : 'dump-' . date("Y-m-d-H-i-s") . '.sql'; $target = $input->getOption('target') ? $input->getOption('target') : ''; if ($target && !preg_match('/$\\//', $target)) { $target = "{$target}/"; } try { $dump = new Dump(); $dump->file($target . $filename)->dsn("mysql:dbname={$database};host={$host}")->user($user)->pass($pass)->tmp(getcwd() . 'site/assets/tmp'); new Export($dump); } catch (Exception $e) { $output->writeln("<error>Export failed with message: {$e->getMessage()}. Please make sure that the provided target exists.</error>"); exit(1); } $output->writeln("<info>Dumped database into `{$target}{$filename}` successfully.</info>"); }