/** * Import the database dump by running mysql from the command line (assumes Bash?) * * @param BaseModel $settings The task's settings * @param mixed $arg An optional second argument * * @return bool */ public function importBackup($settings, $arg = null) { $keepAfterCopy = $this->getSettings()['importBackup']['keepBackup'] === '1' ? true : false; $pathToBackup = craft()->path->getDbBackupPath() . StringHelper::toLowerCase(IOHelper::cleanFilename($settings->backupFileName)); $destination = $this->getSettings()['copyBackup']['destination']; $destination = rtrim($destination, '/') . '/'; $destination = $destination . basename($pathToBackup); $sshHostname = $this->getSettings()['ssh']['remote']['hostname']; $sshUsername = $this->getSettings()['ssh']['remote']['username']; $sshPassword = craft()->goLive_security->decrypt($this->getSettings()['ssh']['remote']['password']); $mysqlHostname = $this->getSettings()['mysql']['hostname']; $mysqlUsername = $this->getSettings()['mysql']['username']; $mysqlPassword = craft()->goLive_security->decrypt($this->getSettings()['mysql']['password']); $mysqlDb = $this->getSettings()['mysql']['dbname']; $ssh = new Net_SSH2($sshHostname); $ssh->login($sshUsername, $sshPassword); $commands = array(array('command' => sprintf('mysql -h %s -u %s -p%s %s < %s', $mysqlHostname, $mysqlUsername, $mysqlPassword, $mysqlDb, $destination), 'output' => '')); if (!$keepAfterCopy) { array_push($commands, array('command' => sprintf('rm %s', $destination), 'output' => '')); } for ($i = 0; $i < count($commands); $i++) { $commands[$i]['output'] = $ssh->exec($commands[$i]['command']); } return true; }