public function run($args) { $cli = new CLImate(); $file_name = 'db_' . time() . '.sql'; $remote_file = Remote::getHomePath() . $file_name; $local_file = Local::getDocRoot() . "{$file_name}"; $ssh = SSHConnection::getInstance(); $ssh->exec('mysqldump -h ' . Setting::getSetting('mysql:host') . ' -u ' . Setting::getSetting('mysql:user') . ' -p' . addslashes(Setting::getSetting('mysql:pass')) . ' ' . Setting::getSetting('mysql:db') . " > " . $remote_file); $ssh->scpRemoteLocal($remote_file, $local_file); $ssh->rmRemoteFile($remote_file); $sql = file($local_file); $db = new LocalDB(); $templine = ''; $size = count($sql); $cli->out("Importing database"); $progress = $cli->progress()->total($size); $current = 0; foreach ($sql as $line) { $current++; // Skip it if it's a comment if (substr($line, 0, 2) == '--' || $line == '') { continue; } $templine .= $line; if (substr(trim($line), -1, 1) == ';') { $db->execute($templine); $progress->current($current); $templine = ''; } } unlink($local_file); }
public function run($args) { $cli = new CLImate(); $origin = Setting::getSetting('remote:user') . '@' . Setting::getSetting('remote:host') . ':' . Remote::getFilesPath(); $dest = Local::getFilesPath(); if (!file_exists($dest)) { if (!mkdir($dest, 0777, true)) { $cli->error('Could not create local files directory'); return false; } } $rsync = new Rsync(); $rsync->setVerbose(true); $rsync->setExclude(Setting::getSetting('rsync:excludes')); $rsync->sync($origin, $dest); }