CanDoOperation('edit_php')) $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED")); if(!defined("START_EXEC_TIME")) define("START_EXEC_TIME", microtime(true)); IncludeModuleLangFile(__FILE__); require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/classes/general/backup.php"); $strBXError = ''; $bGzip = function_exists('gzcompress'); $encrypt = function_exists('openssl_encrypt'); $bHash = function_exists('hash'); $bBitrixCloud = $encrypt && $bHash; if (!CModule::IncludeModule('bitrixcloud')) { $bBitrixCloud = false; $strBXError = GetMessage('ERR_NO_BX_CLOUD'); } elseif (!CModule::IncludeModule('clouds')) { $bBitrixCloud = false; $strBXError = GetMessage('ERR_NO_CLOUDS'); } if($bBitrixCloud) { $backup = CBitrixCloudBackup::getInstance(); $arFiles = $backup->listFiles(); $backup->saveToOptions(); } define('DOCUMENT_ROOT', rtrim(str_replace('\\','/',$_SERVER['DOCUMENT_ROOT']),'/')); // define('DUMP_DEBUG_MODE', true); // xdebug_start_trace(); $arAllBucket = CBackup::GetBucketList(); $status_title = ""; if (isset($_REQUEST['ajax_mode']) && $_REQUEST['ajax_mode'] == 'Y') { if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'get_table_size') { ?> getSession()['BX_DUMP_STATE']; if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'start') { define('NO_TIME', true); $bFull = isset($_REQUEST['dump_all']) && $_REQUEST['dump_all'] == 'Y'; if(!file_exists(DOCUMENT_ROOT.BX_ROOT."/backup")) mkdir(DOCUMENT_ROOT.BX_ROOT."/backup", BX_DIR_PERMISSIONS); if(!file_exists(DOCUMENT_ROOT.BX_ROOT."/backup/index.php")) { $f = fopen(DOCUMENT_ROOT.BX_ROOT."/backup/index.php","w"); fwrite($f,""); fclose($f); } if(!is_dir(DOCUMENT_ROOT.BX_ROOT."/backup") || !is_writable(DOCUMENT_ROOT.BX_ROOT."/backup")) RaiseErrorAndDie(GetMessage("MAIN_DUMP_FOLDER_ERR",array('#FOLDER#' => DOCUMENT_ROOT.BX_ROOT.'/backup'))); DeleteDirFilesEx(BX_ROOT.'/backup/clouds'); $NS = Array(); $NS['finished_steps'] = 0; $NS['dump_state'] = ''; $NS['BUCKET_ID'] = intval($_REQUEST['dump_bucket_id'] ?? 0); COption::SetOptionInt("main", "dump_bucket_id", $NS['BUCKET_ID']); if ($encrypt && !empty($_REQUEST['dump_encrypt_key'])) { $NS['dump_encrypt_key'] = $_REQUEST['dump_encrypt_key']; COption::SetOptionInt("main", "dump_encrypt", 1); } else COption::SetOptionInt("main", "dump_encrypt", 0); if ($NS['BUCKET_ID'] == -1 && !$NS['dump_encrypt_key']) RaiseErrorAndDie(GetMessage('MAIN_DUMP_BXCLOUD_ENC')); $bUseCompression = $bGzip && (!isset($_REQUEST['dump_disable_gzip']) || $_REQUEST['dump_disable_gzip'] != 'Y' || $bFull); COption::SetOptionInt("main", "dump_use_compression", $bUseCompression); if ($bFull) { $NS['total_steps'] = 4; // dump, tar dump, tar files, integrity COption::SetOptionInt("main", "dump_max_exec_time", 20); COption::SetOptionInt("main", "dump_max_exec_time_sleep", 1); COption::SetOptionInt("main", "dump_archive_size_limit", 100 * 1024 * 1024); COption::SetOptionInt("main", "dump_integrity_check", 1); COption::SetOptionInt("main", "dump_max_file_size", 0); COption::SetOptionInt("main", "dump_file_public", 1); COption::SetOptionInt("main", "dump_file_kernel", 1); COption::SetOptionInt("main", "dump_base", $DB->type == 'MYSQL' ? 1 : 0); COption::SetOptionInt("main", "dump_base_skip_stat", 0); COption::SetOptionInt("main", "dump_base_skip_search", 0); COption::SetOptionInt("main", "dump_base_skip_log", 0); if ($arAllBucket) { $bDumpCloud = 1; $NS['total_steps']++; COption::SetOptionInt("main", "dump_do_clouds", 1); foreach($arAllBucket as $arBucket) COption::SetOptionInt('main', 'dump_cloud_'.$arBucket['ID'], 1); } COption::SetOptionInt("main", "skip_mask", 0); } else { COption::SetOptionInt("main", "dump_max_exec_time", max(intval($_REQUEST['dump_max_exec_time'] ?? 0), 5)); COption::SetOptionInt("main", "dump_max_exec_time_sleep", $_REQUEST['dump_max_exec_time_sleep'] ?? 0); $dump_archive_size_limit = intval($_REQUEST['dump_archive_size_limit'] ?? 0); if ($dump_archive_size_limit > 2047 || $dump_archive_size_limit <= 10) $dump_archive_size_limit = 100; COption::SetOptionInt("main", "dump_archive_size_limit", $dump_archive_size_limit * 1024 * 1024); COption::SetOptionInt("main", "dump_max_file_size", $_REQUEST['max_file_size'] ?? 0); $NS['total_steps'] = 0; if ($r = (isset($_REQUEST['dump_file_public']) && $_REQUEST['dump_file_public'] == 'Y')) $NS['total_steps'] = 1; COption::SetOptionInt("main", "dump_file_public", $r); if ($r = (isset($_REQUEST['dump_file_kernel']) && $_REQUEST['dump_file_kernel'] == 'Y')) $NS['total_steps'] = 1; COption::SetOptionInt("main", "dump_file_kernel", $r); if ($r = $DB->type == 'MYSQL' ? (isset($_REQUEST['dump_base']) && $_REQUEST['dump_base'] == 'Y') : 0) $NS['total_steps'] += 2; COption::SetOptionInt("main", "dump_base", $r); COption::SetOptionInt("main", "dump_base_skip_stat", isset($_REQUEST['dump_base_skip_stat']) && $_REQUEST['dump_base_skip_stat'] == 'Y'); COption::SetOptionInt("main", "dump_base_skip_search", isset($_REQUEST['dump_base_skip_search']) && $_REQUEST['dump_base_skip_search'] == 'Y'); COption::SetOptionInt("main", "dump_base_skip_log", isset($_REQUEST['dump_base_skip_log']) && $_REQUEST['dump_base_skip_log'] == 'Y'); if ($r = (isset($_REQUEST['dump_integrity_check']) && $_REQUEST['dump_integrity_check'] == 'Y')) $NS['total_steps']++; COption::SetOptionInt("main", "dump_integrity_check", $r); $bDumpCloud = false; if ($arAllBucket) { foreach($arAllBucket as $arBucket) { if ($res = (isset($_REQUEST['dump_cloud'][$arBucket['ID']]) && $_REQUEST['dump_cloud'][$arBucket['ID']] == 'Y')) $bDumpCloud = true; COption::SetOptionInt('main', 'dump_cloud_'.$arBucket['ID'], $res); } if ($bDumpCloud) $NS['total_steps']++; } COption::SetOptionInt("main", "dump_do_clouds", $bDumpCloud); $skip_mask = isset($_REQUEST['skip_mask']) && $_REQUEST['skip_mask'] == 'Y'; COption::SetOptionInt("main", "skip_mask", $skip_mask); $skip_mask_array = array(); if ($skip_mask && isset($_REQUEST['arMask']) && is_array($_REQUEST['arMask'])) { $arMask = array_unique($_REQUEST['arMask']); foreach($arMask as $mask) if (trim($mask)) { $mask = rtrim(str_replace('\\','/',trim($mask)),'/'); $skip_mask_array[] = $mask; } COption::SetOptionString("main", "skip_mask_array", serialize($skip_mask_array)); } } $NS["step"] = 1; if ($NS['BUCKET_ID']) // send to the [bitrix]cloud $NS['total_steps']++; $NS['dump_site_id'] = $_REQUEST['dump_site_id'] ?? ''; if (!is_array($NS['dump_site_id'])) $NS['dump_site_id'] = array(); COption::SetOptionString("main", "dump_site_id", serialize($NS['dump_site_id'])); if ($NS['BUCKET_ID'] == -1) // Bitrixcloud { $name = DOCUMENT_ROOT . BX_ROOT . "/backup/" . date('Ymd_His_') . Random::getStringByAlphabet(16, Random::ALPHABET_NUM); $NS['arc_name'] = $name.'.enc'.($bUseCompression ? ".gz" : ''); $NS['dump_name'] = $name.'.sql'; } else { $prefix = ''; if (count($NS['dump_site_id']) == 1) { $rs = CSite::GetList('sort', 'asc', array('ID' => $NS['dump_site_id'][0], 'ACTIVE' => 'Y')); if ($f = $rs->Fetch()) $prefix = str_replace('/', '', $f['SERVER_NAME']); } else $prefix = str_replace('/', '', COption::GetOptionString("main", "server_name", "")); $arc_name = CBackup::GetArcName(preg_match('#^[a-z0-9.\-]+$#i', $prefix) ? substr($prefix, 0, 20).'_' : ''); $NS['dump_name'] = $arc_name.".sql"; $NS['arc_name'] = $arc_name.(!empty($NS['dump_encrypt_key']) ? ".enc" : ".tar").($bUseCompression ? ".gz" : ''); } } elseif(isset($_REQUEST['action']) && $_REQUEST['action'] == 'cloud_send') { define('NO_TIME', true); $NS = Array(); $NS['finished_steps'] = 0; $NS['total_steps'] = 1; $NS['cloud_send'] = 1; $NS['dump_encrypt_key'] = $_REQUEST['dump_encrypt_key'] ?? ''; $NS['arc_name'] = $name = DOCUMENT_ROOT.BX_ROOT.'/backup/'.str_replace(array('..','/','\\'),'',$_REQUEST['f_id'] ?? ''); $NS['arc_size'] = filesize($NS['arc_name']); $NS['BUCKET_ID'] = intval($_REQUEST['dump_bucket_id'] ?? 0); $tar = new CTar; while(file_exists($name = $tar->getNextName($name))) $NS['arc_size'] += filesize($name); $NS['step'] = 6; } elseif(isset($_REQUEST['action']) && $_REQUEST['action'] == 'check_archive') { define('NO_TIME', true); $NS = Array(); $NS['finished_steps'] = 0; $NS['total_steps'] = 1; $NS['arc_name'] = $name = DOCUMENT_ROOT.BX_ROOT.'/backup/'.str_replace(array('..','/','\\'),'',$_REQUEST['f_id'] ?? ''); $NS['step'] = 5; $NS['dump_encrypt_key'] = $_REQUEST['dump_encrypt_key'] ?? ''; $NS['check_archive'] = true; $tar = new CTar; $NS['data_size'] = $tar->getDataSize($name); } else { $ar = unserialize(COption::GetOptionString("main","skip_mask_array"), ['allowed_classes' => false]); $skip_mask_array = is_array($ar) ? $ar : array(); } $after_file = str_replace('.sql','_after_connect.sql',preg_replace('#\.[0-9]+$#', '', $NS['dump_name'])); $FinishedTables = 0; // Step 1: Dump if($NS["step"] == 1) { $step_done = 0; if (IntOption('dump_base')) { if (!CBackup::MakeDump($NS['dump_name'], $NS['dump_state'])) { RaiseErrorAndDie(GetMessage('DUMP_NO_PERMS')); } $TotalTables = $NS['dump_state']['TableCount']; $FinishedTables = $TotalTables - count($NS['dump_state']['TABLES']); $status_title = GetMessage('DUMP_DB_CREATE'); $status_details = GetMessage("MAIN_DUMP_TABLE_FINISH")." ".(intval($FinishedTables))." ".GetMessage('MAIN_DUMP_FROM').' '.$TotalTables.''; $step_done = $FinishedTables / $TotalTables; if (!empty($NS['dump_state']['end'])) { $rs = $DB->Query('SHOW VARIABLES LIKE "character_set_results"'); if (($f = $rs->Fetch()) && array_key_exists ('Value', $f)) file_put_contents($after_file, "SET NAMES '".$f['Value']."';\n"); $rs = $DB->Query('SHOW VARIABLES LIKE "collation_database"'); if (($f = $rs->Fetch()) && array_key_exists ('Value', $f)) file_put_contents($after_file, "ALTER DATABASE `` COLLATE ".$f['Value'].";\n",8); clearstatcache(); $NS["step"]++; $NS['finished_steps']++; } } else $NS["step"]++; } // Step 2: pack dump if($NS["step"] == 2) { $step_done = 0; if (IntOption('dump_base')) { if (haveTime()) { $tar = new CTar; $tar->EncryptKey = $NS['dump_encrypt_key'] ?? ''; $tar->ArchiveSizeLimit = IntOption('dump_archive_size_limit'); $tar->gzip = IntOption('dump_use_compression'); $tar->path = DOCUMENT_ROOT; $tar->ReadBlockCurrent = intval($NS['ReadBlockCurrent'] ?? 0); if (!$tar->openWrite($NS["arc_name"])) { RaiseErrorAndDie(GetMessage('DUMP_NO_PERMS')); } if (!$tar->ReadBlockCurrent && file_exists($f = DOCUMENT_ROOT.BX_ROOT.'/.config.php')) $tar->addFile($f); $Block = $tar->Block; $r = null; while(haveTime() && ($r = $tar->addFile($NS['dump_name'])) && $tar->ReadBlockCurrent > 0); if (!isset($NS["data_size"])) { $NS["data_size"] = 0; } $NS["data_size"] += 512 * ($tar->Block - $Block); if ($r === false) RaiseErrorAndDie(implode('
',$tar->err)); $NS["ReadBlockCurrent"] = $tar->ReadBlockCurrent; if (empty($NS['dump_size'])) { $next_part = $NS['dump_name']; $NS['dump_size'] = filesize($next_part); while(file_exists($next_part = CBackup::getNextName($next_part))) $NS['dump_size'] += filesize($next_part); } $status_title = GetMessage("MAIN_DUMP_DB_PROC"); $status_details = GetMessage('CURRENT_POS').' '.round(100 * $NS['data_size'] / $NS['dump_size']).'%'; $step_done = $NS['data_size'] / $NS['dump_size']; if($tar->ReadBlockCurrent == 0) { unlink($NS["dump_name"]); if (file_exists($next_part = CBackup::getNextName($NS['dump_name']))) { $NS['dump_name'] = $next_part; } else { if (file_exists($after_file)) { $tar->addFile($after_file); unlink($after_file); } $NS['arc_size'] = 0; $name = $NS["arc_name"]; while(file_exists($name)) { $size = filesize($name); $NS['arc_size'] += $size; if (IntOption("disk_space") > 0) CDiskQuota::updateDiskQuota("file", $size, "add"); $name = $tar->getNextName($name); } $NS["step"]++; $NS['finished_steps']++; } } $tar->close(); } } else $NS["step"]++; } // Step 3: Download Cloud Files $arDumpClouds = false; if($NS["step"] == 3) { $step_done = 0; if ($arDumpClouds = CBackup::CheckDumpClouds()) { if (haveTime()) { $res = null; foreach($arDumpClouds as $id) { if (!empty($NS['bucket_finished_'.$id])) continue; $obCloud = new CloudDownload($id); $obCloud->last_bucket_path = $NS['last_bucket_path'] ?? ''; if ($res = $obCloud->Scan('')) { $NS['bucket_finished_'.$id] = true; } else // partial { $NS['last_bucket_path'] = $obCloud->path; $NS['download_cnt'] += $obCloud->download_cnt; $NS['download_size'] += $obCloud->download_size; if ($c = count($obCloud->arSkipped)) $NS['download_skipped'] += $c; break; } } $status_title = GetMessage("MAIN_DUMP_CLOUDS_DOWNLOAD"); $status_details = GetMessage("MAIN_DUMP_FILES_DOWNLOADED").': '.intval($NS["download_cnt"] ?? 0).''; // if ($NS['download_skipped']) // $status_title .= GetMessage("MAIN_DUMP_DOWN_ERR_CNT").': '.$NS['download_skipped'].'
'; if ($res) // finish { $NS['step']++; $NS['finished_steps']++; } } } else $NS["step"]++; } // Step 4: Tar Files if($NS["step"] == 4) { $step_done = 0; if (CBackup::CheckDumpFiles() || CBackup::CheckDumpClouds()) { if (haveTime()) { $tar = new CTar; $DirScan = new CDirRealScan; $DOCUMENT_ROOT_SITE = DOCUMENT_ROOT; if (is_array($NS['dump_site_id'])) { $SITE_ID = reset($NS['dump_site_id']); $rs = CSite::GetList('sort', 'asc', array('ID' => $SITE_ID, 'ACTIVE' => 'Y')); if ($f = $rs->Fetch()) { $DOCUMENT_ROOT_SITE = rtrim(str_replace('\\','/',$f['ABS_DOC_ROOT']),'/'); if (!empty($NS['multisite'])) { $tar->prefix = 'bitrix/backup/sites/'.$f['LID'].'/'; $DirScan->arSkip[$DOCUMENT_ROOT_SITE.'/bitrix'] = true; $DirScan->arSkip[$DOCUMENT_ROOT_SITE.'/upload'] = true; if (is_link($DOCUMENT_ROOT_SITE.'/local')) { // if it's a link, we need it only the first time $DirScan->arSkip[$DOCUMENT_ROOT_SITE.'/local'] = true; } } } } CBackup::$DOCUMENT_ROOT_SITE = $DOCUMENT_ROOT_SITE; CBackup::$REAL_DOCUMENT_ROOT_SITE = realpath($DOCUMENT_ROOT_SITE); $tar->EncryptKey = $NS['dump_encrypt_key'] ?? ''; $tar->ArchiveSizeLimit = IntOption('dump_archive_size_limit'); $tar->gzip = IntOption('dump_use_compression'); $tar->path = $DOCUMENT_ROOT_SITE; $tar->ReadBlockCurrent = intval($NS['ReadBlockCurrent'] ?? 0); $tar->ReadFileSize = intval($NS['ReadFileSize'] ?? 0); if (!$tar->openWrite($NS["arc_name"] ?? '')) { RaiseErrorAndDie(GetMessage('DUMP_NO_PERMS')); } $Block = $tar->Block; if (empty($NS['startPath'])) { if (!IntOption('dump_base') && file_exists($f = DOCUMENT_ROOT.BX_ROOT.'/.config.php')) $tar->addFile($f); } else $DirScan->startPath = $NS['startPath']; $r = $DirScan->Scan($DOCUMENT_ROOT_SITE); if (!isset($NS["data_size"])) { $NS["data_size"] = 0; } $NS["data_size"] += 512 * ($tar->Block - $Block); $tar->close(); if ($r === false) RaiseErrorAndDie(implode('
',array_merge($tar->err,$DirScan->err))); $NS["ReadBlockCurrent"] = $tar->ReadBlockCurrent; $NS["ReadFileSize"] = $tar->ReadFileSize; $NS["startPath"] = $DirScan->nextPath; if (!isset($NS["cnt"])) { $NS["cnt"] = 0; } $NS["cnt"] += $DirScan->FileCount; $status_title = GetMessage("MAIN_DUMP_SITE_PROC"); $status_details = GetMessage("MAIN_DUMP_FILE_CNT")." ".intval($NS["cnt"]).""; $last_files_count = IntOption('last_files_count'); if (!$last_files_count) $last_files_count = 200000; $step_done = $NS['cnt'] / $last_files_count; if ($step_done > 1) $step_done = 1; if ($r !== 'BREAK') { if (count($NS['dump_site_id']) > 1) { array_shift($NS['dump_site_id']); $NS['multisite'] = true; unset($NS['startPath']); } else // finish { $NS['arc_size'] = 0; $name = $NS["arc_name"]; while(file_exists($name)) { $size = filesize($name); $NS['arc_size'] += $size; if (IntOption("disk_space") > 0) CDiskQuota::updateDiskQuota("file", $size, "add"); $name = $tar->getNextName($name); } DeleteDirFilesEx(BX_ROOT.'/backup/clouds'); $NS["step"]++; $NS['finished_steps']++; } } } } else $NS["step"]++; } // Step 5: Integrity check if($NS["step"] == 5) { $step_done = 0; if (IntOption('dump_integrity_check') || $NS['check_archive']) { if (haveTime()) { $tar = new CTarCheck; $tar->EncryptKey = $NS['dump_encrypt_key'] ?? ''; if (!$tar->openRead($NS["arc_name"] ?? '')) RaiseErrorAndDie(GetMessage('DUMP_NO_PERMS_READ').'
'.implode('
',$tar->err)); else { if(($Block = intval($NS['Block'] ?? 0)) && !$tar->SkipTo($Block)) RaiseErrorAndDie(implode('
',$tar->err)); while(($r = $tar->extractFile()) && haveTime()); $NS["Block"] = $tar->Block; $status_title = GetMessage('INTEGRITY_CHECK'); $status_details = GetMessage('CURRENT_POS').' '.CFile::FormatSize($NS['Block'] * 512).' '.GetMessage('MAIN_DUMP_FROM').' '.CFile::FormatSize($NS['data_size']).''; $step_done = $NS['Block'] * 512 / $NS['data_size']; if ($r === false) RaiseErrorAndDie(implode('
',$tar->err)); if ($r === 0) { $NS["step"]++; $NS['finished_steps']++; } } $tar->close(); } } 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 { if ($NS['arc_size'] > $q) RaiseErrorAndDie(GetMessage('DUMP_ERR_BIG_BACKUP', array('#ARC_SIZE#' => $NS['arc_size'], '#QUOTA#' => $q)), true); try { $obBucket = $backup->getBucketToWriteFile(CTar::getCheckword($NS['dump_encrypt_key']), basename($NS['arc_name'])); $NS['obBucket'] = serialize($obBucket); } catch (CBitrixCloudException $e) { RaiseErrorAndDie($e->GetMessage(),true); } } } else { $obBucket = unserialize( $NS['obBucket'], ['allowed_classes' => ['CBitrixCloudBackupBucket']] ); } $obBucket->Init(); $obBucket->GetService()->setPublic(false); $bucket_id = $obBucket; } else { $obBucket = null; $bucket_id = $NS['BUCKET_ID']; } if (!$obUpload->isStarted()) { if (is_object($obBucket)) $obBucket->setCheckWordHeader(); if (!$obUpload->Start($bucket_id, $file_size)) { if ($e = $APPLICATION->GetException()) $strError = $e->GetString(); else $strError = GetMessage('MAIN_DUMP_INT_CLOUD_ERR'); unset($NS['obBucket']); RaiseErrorAndDie($strError,true); } if (is_object($obBucket)) $obBucket->unsetCheckWordHeader(); } if ($fp = fopen($NS['arc_name'],'rb')) { fseek($fp, $obUpload->getPos()); $part = fread($fp, $obUpload->getPartSize()); fclose($fp); $fails = 0; $res = null; while($obUpload->hasRetries()) { if($res = $obUpload->Next($part, $obBucket)) break; elseif (++$fails >= 10) { $e = $APPLICATION->GetException(); $strError = $e ? '. ' . $e->GetString() : ''; RaiseErrorAndDie('Internal Error: could not init upload for ' . $fails . ' times' . $strError); } } if ($res) { $pos = $obUpload->getPos(); if ($pos >= $file_size) // file ended { if($obUpload->Finish($obBucket)) { $NS['pos'] += $file_size; $pos = 0; if ($NS['BUCKET_ID'] != -1) { $oBucket = new CCloudStorageBucket($NS['BUCKET_ID']); $oBucket->IncFileCounter($file_size); } $tar = new CTar; if (file_exists($arc_name = $tar->getNextName($NS['arc_name']))) { unset($NS['obBucket']); $NS['arc_name'] = $arc_name; } else { if ($bBitrixCloud) { $ob = new CBitrixCloudBackup; $ob->clearOptions(); } $name = CTar::getFirstName($NS['arc_name']); while(file_exists($name)) { $size = filesize($name); if (unlink($name) && IntOption("disk_space") > 0) CDiskQuota::updateDiskQuota("file",$size , "del"); $name = $tar->getNextName($name); } $NS["step"]++; $NS['finished_steps']++; } } else { $obUpload->Delete(); unset($NS['obBucket']); $e = $APPLICATION->GetException(); $strError = $e ? '. ' . $e->GetString() : ''; RaiseErrorAndDie(GetMessage('MAIN_DUMP_ERR_FILE_SEND') . basename($NS['arc_name']) . $strError,true); } } $pos += $NS['pos']; $status_title = GetMessage("MAIN_DUMP_FILE_SENDING"); $status_details = GetMessage('CURRENT_POS').' '.CFile::FormatSize($pos).' '.GetMessage('MAIN_DUMP_FROM').' '.CFile::FormatSize($NS["arc_size"])."". GetMessage('TIME_LEFT', array('#TIME#' => HumanTime(($NS['arc_size'] - $pos) / $pos * (microtime(true) - $NS['upload_start_time'])))); $step_done = $pos / $NS['arc_size']; } else { $obUpload->Delete(); unset($NS['obBucket']); $e = $APPLICATION->GetException(); $strError = $e ? '. ' . $e->GetString() : ''; RaiseErrorAndDie(GetMessage('MAIN_DUMP_ERR_FILE_SEND') . basename($NS['arc_name']) . $strError, true); } } else { unset($NS['obBucket']); RaiseErrorAndDie(GetMessage("MAIN_DUMP_ERR_OPEN_FILE").$NS['arc_name'],true); } } } else $NS["step"]++; } if (!isset($NS["time"])) { $NS["time"] = 0; } $NS["time"] += workTime(); if ($NS["step"] <= 6) // partial { CAdminMessage::ShowMessage(array( "TYPE" => "PROGRESS", "MESSAGE" => $status_title, "DETAILS" => $status_details.'#PROGRESS_BAR#'. // GetMessage('TIME_SPENT').' '.HumanTime($NS["time"]), GetMessage('TIME_SPENT').' '.sprintf('%02d',floor($NS["time"]/60)).':'.sprintf('%02d', $NS['time']%60).'', "HTML" => true, "PROGRESS_TOTAL" => 100, "PROGRESS_VALUE" => ($NS['finished_steps'] + $step_done) * 100 / $NS['total_steps'], )); ?>
'; $status_msg = ''; if (!empty($NS["arc_size"])) { $status_msg .= GetMessage("MAIN_DUMP_ARC_NAME").": ".basename(CTar::getFirstName($NS["arc_name"]))."
"; $status_msg .= GetMessage("MAIN_DUMP_ARC_SIZE")." ".CFile::FormatSize($NS["arc_size"])."
"; if ($NS['BUCKET_ID'] > 0) $l = ''; //htmlspecialcharsbx($arBucket['BUCKET'].' ('.$arBucket['SERVICE_ID'].')'); elseif ($NS['BUCKET_ID'] == -1) $l = GetMessage('DUMP_MAIN_BITRIX_CLOUD'); else $l = GetMessage("MAIN_DUMP_LOCAL"); if ($l) $status_msg .= GetMessage("MAIN_DUMP_LOCATION").": ".$l."
"; } if ($FinishedTables) $status_msg .= GetMessage("MAIN_DUMP_TABLE_FINISH")." ".$FinishedTables."
"; if (!empty($NS["cnt"])) { $status_msg .= GetMessage("MAIN_DUMP_FILE_CNT")." ".$NS["cnt"]."
"; if (IntOption("dump_file_public") && IntOption("dump_file_kernel")) COption::SetOptionInt("main", "last_files_count", $NS['cnt']); } if (!empty($NS["data_size"])) $status_msg .= GetMessage("MAIN_DUMP_FILE_SIZE")." ".CFile::FormatSize($NS["data_size"])."
"; $status_msg .= GetMessage('TIME_SPENT').' '.HumanTime($NS["time"]).''; CAdminMessage::ShowMessage(array( "MESSAGE" => $title, "DETAILS" => $status_msg, "TYPE" => "OK", "HTML" => true)); ?> Query("UNLOCK TABLES",true); $APPLICATION->SetTitle(GetMessage("MAIN_DUMP_PAGE_TITLE")); require($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/include/prolog_admin_after.php"); $aTabs = array(); $aTabs[] = array("DIV"=>"std", "TAB"=>GetMessage("DUMP_MAIN_MAKE_ARC"), "ICON"=>"main_user_edit", "TITLE"=>GetMessage("MAKE_DUMP_FULL")); $aTabs[] = array("DIV"=>"expert", "TAB"=>GetMessage("DUMP_MAIN_PARAMETERS"), "ICON"=>"main_user_edit", "TITLE"=>GetMessage("DUMP_MAIN_EXPERT_SETTINGS")); $editTab = new CAdminTabControl("editTab", $aTabs, true, true); if ($DB->type != 'MYSQL') echo BeginNote().GetMessage('MAIN_DUMP_MYSQL_ONLY').EndNote(); if (!$encrypt || !$bHash) { CAdminMessage::ShowMessage(array( "MESSAGE" => ($encrypt ? '' : GetMessage("MAIN_DUMP_NOT_INSTALLED1")).($bHash ? '' : ' '.GetMessage('MAIN_DUMP_NOT_INSTALLED_HASH')), "DETAILS" => GetMessage("MAIN_DUMP_NO_ENC_FUNCTIONS"), "TYPE" => "ERROR", "HTML" => true)); } if (defined('DUMP_DEBUG_MODE')) echo '
DEBUG MODE
'; ?>
GetMessage("MAIN_DUMP_LIST_PAGE_TITLE"), "LINK" => "/bitrix/admin/dump_list.php?lang=".LANGUAGE_ID, "TITLE" => GetMessage("MAIN_DUMP_LIST_PAGE_TITLE"), "ICON" => "btn_list" ) ); $context = new CAdminContextMenu($aMenu); $context->Show(); CAdminFileDialog::ShowScript( Array ( "event" => "__bx_select_dir", "arResultDest" => Array("FUNCTION_NAME" => "mnu_SelectValue"), "arPath" => Array('PATH'=>"/"), "select" => 'D', "operation" => 'O', "showUploadTab" => false, "showAddToMenuTab" => false, "allowAllFiles" => true, "SaveConfig" => true ) ); ?>
Begin(); $editTab->BeginNextTab(); if (!COption::GetOptionInt("main", 'dump_auto_enable_auto', 0)) { ?> '/bitrix/admin/dump_auto.php?lang='.LANGUAGE_ID)); echo EndNote(); ?> 1: "PROGRESS", "DETAILS" => GetMessage("BCL_BACKUP_USAGE", array( "#QUOTA#" => CFile::FormatSize($quota = $backup->getQuota()), "#USAGE#" => CFile::FormatSize($usage = $backup->getUsage()), )).'#PROGRESS_BAR#', "HTML" => false, "PROGRESS_TOTAL" => $quota, "PROGRESS_VALUE" => $usage, )); } ?>
id="bitrixcloud" onclick="CheckEncrypt(this)"> ('.$strBXError.')' : ''?>
id="dump_bucket_id_0" onclick="CheckEncrypt(this)">
'N')); if ($arWriteBucket) { foreach($arWriteBucket as $f) echo '
'; } ?> 'Y')); while($f = $res->Fetch()) { $root = rtrim($f['ABS_DOC_ROOT'],'/'); if (is_dir($root)) $arSitePath[$root] = array($f['ID'] => '['.$f['ID'].'] '.$f['NAME']); } if (count($arSitePath) > 1) { ?> 2 false]); else $dump_site_id = array(); $i = 0; foreach($arSitePath as $path => $val) { $path = rtrim(str_replace('\\','/',$path),'/'); $k = key($val); $v = current($val); echo '
'; $i++; } ?> BeginNextTab(); ?> '; ?> type == 'MYSQL') { ?> (? ): >
id="dump_base_skip_stat">
id="dump_base_skip_search">
id="dump_base_skip_log">
> > 3 onclick="CheckActiveStart()"> false]); $skip_mask_array = is_array($res)?$res:array(); foreach($skip_mask_array as $mask) { $i++; echo ''; } $i++; ?>
'. ''. '
" > 4 > > > " size=2> , " size=2> 5 Buttons(); ?> " OnClick="StartDump();"> " OnClick="EndDump(true)" disabled> End(); ?>
1 '.GetMessage("DUMP_MAIN_BXCLOUD_INFO").''; echo '
2 '.GetMessage("DUMP_MAIN_MULTISITE_INFO").'
'; echo '
3 '.GetMessage("MAIN_DUMP_FOOTER_MASK").'
'; echo '
4 '.GetMessage("MAIN_DUMP_BXCLOUD_ENC").'
'; echo '
5 '.GetMessage("MAIN_DUMP_MAX_ARCHIVE_SIZE_INFO").'
'; echo EndNote(); require($_SERVER["DOCUMENT_ROOT"].BX_ROOT."/modules/main/include/epilog_admin.php"); function IntOption($name, $def = 0) { static $CACHE; if (!isset($CACHE[$name])) $CACHE[$name] = COption::GetOptionInt("main", $name, $def); return $CACHE[$name]; } function getTableSize($reg) { global $DB; if ($DB->type != 'MYSQL') return 0; static $CACHE; if (!$CACHE) { $CACHE = array(); $sql = "SHOW TABLE STATUS"; $res = $DB->Query($sql); while($row = $res->Fetch()) $CACHE[$row['Name']] = $row['Data_length']; } $size = 0; foreach($CACHE as $table => $s) if (!$reg || preg_match('#'.$reg.'#i', $table)) $size += $s; return $size; } function haveTime() { if(defined('NO_TIME')) return microtime(true) - START_EXEC_TIME < 1; return microtime(true) - START_EXEC_TIME < IntOption("dump_max_exec_time"); } function workTime() { return microtime(true) - START_EXEC_TIME; } function RaiseErrorAndDie($strError, $bRepeat = false) { if ($bRepeat) { $strError .= '
'; } CAdminMessage::ShowMessage(array( "MESSAGE" => GetMessage("MAIN_DUMP_ERROR"), "DETAILS" => $strError, "TYPE" => "ERROR", "HTML" => true)); echo ''; die(); }