public static function backupdb() { $backUpdir = SystemUtil::getUploadTmpPath(); $backUpdir .= DIRECTORY_SEPARATOR . uniqid(mt_rand()) . '.txt'; $dbSetting = array('exclude' => array('session', 'cache')); $dump = new MySQLDumper(ServiceKernel::instance()->getConnection(), $dbSetting); return $dump->export($backUpdir); }
public function backupDbForPackageUpdate($packageId) { $errors = array(); try { $filesystem = new Filesystem(); $package = $this->getCenterPackageInfo($packageId); if (empty($package)) { $errors[] = "获取应用包#{$packageId}信息失败"; goto last; } if (empty($package['backupDB'])) { goto last; } $dumper = new MySQLDumper($this->getKernel()->getConnection(), array('exclude' => array('session', 'cache'))); $targetBaseDir = "{$this->getBackUpDirectory()}/{$package['id']}_{$package['type']}_{$package['fromVersion']}_to_{$package['toVersion']}_db"; $dumper->export($targetBaseDir); } catch (\Exception $e) { $errors[] = $e->getMessage(); } last: $this->_submitRunLogForPackageUpdate('备份数据库', $package, $errors); return $errors; }