_networkMounted) { $this->Debug("Desconectando do host '{$this->GetInfo('host')}'"); $this->sys(sprintf("umount -f %s", $this->_diretorioRedeLocal)); $this->Debug("Desconectado do host '{$this->GetInfo('host')}'"); } else { $this->Debug("Nenhum mapeameto de rede ativo para desmontar"); } $this->Debug(self::$BACKUP_FINALIZADO); } public function Connect(BackupInfo $backup) { $this->backup = $backup; $this->Debug("Conectando ao host '{$this->backup->host}' na rede..."); $host = str_replace("\\", "/", $this->backup->host . $this->backup->dir); $aut = $this->backup->anon ? "guest" : sprintf("username=%s,pass=%s", $this->backup->user, $this->backup->pass); if (!file_exists($this->_diretorioRedeLocal)) { $this->Debug("'{$this->_diretorioRedeLocal}' não existe. Criando diretório..."); $this->sys(sprintf("mkdir -o %s", $this->_diretorioRedeLocal)); if (!file_exists($this->_diretorioRedeLocal)) { $this->Error("Não foi possível criar o diretório '{$this->_diretorioRedeLocal}' para mapeamento da rede"); return false; } $this->Debug("Diretório criado"); } if (!is_readable($this->_diretorioRedeLocal)) { $this->Error("Sem permissão de leitura para o diretório {$this->_diretorioRedeLocal}"); return false; } else { if (!is_writable($this->_diretorioRedeLocal)) { $this->Error("Sem permissão de escrita para o diretório {$this->_diretorioRedeLocal}"); return false; } } // mount -t cifs -o username=user,pass=SimpleS_root //192.168.115.139/Downloads/ /mnt/bk_simples/ $cmd = sprintf("mount -t cifs -o %s %s %s", $aut, $host, $this->_diretorioRedeLocal); $this->Debug("Montando mapeamento de unidade do host na rede..."); $output = $this->sys($cmd); if (is_null($output)) { $this->Debug("Não foi possível conectar ao host"); return false; } if (StringClass::ContemTexto($output, "exclusiva de root")) { $this->Error($output); return false; } $this->Debug("Mapeamento concluído com sucesso"); $this->backup->dirAtual = $host; $this->_networkMounted = true; return true; } public function Upload(array $dadosArquivo, $remoteFile) { $localFile = $dadosArquivo['file']; $hash = $dadosArquivo['hash']; $arquivoCopiado = sprintf("%s%s", $this->_diretorioRedeLocal, $remoteFile); $cmd = sprintf("cp -u %s %s", $localFile, $arquivoCopiado); $this->Debug("Copiando arquivos de backup para o host na rede..."); $result = $this->sys($cmd); if (!file_exists($arquivoCopiado)) { $this->Error("Não foi possível gravar o arquivo remoto!\n" . $cmd); return false; } $remoto = str_replace("\\", "/", $this->backup->host . $this->backup->dir . $remoteFile); $this->Debug("Backup copiado para [$remoto]"); //apaga arquivo local $this->unlink($localFile); return $this->CheckHash($hash, $arquivoCopiado); } }