Exemplo n.º 1
0
		else
		{
			$host = COption::GetOptionString('main', 'server_name', $_SERVER['HTTP_HOST']);
			$url = 'http://'.htmlspecialcharsbx($host.$name);
		}
		if ($url)
			echo 'window.prompt("'.GetMessage("MAIN_DUMP_USE_THIS_LINK").' restore.php", "'.htmlspecialcharsbx($url).'");'."\n";
		echo '
			EndDump();
		</script>';
		die();
	}
	elseif ($_REQUEST['action'] == 'restore')
	{
		if (!copy($f = DOCUMENT_ROOT.BX_ROOT.'/modules/main/admin/restore.php', DOCUMENT_ROOT.'/restore.php'))
			RaiseErrorAndDie(GetMessage("MAIN_DUMP_ERR_COPY_FILE").htmlspecialcharsbx($f));

		$url = '';
		$name = $path.'/'.$_REQUEST['f_id'];
		if ($BUCKET_ID = intval($_REQUEST['BUCKET_ID']))
		{
			if (CModule::IncludeModule('clouds'))
			{
				$obBucket = new CCloudStorageBucket($BUCKET_ID);
				if ($obBucket->Init())
					$url = 'arc_down_url='.htmlspecialcharsbx($obBucket->GetFileSRC(array("URN" => $name)));
			}
		}
		else
			$url = 'local_arc_name='.htmlspecialcharsbx($name);
		if ($url)
Exemplo n.º 2
0
                                unset($NS['obBucket']);
                                RaiseErrorAndDie(GetMessage("MAIN_DUMP_ERR_FILE_SEND") . basename($NS['arc_name']), true);
                            }
                        }
                        $pos += $NS['pos'];
                        $status_title = GetMessage("MAIN_DUMP_FILE_SENDING");
                        $status_details = GetMessage('CURRENT_POS') . ' <b>' . CFile::FormatSize($pos) . '</b>  ' . GetMessage('MAIN_DUMP_FROM') . ' <b>' . CFile::FormatSize($NS["arc_size"]) . "</b>" . 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']);
                        RaiseErrorAndDie(GetMessage("MAIN_DUMP_ERR_FILE_SEND") . basename($NS['arc_name']), true);
                    }
                } else {
                    unset($NS['obBucket']);
                    RaiseErrorAndDie(GetMessage("MAIN_DUMP_ERR_OPEN_FILE") . $NS['arc_name'], true);
                }
            }
        } else {
            $NS["step"]++;
        }
    }
    $NS["time"] += workTime();
    if ($NS["step"] <= 6) {
        CAdminMessage::ShowMessage(array("TYPE" => "PROGRESS", "MESSAGE" => $status_title, "DETAILS" => $status_details . '#PROGRESS_BAR#' . GetMessage('TIME_SPENT') . ' <span id="counter_field">' . sprintf('%02d', floor($NS["time"] / 60)) . ':' . sprintf('%02d', $NS['time'] % 60) . '</span><!--' . intval($NS['time']) . '-->', "HTML" => true, "PROGRESS_TOTAL" => 100, "PROGRESS_VALUE" => ($NS['finished_steps'] + $step_done) * 100 / $NS['total_steps']));
        ?>
		<script>
			window.setTimeout("if(!stop)AjaxSend('?process=Y&<?php 
        echo bitrix_sessid_get();
        ?>
')",<?php 
Exemplo n.º 3
0
 function MakeDump($strDumpFile, &$arState)
 {
     global $DB;
     $B = new CBackup();
     if (!$arState) {
         if (!$B->file_put_contents_ex($strDumpFile, "-- Started: " . date('Y-m-d H:i:s') . "\n")) {
             return false;
         }
         $rs = $DB->Query('SHOW VARIABLES LIKE "character_set_results"');
         if (($f = $rs->Fetch()) && array_key_exists('Value', $f)) {
             if (!$B->file_put_contents_ex($strDumpFile, "SET NAMES '" . $f['Value'] . "';\n")) {
                 return false;
             }
         }
         $arState = array('TABLES' => array());
         $arTables = array();
         $rsTables = $DB->Query("SHOW FULL TABLES WHERE TABLE_TYPE NOT LIKE 'VIEW'", false, '', array("fixed_connection" => true));
         while ($arTable = $rsTables->Fetch()) {
             list($key, $table) = each($arTable);
             $rsIndexes = $DB->Query("SHOW INDEX FROM `" . $DB->ForSql($table) . "`", true, '', array("fixed_connection" => true));
             if ($rsIndexes) {
                 $arIndexes = array();
                 while ($ar = $rsIndexes->Fetch()) {
                     if ($ar["Non_unique"] == "0") {
                         $arIndexes[$ar["Key_name"]][$ar["Seq_in_index"] - 1] = $ar["Column_name"];
                     }
                 }
                 foreach ($arIndexes as $IndexName => $arIndexColumns) {
                     if (count($arIndexColumns) != 1) {
                         unset($arIndexes[$IndexName]);
                     }
                 }
                 if (count($arIndexes) > 0) {
                     foreach ($arIndexes as $IndexName => $arIndexColumns) {
                         foreach ($arIndexColumns as $SeqInIndex => $ColumnName) {
                             $key_column = $ColumnName;
                         }
                         break;
                     }
                 } else {
                     $key_column = false;
                 }
             } else {
                 $key_column = false;
             }
             $arState['TABLES'][$table] = array("TABLE_NAME" => $table, "KEY_COLUMN" => $key_column, "LAST_ID" => 0);
         }
         $rsTables = $DB->Query("SHOW FULL TABLES WHERE TABLE_TYPE LIKE 'VIEW'", false, '', array("fixed_connection" => true));
         while ($arTable = $rsTables->Fetch()) {
             list($key, $table) = each($arTable);
             $arState['TABLES'][$table] = array("TABLE_NAME" => $table, "KEY_COLUMN" => false, "LAST_ID" => 0);
         }
         $arState['TableCount'] = count($arState['TABLES']);
         if (!haveTime()) {
             return true;
         }
     }
     foreach ($arState['TABLES'] as $table => $arTable) {
         if (!$arTable["LAST_ID"]) {
             $rs = $DB->Query("SHOW CREATE TABLE `" . $DB->ForSQL($table) . "`", true);
             if ($rs === false) {
                 RaiseErrorAndDie(GetMessage('DUMP_TABLE_BROKEN', array('#TABLE#' => $table)));
             }
             $row = $rs->Fetch();
             $string = $row['Create Table'];
             if (!$string) {
                 $string = $row['Create View'];
                 if (!$B->file_put_contents_ex($strDumpFile, "-- -----------------------------------\n" . "-- Creating view " . $DB->ForSQL($table) . "\n" . "-- -----------------------------------\n" . "DROP VIEW IF EXISTS `" . $DB->ForSQL($table) . "`;\n" . $string . ";\n\n")) {
                     return false;
                 }
                 unset($arState['TABLES'][$table]);
                 continue;
             } elseif (CBackup::SkipTableData($table)) {
                 $string = str_replace('CREATE TABLE', 'CREATE TABLE IF NOT EXISTS', $string);
                 if (!$B->file_put_contents_ex($strDumpFile, "-- -----------------------------------\n" . "-- Creating empty table " . $DB->ForSQL($table) . "\n" . "-- -----------------------------------\n" . $string . ";\n\n")) {
                     return false;
                 }
                 unset($arState['TABLES'][$table]);
                 continue;
             }
             if (!$B->file_put_contents_ex($strDumpFile, "-- -----------------------------------\n" . "-- Dumping table " . $DB->ForSQL($table) . "\n" . "-- -----------------------------------\n" . "DROP TABLE IF EXISTS `" . $DB->ForSQL($table) . "`;\n" . $string . ";\n\n")) {
                 return false;
             }
             $arState['TABLES'][$table]['COLUMNS'] = $arTable["COLUMNS"] = CBackup::GetTableColumns($table);
             if (($k = $arTable['KEY_COLUMN']) && $arTable['COLUMNS'][$k] > 0) {
                 unset($arTable['KEY_COLUMN']);
                 unset($arState['TABLES'][$table]['KEY_COLUMN']);
             }
         }
         $strInsert = "";
         $cnt = $LIMIT = 10000;
         while ($cnt == $LIMIT) {
             $i = $arTable['LAST_ID'];
             if ($arTable["KEY_COLUMN"]) {
                 $strSelect = "\n\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\tFROM `" . $arTable["TABLE_NAME"] . "`\n\t\t\t\t\t\t" . ($arTable["LAST_ID"] ? "WHERE `" . $arTable["KEY_COLUMN"] . "` > '" . $arTable["LAST_ID"] . "'" : "") . "\n\t\t\t\t\t\tORDER BY `" . $arTable["KEY_COLUMN"] . "`\n\t\t\t\t\t\tLIMIT " . $LIMIT;
             } else {
                 $strSelect = "\n\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\tFROM `" . $arTable["TABLE_NAME"] . "`\n\t\t\t\t\t\tLIMIT " . ($arTable["LAST_ID"] ? $arTable["LAST_ID"] . ", " : "") . $LIMIT;
             }
             $rsSource = $DB->Query($strSelect, false, '', array("fixed_connection" => true));
             $cnt = $rsSource->SelectedRowsCount();
             while ($arSource = $rsSource->Fetch()) {
                 if (!$strInsert) {
                     $strInsert = "INSERT INTO `" . $arTable["TABLE_NAME"] . "` VALUES";
                 } else {
                     $strInsert .= ",";
                 }
                 foreach ($arSource as $key => $value) {
                     if (!isset($value) || is_null($value)) {
                         $arSource[$key] = 'NULL';
                     } elseif ($arTable["COLUMNS"][$key] == 0) {
                         $arSource[$key] = $value;
                     } elseif ($arTable["COLUMNS"][$key] == 1) {
                         if (empty($value) && $value != '0') {
                             $arSource[$key] = '\'\'';
                         } else {
                             $arSource[$key] = '0x' . bin2hex($value);
                         }
                     } elseif ($arTable["COLUMNS"][$key] == 2) {
                         $arSource[$key] = "'" . $DB->ForSql($value) . "'";
                     }
                 }
                 $strInsert .= "\n(" . implode(", ", $arSource) . ")";
                 $arState['TABLES'][$table]['LAST_ID'] = $arTable['LAST_ID'] = $arTable["KEY_COLUMN"] ? $arSource[$arTable["KEY_COLUMN"]] : ++$i;
                 if (CTar::strlen($strInsert) > 1000000) {
                     if (!$B->file_put_contents_ex($strDumpFile, $strInsert . ";\n")) {
                         return false;
                     }
                     $strInsert = "";
                 }
                 if (!haveTime()) {
                     return $strInsert ? $B->file_put_contents_ex($strDumpFile, $strInsert . ";\n") : true;
                 }
             }
         }
         if ($strInsert && !$B->file_put_contents_ex($strDumpFile, $strInsert . ";\n")) {
             return false;
         }
         if ($cnt < $LIMIT) {
             unset($arState['TABLES'][$table]);
         }
     }
     if (!$B->file_put_contents_ex($strDumpFile, "-- Finished: " . date('Y-m-d H:i:s'))) {
         return false;
     }
     $arState['end'] = true;
     return true;
 }
Exemplo n.º 4
0
 function BaseDump($arc_name = "", $tbl_num, $start_row, &$TotalTables = 0)
 {
     global $DB;
     $ret = array();
     $last_row = $start_row;
     $mem = 32;
     // Minimum required value
     $sql = "SHOW TABLES;";
     $res = $DB->Query($sql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     $ptab = array();
     while ($row = $res->Fetch()) {
         $ar = each($row);
         $table = $ar[1];
         $ptab[] = $table;
     }
     if (!($f = fopen($arc_name, "a"))) {
         RaiseErrorAndDie('Can\'t open file: ' . $arc_name);
     }
     $i = $tbl_num;
     $dump = "";
     $TotalTables = count($ptab);
     while ($i <= $TotalTables - 1 && haveTime()) {
         if (!strlen($ptab[$i])) {
             continue;
         }
         if ($last_row == -1) {
             $table = $ptab[$i];
             $drop = !IntOption('dump_base_skip_stat') || !preg_match("#^b_stat#i", $table);
             // если не переносим статистику, то не удаляем старую статистику при восстановлении
             if ($dump = CBackup::createTable($ptab[$i], $drop)) {
                 fwrite($f, $dump . "\n");
             } else {
                 $row_next = -1;
             }
             $next = false;
             $ret["num"] = $i;
             $ret["st_row"] = 0;
             $last_row = 0;
         }
         if ($dump) {
             $res = $DB->Query("SELECT count(*) as count FROM `{$ptab[$i]}`");
             $row_count = $res->Fetch();
             if ($row_count["count"] > 0) {
                 if ($ptab[$i] == 'b_xml_tree') {
                     $row_next = -1;
                 } elseif (IntOption('dump_base_skip_stat') && preg_match('#^b_stat#i', $ptab[$i])) {
                     $row_next = -1;
                 } elseif (IntOption('dump_base_skip_search') && preg_match("#^(b_search_content_site|b_search_content_group|b_search_content_stem|b_search_content_title|b_search_tags|b_search_content_freq|b_search_content|b_search_suggest)\$#i", $ptab[$i])) {
                     $row_next = -1;
                 } elseif (IntOption('dump_base_skip_log') && $ptab[$i] == 'b_event_log') {
                     $row_next = -1;
                 } elseif (CTar::strpos($dump, 'DEFINER VIEW')) {
                     $row_next = -1;
                 } else {
                     $row_next = CBackup::getData($ptab[$i], $f, $row_count["count"], $last_row, $mem);
                 }
             } else {
                 $row_next = -1;
             }
         }
         if ($row_next > 0) {
             $last_row = $row_next;
             $ret["num"] = $i;
             $ret["st_row"] = $last_row;
         } else {
             $ret["num"] = ++$i;
             $ret["st_row"] = -1;
             $last_row = -1;
         }
     }
     fclose($f);
     if (!($i <= count($ptab) - 1)) {
         $ret["end"] = true;
     }
     return $ret;
 }
Exemplo n.º 5
0
	$NS['step'] = 8;
}


$info = "Finished.\n\nData size: ".round($NS['data_size']/1024/1024, 2)." M\nArchive size: ".round($NS['arc_size']/1024/1024, 2)." M\nTime: ".(time() - START_TIME)." sec\n";
ShowBackupStatus($info);
CEventLog::Add(array(
	"SEVERITY" => "WARNING",
	"AUDIT_TYPE_ID" => "BACKUP_SUCCESS",
	"MODULE_ID" => "main",
	"ITEM_ID" => $NS['arc_name'],
	"DESCRIPTION" => $info,
));
$NS = array();
if (defined('LOCK_FILE'))
	unlink(LOCK_FILE) || RaiseErrorAndDie('Can\'t delete file: '.LOCK_FILE, 1000);
if (!CLI)
	echo 'FINISH';
COption::SetOptionInt('main', 'last_backup_end_time', time());
##########################################
########################### Functions ####
function IntOption($name, $def = 0)
{
	global $arParams;
	if (isset($arParams[$name]))
		return $arParams[$name];

	static $CACHE;
	$name .= '_auto';

	if (!$CACHE[$name])
Exemplo n.º 6
0
			$part = fread($fp, $obUpload->getPartSize());
			while($obUpload->hasRetries())
				if($res = $obUpload->Next($part))
					break;
			if (!$res)
			{
				$obUpload->Delete();
				RaiseErrorAndDie(GetMessage("MAIN_DUMP_ERR_FILE_SEND").basename($NS['arc_name']));
			}
		}
		fclose($fp);

		if (!$obUpload->Finish())
		{
			$obUpload->Delete();
			RaiseErrorAndDie(GetMessage("MAIN_DUMP_ERR_FILE_SEND").basename($NS['arc_name']));
		}

		$oBucket = new CCloudStorageBucket(IntOption('dump_send_to_bucket_id'));
		$oBucket->IncFileCounter($file_size);

		if (file_exists($arc_name = CTar::getNextName($NS['arc_name'])))
			$NS['arc_name'] = $arc_name; # GOTO 223
		else // finish
		{
			$name = preg_replace('#\.[0-9]+$#','',$NS['arc_name']);
			while(file_exists($name))
			{
				$size = filesize($name);
				if (unlink($name) && IntOption("disk_space") > 0)
					CDiskQuota::updateDiskQuota("file",$size , "del");