예제 #1
0
 /**
  * @param \Cogeco\Build\Entity\Database $db
  * @param \Cogeco\Build\Entity\File $dumpFile
  * @param $dbName
  * @param array $tables
  * @throws \Cogeco\Build\Exception
  */
 public static function mysqlDump(Database $db, $dbName, array $tables = array(), File $dumpFile)
 {
     if (!is_array($tables) || count($tables) === 0) {
         $tablesParam = '';
     } else {
         $tablesParam = explode(' ', $tables) . ' ';
     }
     // Presentation
     self::log("- Getting dump of {$dbName}");
     if ($db->isRemote()) {
         Task::log(" from {$db->host->hostname}");
     }
     self::log("\n");
     // For use when converting a dump to SQLite
     // --compatible=ansi --skip-extended-insert --compact
     // Build the command
     $cmd = Config::get('mysqldump.bin') . " -vf -P {$db->port}";
     if ($db->isRemote()) {
         $cmd .= " -h {$db->host->hostname}";
     }
     // Create the folder if it doesn't exist already
     FileSystemTask::mkdir($dumpFile->dir->getPath());
     $cmd .= " -u {$db->account->username} -p{$db->account->password} {$dbName} {$tablesParam}| sed '/^\\/\\*\\!50013 DEFINER/d' > {$dumpFile->getPath()}";
     //$cmd .= " --result-file={$dumpFile->getPath()} -u {$db->account->username} -p{$db->account->password} {$dbName} {$tablesParam} 2>&1";
     self::runCmd($cmd);
     self::log("\n");
 }
예제 #2
0
 /**
  * Import a sql file into mysql by copying a temp file through SSH then importing it with mysql and deleting the
  * dump afterward
  * @param \Cogeco\Build\Entity\File $dumpFile
  * @param \Cogeco\Build\Entity\Database $db
  * @param $dbName
  * @throws \Cogeco\Build\Exception
  */
 public static function mysqlImport(File $dumpFile, Database $db, $dbName)
 {
     self::log("- Importing {$dumpFile->name} into {$dbName}\n");
     $command = "mysql -u {$db->account->username} -p{$db->account->password} {$dbName} < {$dumpFile->getPath()}";
     self::exec($db->getHost(), $command);
     self::log("\n");
 }