Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 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 = '';
         }
     }
 }
Ejemplo n.º 3
0
 public function run($args)
 {
     $cli = new CLImate();
     $db = new LocalDB();
     $db->execute("SELECT * FROM users");
 }