예제 #1
0
파일: CmdBackup.php 프로젝트: point/cassea
 public function createMySQL($root, $name, $separate = null)
 {
     if (file_exists($root . '/' . $name . "_" . date('Ymd') . ".sql.bz2")) {
         $sqlname = $name . "_" . date('Ymd_H_i_s') . '.sql';
     } else {
         $sqlname = $name . "_" . date('Ymd') . '.sql';
     }
     $db = Config::getInstance()->db;
     $db = parse_url($db);
     io::out("Creating Mysql dump .....", false);
     $cmd = 'mysqldump -R -q --single-transaction ' . trim($db['path'], '/') . ' -u' . $db['user'] . ' --password='******'pass']) ? $db['pass'] : "") . ' --result-file=' . $root . '/' . $sqlname . '  2>&1';
     exec($cmd, $out, $return);
     if ($return) {
         io::OUt();
         if (IO::getVerboseLevel() > IO::MESSAGE_FAIL) {
             io::out('mysqldump return code ' . print_r($return, true), IO::MESSAGE_FAIL);
             io::out('~WHITE~Command~~~: ' . $cmd);
             IO::out('~WHITE~Output ~~~:' . implode(PHP_EOL, $out));
         }
         throw new ConsoleException('mysqldump finished with errors: ' . PHP_EOL . implode(PHP_EOL, $out));
     }
     if ($separate) {
         $cmd = 'bzip2 -9 ' . $root . '/' . $sqlname . ' 2>&1';
         exec($cmd, $out, $return);
         if (!$return) {
             $sqlname .= '.bz2';
         } else {
             io::OUt();
             if (IO::getVerboseLevel() > IO::MESSAGE_FAIL) {
                 io::out('Bzip  return code ' . print_r($return, true), IO::MESSAGE_FAIL);
                 io::out('~WHITE~Command~~~: ' . $cmd);
                 IO::out('~WHITE~Output ~~~:' . implode(PHP_EOL, $out));
             }
             throw new ConsoleException('Bzip finished with errors: ' . PHP_EOL . implode(PHP_EOL, $out));
         }
     }
     io::done();
     return $sqlname;
 }