コード例 #1
0
ファイル: Pull.php プロジェクト: VonUniGE/consh
 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);
 }
コード例 #2
0
ファイル: Backup.php プロジェクト: VonUniGE/consh
 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}");
 }