forked from SimplesIP/pabx-app
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.6 KiB
51 lines
1.6 KiB
<?php |
|
|
|
/** |
|
* Description of BackupLocal |
|
* |
|
* @author Victor |
|
*/ |
|
final class BackupLocal extends AbstractLocalLan { |
|
|
|
public function __destruct() { |
|
$this->Debug(self::$BACKUP_FINALIZADO); |
|
} |
|
|
|
public function Connect(BackupInfo $backup) { |
|
$this->backup = $backup; |
|
$this->Debug("Iniciando processo de backup"); |
|
if (!file_exists($this->backup->dir)) { |
|
$this->Error("O diretório de destino '{$this->backup->dir}' não existe"); |
|
|
|
return false; |
|
} |
|
if (!is_dir($this->backup->dir)) { |
|
$this->Error("O destino '{$this->backup->dir}' não é um diretório válido!"); |
|
|
|
return false; |
|
} |
|
$this->Debug("Diretório '{$this->backup->dir}' encontrado"); |
|
$this->_handler = $this->backup->dir; |
|
$this->backup->dirAtual = $this->backup->dir; |
|
|
|
return true; |
|
} |
|
|
|
public function Upload(array $dadosArquivo, $remoteFile) { |
|
$localFile = $dadosArquivo['file']; |
|
$hash = $dadosArquivo['hash']; |
|
$cmd = sprintf("cp -u %s %s%s", $localFile, $this->backup->dirAtual, $remoteFile); |
|
$debugMsg = sprintf("Iniciando cópia do arquivo '%s' para '%s%s%s'...", $localFile, $this->GetInfo('host'), $this->GetInfo('dir'), $remoteFile); |
|
$this->Debug($debugMsg); |
|
$result = $this->sys($cmd); |
|
if (!file_exists(sprintf("%s%s", $this->backup->dirAtual, $remoteFile))) { |
|
$this->Error("Não foi possível gravar o arquivo remoto!"); |
|
|
|
return false; |
|
} |
|
$this->Debug("Cópia concluído com sucesso"); |
|
|
|
return $this->CheckHash($hash, $this->backup->dirAtual . $remoteFile); |
|
} |
|
|
|
}
|
|
|