Beispiel #1
0
		else
			$NS["step"]++;
	}

	// Step 6: Send to the cloud 
	if($NS["step"] == 6)
	{
		if ($NS['BUCKET_ID'])
		{
			if (haveTime())
			{
				if (!CModule::IncludeModule('clouds'))
					RaiseErrorAndDie(GetMessage("MAIN_DUMP_NO_CLOUDS_MODULE"));

				$file_size = filesize($NS["arc_name"]);
				$obUpload = new CCloudStorageUpload(substr($NS['arc_name'],strlen(DOCUMENT_ROOT)));
				if (!$obUpload->isStarted())
				{
					if (!$obUpload->Start(intval($NS['BUCKET_ID']), $file_size))
					{
						if ($e = $APPLICATION->GetException())
							$strError = $e->GetString();
						else
							$strError = GetMessage('MAIN_DUMP_INT_CLOUD_ERR');
						RaiseErrorAndDie($strError);
					}
				}

				if ($fp = fopen($NS['arc_name'],'rb'))
				{
					fseek($fp, $obUpload->getPos());
Beispiel #2
0
         }
     } else {
         $NS["step"]++;
     }
 }
 // Step 6: Send to the cloud
 if ($NS["step"] == 6) {
     $step_done = 0;
     if ($NS['BUCKET_ID']) {
         if (haveTime()) {
             if (!CModule::IncludeModule('clouds')) {
                 RaiseErrorAndDie(GetMessage("MAIN_DUMP_NO_CLOUDS_MODULE"));
             }
             $file_size = filesize($NS["arc_name"]);
             $file_name = $NS['BUCKET_ID'] == -1 ? basename($NS['arc_name']) : substr($NS['arc_name'], strlen(DOCUMENT_ROOT));
             $obUpload = new CCloudStorageUpload($file_name);
             if (!$NS['upload_start_time']) {
                 $NS['upload_start_time'] = START_EXEC_TIME;
             }
             if ($NS['BUCKET_ID'] == -1) {
                 if (!$bBitrixCloud) {
                     RaiseErrorAndDie(getMessage('DUMP_BXCLOUD_NA'));
                 }
                 $obBucket = null;
                 if (!$NS['obBucket']) {
                     $backup = CBitrixCloudBackup::getInstance();
                     $q = $backup->getQuota();
                     if ($e = $APPLICATION->GetException()) {
                         unset($NS['obBucket']);
                         RaiseErrorAndDie($e->GetString(), true);
                     } else {
Beispiel #3
0
 public static function MoveFile($arFile, $obTargetBucket)
 {
     $io = CBXVirtualIo::GetInstance();
     //Try to find suitable bucket for the file
     $bucket = CCloudStorage::FindBucketForFile($arFile, $arFile["FILE_NAME"]);
     if (!is_object($bucket)) {
         return CCloudStorage::FILE_SKIPPED;
     }
     if (!$bucket->Init()) {
         return CCloudStorage::FILE_SKIPPED;
     }
     //Check if this is same bucket as the target
     if ($bucket->ID != $obTargetBucket->ID) {
         return CCloudStorage::FILE_SKIPPED;
     }
     if ($bucket->FileExists($bucket->GetFileSRC($arFile))) {
         //TODO rename file
         return CCloudStorage::FILE_SKIPPED;
     }
     $filePath = "/" . $arFile["SUBDIR"] . "/" . $arFile["FILE_NAME"];
     $filePath = preg_replace("#[\\\\\\/]+#", "/", $filePath);
     if ($arFile["FILE_SIZE"] > $bucket->GetService()->GetMinUploadPartSize()) {
         $obUpload = new CCloudStorageUpload($filePath);
         if (!$obUpload->isStarted()) {
             if ($arFile["HANDLER_ID"]) {
                 $ar = array();
                 if (!CCloudStorage::OnMakeFileArray($arFile, $ar)) {
                     return CCloudStorage::FILE_SKIPPED;
                 }
                 if (!isset($ar["tmp_name"])) {
                     return CCloudStorage::FILE_SKIPPED;
                 }
             } else {
                 $ar = CFile::MakeFileArray($arFile["ID"]);
                 if (!isset($ar["tmp_name"])) {
                     return CCloudStorage::FILE_SKIPPED;
                 }
             }
             $temp_file = CTempFile::GetDirectoryName(2, "clouds") . bx_basename($arFile["FILE_NAME"]);
             $temp_fileX = $io->GetPhysicalName($temp_file);
             CheckDirPath($temp_fileX);
             if (!copy($io->GetPhysicalName($ar["tmp_name"]), $temp_fileX)) {
                 return CCloudStorage::FILE_SKIPPED;
             }
             if ($obUpload->Start($bucket->ID, $arFile["FILE_SIZE"], $arFile["CONTENT_TYPE"], $temp_file)) {
                 return CCloudStorage::FILE_PARTLY_UPLOADED;
             } else {
                 return CCloudStorage::FILE_SKIPPED;
             }
         } else {
             $temp_file = $obUpload->getTempFileName();
             $temp_fileX = $io->GetPhysicalName($temp_file);
             $fp = fopen($temp_fileX, "rb");
             if (!is_resource($fp)) {
                 return CCloudStorage::FILE_SKIPPED;
             }
             $pos = $obUpload->getPos();
             if ($pos > filesize($temp_fileX)) {
                 if ($obUpload->Finish()) {
                     $bucket->IncFileCounter(filesize($temp_fileX));
                     if ($arFile["HANDLER_ID"]) {
                         CCloudStorage::OnFileDelete($arFile);
                     } else {
                         $ar = CFile::MakeFileArray($arFile["ID"]);
                         $fileNameX = $io->GetPhysicalName($ar["tmp_name"]);
                         unlink($fileNameX);
                         @rmdir(substr($fileNameX, 0, -strlen(bx_basename($fileNameX))));
                     }
                     return CCloudStorage::FILE_MOVED;
                 } else {
                     return CCloudStorage::FILE_SKIPPED;
                 }
             }
             fseek($fp, $pos);
             self::$part_count = $obUpload->GetPartCount();
             self::$part_size = $obUpload->getPartSize();
             $part = fread($fp, self::$part_size);
             while ($obUpload->hasRetries()) {
                 if ($obUpload->Next($part)) {
                     return CCloudStorage::FILE_PARTLY_UPLOADED;
                 }
             }
             return CCloudStorage::FILE_SKIPPED;
         }
     } else {
         if ($arFile["HANDLER_ID"]) {
             $ar = array();
             if (!CCloudStorage::OnMakeFileArray($arFile, $ar)) {
                 return CCloudStorage::FILE_SKIPPED;
             }
             if (!isset($ar["tmp_name"])) {
                 return CCloudStorage::FILE_SKIPPED;
             }
         } else {
             $ar = CFile::MakeFileArray($arFile["ID"]);
             if (!isset($ar["tmp_name"])) {
                 return CCloudStorage::FILE_SKIPPED;
             }
         }
         $res = $bucket->SaveFile($filePath, $ar);
         if ($res) {
             $bucket->IncFileCounter(filesize($ar["tmp_name"]));
             if (file_exists($ar["tmp_name"])) {
                 unlink($ar["tmp_name"]);
                 @rmdir(substr($ar["tmp_name"], 0, -strlen(bx_basename($ar["tmp_name"]))));
             }
             if ($arFile["HANDLER_ID"]) {
                 CCloudStorage::OnFileDelete($arFile);
             }
         } else {
             //delete temporary copy
             if ($arFile["HANDLER_ID"]) {
                 unlink($ar["tmp_name"]);
                 @rmdir(substr($ar["tmp_name"], 0, -strlen(bx_basename($ar["tmp_name"]))));
             }
         }
         return $res ? CCloudStorage::FILE_MOVED : CCloudStorage::FILE_SKIPPED;
     }
 }
Beispiel #4
0
 }
 if (!$f) {
     break;
 }
 if (substr($ID, 0, 1) !== "F" || $obBucket->ACTIVE !== "Y" || $obBucket->READ_ONLY !== "N") {
     break;
 }
 $fp = $f->Open("rb");
 if (!is_resource($fp)) {
     $message = new CAdminMessage(GetMessage("CLO_STORAGE_FILE_UPLOAD_ERROR"), new CApplicationException(GetMessage("CLO_STORAGE_FILE_OPEN_ERROR")));
     break;
 }
 $bytes = 0;
 $fileSize = $f->GetFileSize();
 if ($fileSize > $obBucket->GetService()->GetMinUploadPartSize()) {
     $obUpload = new CCloudStorageUpload($filePath);
     if (!$obUpload->isStarted()) {
         if ($obBucket->FileExists($filePath)) {
             $message = new CAdminMessage(GetMessage("CLO_STORAGE_FILE_UPLOAD_ERROR"), new CApplicationException(GetMessage("CLO_STORAGE_FILE_EXISTS_ERROR")));
             break;
         }
         $tempFile = CTempFile::GetDirectoryName(6, "clouds_upload") . $f->GetName();
         $tempFileX = $io->GetPhysicalName($tempFile);
         CheckDirPath($tempFileX);
         if (copy($_FILES["upload"]["tmp_name"], $tempFileX)) {
             if ($obUpload->Start($obBucket->ID, $fileSize, CFile::GetContentType($tempFile), $tempFile)) {
                 $moveResult = CCloudStorage::FILE_PARTLY_UPLOADED;
             } else {
                 $strError = GetMessage("CLO_STORAGE_FILE_UNKNOWN_ERROR", array("#CODE#" => "e01"));
             }
         } else {
Beispiel #5
0
 /**
  * @param CWebDavTmpFile $file
  * @param                $startRange
  * @param                $endRange
  * @param                $fileSize
  * @return bool
  * @throws WebDavTmpFileErrorException
  */
 private function internalAppendCloud(CWebDavTmpFile $file, $startRange, $endRange, $fileSize)
 {
     $isLastChunk = $endRange + 1 == $fileSize;
     if (!CModule::IncludeModule("clouds")) {
         throw new WebDavTmpFileErrorException('Could not include clouds module');
     }
     $bucket = $this->getBucket();
     if ($endRange - $startRange + 1 != $bucket->getService()->getMinUploadPartSize() && !$isLastChunk) {
         throw new WebDavTmpFileErrorException('Error in size chunk. Must be equals ' . $bucket->getService()->getMinUploadPartSize() . ' if not last chunk');
     }
     $upload = new CCloudStorageUpload($this->path . '/' . $this->filename);
     if (!$upload->isStarted()) {
         if (!$upload->start($bucket->ID, $fileSize)) {
             throw new WebDavTmpFileErrorException('Could not start cloud upload');
         }
     }
     $success = false;
     $fileContent = $file->getContent();
     if ($fileContent === false) {
         throw new WebDavTmpFileErrorException('Could not get contents file');
     }
     $fails = 0;
     while ($upload->hasRetries()) {
         if ($upload->next($fileContent)) {
             $success = true;
             break;
         }
         $fails++;
     }
     if (!$success) {
         throw new WebDavTmpFileErrorException('Could not upload part of file for ' . $fails . ' times');
     } elseif ($success && $isLastChunk) {
         if ($upload->finish()) {
             //we don't  inc and don't dec
             //$bucket->incFileCounter($fileSize);
         } else {
             throw new WebDavTmpFileErrorException('Could not finish resumable upload');
         }
         return true;
     } elseif ($success) {
         return true;
     }
 }
Beispiel #6
0
			RaiseErrorAndDie(implode('<br>',$tar->err));
	}
	$tar->close();
}

if (IntOption('dump_send_to_bucket_id'))
{
	ShowBackupStatus('Sending backup to the cloud...');
	if (!CModule::IncludeModule('clouds'))
		RaiseErrorAndDie(GetMessage("MAIN_DUMP_NO_CLOUDS_MODULE"));

	while(haveTime())
	{
	xdebug_start_trace();
		$file_size = filesize($NS["arc_name"]);
		$obUpload = new CCloudStorageUpload(substr($NS['arc_name'],strlen(DOCUMENT_ROOT)));
		if (!$obUpload->isStarted())
		{
			if (!$obUpload->Start(IntOption('dump_send_to_bucket_id'), $file_size))
			{
				if ($e = $APPLICATION->GetException())
					$strError = $e->GetString();
				else
					$strError = GetMessage('MAIN_DUMP_INT_CLOUD_ERR');
				RaiseErrorAndDie($strError);
			}
		}

		if (!$fp = fopen($NS['arc_name'],'rb'))
			RaiseErrorAndDie(GetMessage("MAIN_DUMP_ERR_OPEN_FILE").$NS['arc_name']);