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(); $backup_dir = Setting::getSetting('consh:db_backup_folder'); if (!file_exists($backup_dir)) { if (!mkdir($backup_dir, 0777, true)) { $cli->error("Could not create database backup folder: {$backup_dir}"); return false; } } if (count($args) != 1) { $cli->error("Please pass along the filename to import"); if ($handle = opendir($backup_dir)) { $cli->out("possible files:"); while (false !== ($entry = readdir($handle))) { if ($entry != '.' && $entry != '..') { $cli->out($entry); } } } else { $cli->error("Could not open database backup folder"); } return false; } $file = $args[0]; $path = $backup_dir . "/" . $file; if (!file_exists($path)) { $cli->error("{$file} does not exist"); return false; } $sql = file($path); $db = new LocalDB(); $templine = ''; $size = count($sql); $cli->out("Restoring 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 = ''; } } }
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); }
public function run($args) { $cli = new CLImate(); $file_name = 'db_' . time() . '.sql'; $remote_file = Remote::getHomePath() . $file_name; $local_file = Setting::getSetting('consh:db_backup_folder') . "/{$file_name}"; if (!file_exists(Setting::getSetting('consh:db_backup_folder'))) { if (!mkdir(Setting::getSetting('consh:db_backup_folder'), 0777, true)) { $cli->error("Could not create database backup folder: " . Setting::getSetting('consh:db_backup_folder')); return false; } } $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); $cli->out("File saved to {$local_file}"); }