| 495 | |
| 496 | |
| 497 | void BackupImpl::readBackupMetadata() |
| 498 | { |
| 499 | LOG_TRACE(log, "Backup {}: Reading metadata", backup_name_for_logging); |
| 500 | auto timer = DB::CurrentThread::getProfileEvents().timer(ProfileEvents::BackupReadMetadataMicroseconds); |
| 501 | |
| 502 | using namespace XMLUtils; |
| 503 | |
| 504 | std::unique_ptr<ReadBuffer> in; |
| 505 | if (use_archive) |
| 506 | { |
| 507 | if (!archive_reader->fileExists(".backup")) |
| 508 | throw Exception(ErrorCodes::BACKUP_NOT_FOUND, "Archive {} is not a backup", backup_name_for_logging); |
| 509 | setCompressedSize(); |
| 510 | in = archive_reader->readFile(".backup", /*throw_on_not_found=*/true); |
| 511 | } |
| 512 | else |
| 513 | { |
| 514 | if (!reader->fileExists(".backup")) |
| 515 | throw Exception(ErrorCodes::BACKUP_NOT_FOUND, "Backup {} not found", backup_name_for_logging); |
| 516 | in = reader->readFile(".backup"); |
| 517 | } |
| 518 | |
| 519 | String str; |
| 520 | readStringUntilEOF(str, *in); |
| 521 | Poco::XML::DOMParser dom_parser; |
| 522 | Poco::AutoPtr<Poco::XML::Document> config = dom_parser.parseMemory(str.data(), str.size()); |
| 523 | const Poco::XML::Node * config_root = getRootNode(config); |
| 524 | version = getInt(config_root, "version"); |
| 525 | if ((version < INITIAL_BACKUP_VERSION) || (version > CURRENT_BACKUP_VERSION)) |
| 526 | throw Exception( |
| 527 | ErrorCodes::BACKUP_VERSION_NOT_SUPPORTED, "Backup {}: Version {} is not supported", backup_name_for_logging, version); |
| 528 | |
| 529 | timestamp = parse<::LocalDateTime>(getString(config_root, "timestamp")).to_time_t(); |
| 530 | uuid = parse<UUID>(getString(config_root, "uuid")); |
| 531 | |
| 532 | if (config_root->getNodeByPath("base_backup") && !base_backup_info) |
| 533 | base_backup_info = BackupInfo::fromString(getString(config_root, "base_backup")); |
| 534 | |
| 535 | if (config_root->getNodeByPath("base_backup_uuid")) |
| 536 | base_backup_uuid = parse<UUID>(getString(config_root, "base_backup_uuid")); |
| 537 | |
| 538 | if (config_root->getNodeByPath("original_endpoint")) |
| 539 | original_endpoint = getString(config_root, "original_endpoint"); |
| 540 | if (config_root->getNodeByPath("original_namespace")) |
| 541 | original_namespace = getString(config_root, "original_namespace"); |
| 542 | |
| 543 | num_files = 0; |
| 544 | total_size = 0; |
| 545 | num_entries = 0; |
| 546 | size_of_entries = 0; |
| 547 | |
| 548 | const auto * contents = config_root->getNodeByPath("contents"); |
| 549 | for (const Poco::XML::Node * child = contents->firstChild(); child; child = child->nextSibling()) |
| 550 | { |
| 551 | if (child->nodeName() == "file") |
| 552 | { |
| 553 | const Poco::XML::Node * file_config = child; |
| 554 | BackupFileInfo info; |
nothing calls this directly
no test coverage detected