/** * @return mixed */ public function doBackup() { $date = date('YmdHisO'); $dumpName = trim($this->options->getPath() . $date . '.sql', '/'); switch ($this->dumperOptions->getCompress()) { case Mysqldump::GZIP: $dumpName = $dumpName . '.gz'; break; case Mysqldump::BZIP2: $dumpName = $dumpName . '.bz2'; break; } $tmpFile = tempnam(sys_get_temp_dir(), 'bsb-flysystem-mysql-backup-'); $fileStream = fopen($tmpFile, 'rb'); try { if (false === $fileStream) { throw new \RuntimeException("A temp file could not be created"); } // start dump and backup $this->dumper->start($tmpFile); $this->filesystem->writeStream($dumpName, $fileStream); // write a latest file if ($this->options->getWriteLatest()) { $this->filesystem->put($this->options->getPath() . $this->options->getWriteLatest(), pathinfo($dumpName, PATHINFO_BASENAME)); } if ($this->options->getAutoPrune()) { $this->pruneStorage(); } } catch (\Exception $e) { throw new \RuntimeException($e->getMessage()); } finally { if (is_resource($fileStream)) { fclose($fileStream); } if (file_exists($tmpFile)) { unlink($tmpFile); } } return $dumpName; }
/** * MysqlDumperService constructor. * * @param string $dsn * @param string $user * @param string $pass * @param MysqlDumperOptions $dumpSettings * @param array $pdoSettings */ public function __construct($dsn = '', $user = '', $pass = '', MysqlDumperOptions $dumpSettings, $pdoSettings = []) { parent::__construct($dsn, $user, $pass, $dumpSettings->toDumperArray(), $pdoSettings); }