19 #include <ndb_global.h> 
   23 #include "BackupFormat.hpp" 
   24 #include <AttributeHeader.hpp> 
   25 #include <SimpleProperties.hpp> 
   26 #include <ndb_version.h> 
   27 #include <util/ndbzio.h> 
   49 static Uint32 logEntryNo;
 
   52 main(
int argc, 
const char * argv[]){
 
   56     printf(
"Usage: %s <filename>\n", argv[0]);
 
   61   bzero(&fo, 
sizeof(fo));
 
   62   int r= ndbzopen(&fo,argv[1], O_RDONLY);
 
   66     ndbout_c(
"Failed to open file '%s', error: %d",
 
   74   if(!readHeader(f, &fileHeader)){
 
   75     ndbout << 
"Invalid file!" << endl;
 
   78   ndbout << fileHeader << endl;
 
   80   switch(fileHeader.FileType){
 
   81   case BackupFormat::DATA_FILE:
 
   84       if(!readFragHeader(f, &fragHeader))
 
   86       ndbout << fragHeader << endl;
 
   89       while((len = readRecord(f, &data)) > 0){
 
   91         ndbout << 
"-> " << hex;
 
   92         for(Uint32 
i = 0; 
i<len; 
i++){
 
   93           ndbout << data[
i] << 
" ";
 
  100       if(!readFragFooter(f, &fragFooter))
 
  102       ndbout << fragFooter << endl;
 
  105   case BackupFormat::CTL_FILE:{
 
  107     if(!readTableList(f, &tabList)){
 
  108       ndbout << 
"Invalid file! No table list" << endl;
 
  111     ndbout << (* tabList) << endl;
 
  113     const Uint32 noOfTables = tabList->SectionLength - 2;
 
  114     for(Uint32 
i = 0; 
i<noOfTables; 
i++){
 
  116       if(!readTableDesc(f, &tabDesc)){
 
  117         ndbout << 
"Invalid file missing table description" << endl;
 
  120       ndbout << (* tabDesc) << endl;
 
  124     if(!readGCPEntry(f, &gcpE)){
 
  125       ndbout << 
"Invalid file! GCP ENtry" << endl;
 
  128     ndbout << (* gcpE) << endl;
 
  132   case BackupFormat::LOG_FILE:{
 
  138     while((len = readLogEntry(f, &data)) > 0){
 
  139       LogEntry * logEntry = (LogEntry *) data;
 
  143       Uint32 
event = ntohl(logEntry->TriggerEvent);
 
  144       bool gcp = (
event & 0x10000) != 0;
 
  149       ndbout << 
"LogEntry Table: " << (Uint32)ntohl(logEntry->TableId) 
 
  150              << 
" Event: " << 
event 
  151              << 
" Length: " << (len - 2);
 
  153       const Uint32 dataLen = len - 2;
 
  156       while(pos < dataLen){
 
  158         ndbout_c(
" Attribut: %d Size: %d",
 
  161         pos += ah->getDataSize() + 1;
 
  165           ndbout << 
" GCP: " << (Uint32)ntohl(logEntry->Data[dataLen]);
 
  170   case BackupFormat::LCP_FILE:
 
  173     if(!readTableList(f, &tabList)){
 
  174       ndbout << 
"Invalid file! No table list" << endl;
 
  177     ndbout << (* tabList) << endl;
 
  179     const Uint32 noOfTables = tabList->SectionLength - 2;
 
  180     for(Uint32 
i = 0; 
i<noOfTables; 
i++){
 
  182       if(!readTableDesc(f, &tabDesc)){
 
  183         ndbout << 
"Invalid file missing table description" << endl;
 
  186       ndbout << (* tabDesc) << endl;
 
  191       if(!readFragHeader(f, &fragHeader))
 
  193       ndbout << fragHeader << endl;
 
  196       while((len = readRecord(f, &data)) > 0){
 
  198         ndbout << 
"-> " << hex;
 
  199         for(Uint32 
i = 0; 
i<len; 
i++){
 
  200           ndbout << data[
i] << 
" ";
 
  207       if(!readFragFooter(f, &fragFooter))
 
  209       ndbout << fragFooter << endl;
 
  214     ndbout << 
"Unsupported file type for printer: "  
  215            << fileHeader.FileType << endl;
 
  222 #define RETURN_FALSE() { ndbout_c("false: %d", __LINE__); abort(); return false; } 
  224 static bool endian = 
false;
 
  232   unsigned r = ndbzread(f, buf, (sz * n), &error);
 
  233   if (error || r != (sz * n))
 
  235     printf(
"Failed to read!!");
 
  243   if(aread(dst, 4, 3, f) != 3)
 
  246   if(memcmp(dst->Magic, BACKUP_MAGIC, 
sizeof(BACKUP_MAGIC)) != 0)
 
  248     ndbout_c(
"Incorrect file-header!");
 
  250     for (
unsigned i = 0; 
i<
sizeof(BACKUP_MAGIC); 
i++)
 
  251       printf(
"0x%.2x ", (Uint32)(Uint8)dst->Magic[
i]);
 
  254     for (
unsigned i = 0; i<
sizeof(BACKUP_MAGIC); i++)
 
  255       printf(
"0x%.2x ", (Uint32)(Uint8)BACKUP_MAGIC[i]);
 
  261   dst->BackupVersion = ntohl(dst->BackupVersion);
 
  262   if(dst->BackupVersion >= NDB_VERSION)
 
  264     printf(
"incorrect versions, file: 0x%x expect: 0x%x\n", dst->NdbVersion, NDB_VERSION);
 
  268   if(aread(&dst->SectionType, 4, 2, f) != 2)
 
  270   dst->SectionType = ntohl(dst->SectionType);
 
  271   dst->SectionLength = ntohl(dst->SectionLength);
 
  273   if(dst->SectionType != BackupFormat::FILE_HEADER)
 
  279   if(aread(&dst->FileType, 4, dst->SectionLength - 2, f) != 
 
  280      (dst->SectionLength - 2))
 
  283   dst->FileType = ntohl(dst->FileType);
 
  284   dst->BackupId = ntohl(dst->BackupId);
 
  285   dst->BackupKey_0 = ntohl(dst->BackupKey_0);
 
  286   dst->BackupKey_1 = ntohl(dst->BackupKey_1);
 
  288   if(dst->ByteOrder != 0x12345678)
 
  296   if(aread(dst, 1, 
sizeof(* dst), f) != 
sizeof(* dst))
 
  299   dst->SectionType = ntohl(dst->SectionType);
 
  300   dst->SectionLength = ntohl(dst->SectionLength);
 
  301   dst->TableId = ntohl(dst->TableId);
 
  302   dst->FragmentNo = ntohl(dst->FragmentNo);
 
  303   dst->ChecksumType = ntohl(dst->ChecksumType);
 
  305   if(dst->SectionLength != (
sizeof(* dst) >> 2))
 
  308   if(dst->SectionType != BackupFormat::FRAGMENT_HEADER)
 
  318   if(aread(dst, 1, 
sizeof(* dst), f) != 
sizeof(* dst))
 
  321   dst->SectionType = ntohl(dst->SectionType);
 
  322   dst->SectionLength = ntohl(dst->SectionLength);
 
  323   dst->TableId = ntohl(dst->TableId);
 
  324   dst->FragmentNo = ntohl(dst->FragmentNo);
 
  325   dst->NoOfRecords = ntohl(dst->NoOfRecords);
 
  326   dst->Checksum = ntohl(dst->Checksum);
 
  328   if(dst->SectionLength != (
sizeof(* dst) >> 2))
 
  331   if(dst->SectionType != BackupFormat::FRAGMENT_FOOTER)
 
  348   if(aread(&len, 1, 4, f) != 4)
 
  353   if(aread(theData.buf, 4, len, f) != len)
 
  361     ndbout_c(
"Found %d records", recNo);
 
  363   * dst = &theData.buf[0];
 
  372   if(aread(&len, 1, 4, f) != 4)
 
  377   if(aread(&theData.buf[1], 4, len, f) != len)
 
  380   theData.buf[0] = len;
 
  385   * dst = &theData.buf[0];
 
  395   memcpy(buf, hf.Magic, 
sizeof(hf.Magic));
 
  398   ndbout << 
"-- FileHeader:" << endl;
 
  399   ndbout << 
"Magic: " << buf << endl;
 
  400   ndbout << 
"BackupVersion: " << hex << hf.BackupVersion << endl;
 
  401   ndbout << 
"SectionType: " << hf.SectionType << endl;
 
  402   ndbout << 
"SectionLength: " << hf.SectionLength << endl;
 
  403   ndbout << 
"FileType: " << hf.FileType << endl;
 
  404   ndbout << 
"BackupId: " << hf.BackupId << endl;
 
  405   ndbout << 
"BackupKey: [ " << hex << hf.BackupKey_0 
 
  406          << 
" "<< hf.BackupKey_1 << 
" ]" << endl;
 
  407   ndbout << 
"ByteOrder: " << hex << hf.ByteOrder << endl;
 
  411 NdbOut & operator<<(NdbOut& ndbout, 
 
  414   ndbout << 
"-- Fragment header:" << endl;
 
  415   ndbout << 
"SectionType: " << hf.SectionType << endl;
 
  416   ndbout << 
"SectionLength: " << hf.SectionLength << endl;
 
  417   ndbout << 
"TableId: " << hf.TableId << endl;
 
  418   ndbout << 
"FragmentNo: " << hf.FragmentNo << endl;
 
  419   ndbout << 
"ChecksumType: " << hf.ChecksumType << endl;
 
  423 NdbOut & operator<<(NdbOut& ndbout, 
 
  426   ndbout << 
"-- Fragment footer:" << endl;
 
  427   ndbout << 
"SectionType: " << hf.SectionType << endl;
 
  428   ndbout << 
"SectionLength: " << hf.SectionLength << endl;
 
  429   ndbout << 
"TableId: " << hf.TableId << endl;
 
  430   ndbout << 
"FragmentNo: " << hf.FragmentNo << endl;
 
  431   ndbout << 
"NoOfRecords: " << hf.NoOfRecords << endl;
 
  432   ndbout << 
"Checksum: " << hf.Checksum << endl;
 
  441   if(aread(dst, 4, 2, f) != 2)
 
  444   dst->SectionType = ntohl(dst->SectionType);
 
  445   dst->SectionLength = ntohl(dst->SectionLength);
 
  447   if(dst->SectionType != BackupFormat::TABLE_LIST)
 
  450   const Uint32 len = dst->SectionLength - 2;
 
  451   if(aread(&dst->TableIds[0], 4, len, f) != len)
 
  454   for(Uint32 i = 0; i<len; i++){
 
  455     dst->TableIds[
i] = ntohl(dst->TableIds[i]);
 
  467   if(aread(dst, 4, 3, f) != 3)
 
  470   dst->SectionType = ntohl(dst->SectionType);
 
  471   dst->SectionLength = ntohl(dst->SectionLength);
 
  472   dst->TableType = ntohl(dst->TableType);
 
  474   if(dst->SectionType != BackupFormat::TABLE_DESCRIPTION)
 
  477   const Uint32 len = dst->SectionLength - 3;
 
  478   if(aread(&dst->DictTabInfo[0], 4, len, f) != len)
 
  490   if(aread(dst, 4, 4, f) != 4)
 
  493   dst->SectionType = ntohl(dst->SectionType);
 
  494   dst->SectionLength = ntohl(dst->SectionLength);
 
  496   if(dst->SectionType != BackupFormat::GCP_ENTRY)
 
  499   dst->StartGCP = ntohl(dst->StartGCP);
 
  500   dst->StopGCP = ntohl(dst->StopGCP);
 
  510   ndbout << 
"-- Table List:" << endl;
 
  511   ndbout << 
"SectionType: " << hf.SectionType << endl;
 
  512   ndbout << 
"SectionLength: " << hf.SectionLength << endl;
 
  513   for(Uint32 i = 0; i < hf.SectionLength - 2; i++){
 
  514     ndbout << hf.TableIds[
i] << 
" ";
 
  515     if((i + 1) % 16 == 0)
 
  523   ndbout << 
"-- Table Description:" << endl;
 
  524   ndbout << 
"SectionType: " << hf.SectionType << endl;
 
  525   ndbout << 
"SectionLength: " << hf.SectionLength << endl;
 
  526   ndbout << 
"TableType: " << hf.TableType << endl;
 
  530   for(it.first(); it.valid(); it.next()){
 
  531     switch(it.getValueType()){
 
  532     case SimpleProperties::Uint32Value:
 
  533       ndbout << 
"Key: " << it.getKey()
 
  534              << 
" value(" << it.getValueLen() << 
") : "  
  535              << it.getUint32() << endl;
 
  537     case SimpleProperties::StringValue:
 
  538       if(it.getValueLen() < 
sizeof(
buf)){
 
  540         ndbout << 
"Key: " << it.getKey()
 
  541                << 
" value(" << it.getValueLen() << 
") : "  
  542                << 
"\"" << buf << 
"\"" << endl;
 
  544         ndbout << 
"Key: " << it.getKey()
 
  545                << 
" value(" << it.getValueLen() << 
") : "  
  546                << 
"\"" << 
"<TOO LONG>" << 
"\"" << endl;
 
  551       ndbout << 
"Unknown type for key: " << it.getKey() 
 
  552              << 
" type: " << it.getValueType() << endl;
 
  561   ndbout << 
"-- GCP Entry:" << endl;
 
  562   ndbout << 
"SectionType: " << hf.SectionType << endl;
 
  563   ndbout << 
"SectionLength: " << hf.SectionLength << endl;
 
  564   ndbout << 
"Start GCP: " << hf.StartGCP << endl;
 
  565   ndbout << 
"Stop GCP: " << hf.StopGCP << endl;