#include <ndb_global.h>
#include <ndb_opts.h>
#include <Vector.hpp>
#include <ndb_limits.h>
#include <NdbTCP.h>
#include <NdbOut.hpp>
#include "consumer_restore.hpp"
#include "consumer_printer.hpp"
Go to the source code of this file.
Functions | |
| static bool | checkSysTable (const char *tableName) |
| void | clearConsumers () |
| static void | free_data_callback () |
| static my_bool | get_one_option (int optid, const struct my_option *opt __attribute__((unused)), char *argument) |
| int | main (int argc, char **argv) |
| bool | readArguments (int *pargc, char ***pargv) |
| static void | short_usage_sub (void) |
| static void | usage () |
Variables | |
| static int | _print = 0 |
| static int | _print_data = 0 |
| static int | _print_log = 0 |
| static int | _print_meta = 0 |
| static int | _restore_data = 0 |
| static int | _restore_meta = 0 |
| FilteredNdbOut | debug |
| FilteredNdbOut | err |
| const char * | g_connect_string = 0 |
| static Vector< class BackupConsumer * > | g_consumers |
| static int | ga_backupId = 0 |
| static const char * | ga_backupPath = "." DIR_SEPARATOR |
| static bool | ga_dont_ignore_systab_0 = false |
| static int | ga_nodeId = 0 |
| static int | ga_nParallelism = 128 |
| static bool | ga_print = false |
| static bool | ga_restore = false |
| FilteredNdbOut | info |
| static struct my_option | my_long_options [] |
| NDB_STD_OPTS_VARS | |
|
|
Definition at line 215 of file restore_main.cpp. References ga_dont_ignore_systab_0. Referenced by main(). 00216 { 00217 return ga_dont_ignore_systab_0 || 00218 (strcmp(tableName, "SYSTAB_0") != 0 && 00219 strcmp(tableName, "NDB$EVENTS_0") != 0 && 00220 strcmp(tableName, "sys/def/SYSTAB_0") != 0 && 00221 strcmp(tableName, "sys/def/NDB$EVENTS_0") != 0); 00222 }
|
|
|
Definition at line 207 of file restore_main.cpp. References Vector< T >::clear(), and Vector< T >::size(). Referenced by main(). 00208 { 00209 for(Uint32 i= 0; i<g_consumers.size(); i++) 00210 delete g_consumers[i]; 00211 g_consumers.clear(); 00212 }
|
|
|
Definition at line 225 of file restore_main.cpp. References Vector< T >::size(). Referenced by main(). 00226 { 00227 for(Uint32 i= 0; i < g_consumers.size(); i++) 00228 g_consumers[i]->tuple_free(); 00229 }
|
|
||||||||||||||||
|
Definition at line 109 of file restore_main.cpp. References exit, ga_backupId, ga_nodeId, ndb_std_get_one_option(), opt(), and opt_debug. 00111 { 00112 #ifndef DBUG_OFF 00113 opt_debug= "d:t:O,/tmp/ndb_restore.trace"; 00114 #endif 00115 ndb_std_get_one_option(optid, opt, argument); 00116 switch (optid) { 00117 case 'n': 00118 if (ga_nodeId == 0) 00119 { 00120 printf("Error in --nodeid,-n setting, see --help\n"); 00121 exit(1); 00122 } 00123 break; 00124 case 'b': 00125 if (ga_backupId == 0) 00126 { 00127 printf("Error in --backupid,-b setting, see --help\n"); 00128 exit(1); 00129 } 00130 break; 00131 } 00132 return 0; 00133 }
|
|
||||||||||||
|
we must always load meta data, even if we will only print it to stdout check wheater we can restore the backup (right version). Definition at line 234 of file restore_main.cpp. References checkSysTable(), clearConsumers(), err, free_data_callback(), ga_backupId, ga_backupPath, ga_nodeId, ga_print, ga_restore, BackupFile::getFileHeader(), BackupFile::getFilename(), RestoreLogIterator::getNextLogEntry(), RestoreDataIterator::getNextTuple(), RestoreMetaData::getNoOfTables(), TupleS::getTable(), TableS::getTableName(), getTableName(), getVersionString(), init, RestoreMetaData::loadContent(), LogEntry::m_table, NDB_INIT, ndbout(), ndbout_c(), BackupFormat::FileHeader::NdbVersion, opt_connect_str, readArguments(), RestoreDataIterator::readFragmentHeader(), BackupFile::readHeader(), Vector< T >::size(), BackupFile::validateFooter(), RestoreDataIterator::validateFragmentFooter(), and version(). 00235 { 00236 NDB_INIT(argv[0]); 00237 00238 if (!readArguments(&argc, &argv)) 00239 { 00240 return -1; 00241 } 00242 00243 g_connect_string = opt_connect_str; 00244 00248 RestoreMetaData metaData(ga_backupPath, ga_nodeId, ga_backupId); 00249 if (!metaData.readHeader()) 00250 { 00251 ndbout << "Failed to read " << metaData.getFilename() << endl << endl; 00252 return -1; 00253 } 00254 00255 const BackupFormat::FileHeader & tmp = metaData.getFileHeader(); 00256 const Uint32 version = tmp.NdbVersion; 00257 00258 ndbout << "Ndb version in backup files: " 00259 << getVersionString(version, 0) << endl; 00260 00264 int res = metaData.loadContent(); 00265 00266 if (res == 0) 00267 { 00268 ndbout_c("Restore: Failed to load content"); 00269 return -1; 00270 } 00271 00272 if (metaData.getNoOfTables() == 0) 00273 { 00274 ndbout_c("Restore: The backup contains no tables "); 00275 return -1; 00276 } 00277 00278 00279 if (!metaData.validateFooter()) 00280 { 00281 ndbout_c("Restore: Failed to validate footer."); 00282 return -1; 00283 } 00284 00285 Uint32 i; 00286 for(i= 0; i < g_consumers.size(); i++) 00287 { 00288 if (!g_consumers[i]->init()) 00289 { 00290 clearConsumers(); 00291 return -11; 00292 } 00293 00294 } 00295 00296 for(i = 0; i<metaData.getNoOfTables(); i++) 00297 { 00298 if (checkSysTable(metaData[i]->getTableName())) 00299 { 00300 for(Uint32 j= 0; j < g_consumers.size(); j++) 00301 if (!g_consumers[j]->table(* metaData[i])) 00302 { 00303 ndbout_c("Restore: Failed to restore table: %s. " 00304 "Exiting...", 00305 metaData[i]->getTableName()); 00306 return -11; 00307 } 00308 } 00309 } 00310 00311 for(i= 0; i < g_consumers.size(); i++) 00312 if (!g_consumers[i]->endOfTables()) 00313 { 00314 ndbout_c("Restore: Failed while closing tables"); 00315 return -11; 00316 } 00317 00318 if (ga_restore || ga_print) 00319 { 00320 if (ga_restore) 00321 { 00322 RestoreDataIterator dataIter(metaData, &free_data_callback); 00323 00324 // Read data file header 00325 if (!dataIter.readHeader()) 00326 { 00327 ndbout << "Failed to read header of data file. Exiting..." ; 00328 return -11; 00329 } 00330 00331 00332 while (dataIter.readFragmentHeader(res= 0)) 00333 { 00334 const TupleS* tuple; 00335 while ((tuple = dataIter.getNextTuple(res= 1)) != 0) 00336 { 00337 if (checkSysTable(tuple->getTable()->getTableName())) 00338 for(Uint32 i= 0; i < g_consumers.size(); i++) 00339 g_consumers[i]->tuple(* tuple); 00340 } // while (tuple != NULL); 00341 00342 if (res < 0) 00343 { 00344 ndbout_c("Restore: An error occured while restoring data. " 00345 "Exiting..."); 00346 return -1; 00347 } 00348 if (!dataIter.validateFragmentFooter()) { 00349 ndbout_c("Restore: Error validating fragment footer. " 00350 "Exiting..."); 00351 return -1; 00352 } 00353 } // while (dataIter.readFragmentHeader(res)) 00354 00355 if (res < 0) 00356 { 00357 err << "Restore: An error occured while restoring data. Exiting... " 00358 << "res=" << res << endl; 00359 return -1; 00360 } 00361 00362 00363 dataIter.validateFooter(); //not implemented 00364 00365 for (i= 0; i < g_consumers.size(); i++) 00366 g_consumers[i]->endOfTuples(); 00367 00368 RestoreLogIterator logIter(metaData); 00369 if (!logIter.readHeader()) 00370 { 00371 err << "Failed to read header of data file. Exiting..." << endl; 00372 return -1; 00373 } 00374 00375 const LogEntry * logEntry = 0; 00376 while ((logEntry = logIter.getNextLogEntry(res= 0)) != 0) 00377 { 00378 if (checkSysTable(logEntry->m_table->getTableName())) 00379 for(Uint32 i= 0; i < g_consumers.size(); i++) 00380 g_consumers[i]->logEntry(* logEntry); 00381 } 00382 if (res < 0) 00383 { 00384 err << "Restore: An restoring the data log. Exiting... res=" 00385 << res << endl; 00386 return -1; 00387 } 00388 logIter.validateFooter(); //not implemented 00389 for (i= 0; i < g_consumers.size(); i++) 00390 g_consumers[i]->endOfLogEntrys(); 00391 for(i = 0; i<metaData.getNoOfTables(); i++) 00392 { 00393 if (checkSysTable(metaData[i]->getTableName())) 00394 { 00395 for(Uint32 j= 0; j < g_consumers.size(); j++) 00396 if (!g_consumers[j]->finalize_table(* metaData[i])) 00397 { 00398 ndbout_c("Restore: Failed to finalize restore table: %s. " 00399 "Exiting...", 00400 metaData[i]->getTableName()); 00401 return -11; 00402 } 00403 } 00404 } 00405 } 00406 } 00407 clearConsumers(); 00408 return 0; 00409 } // main
|
|
||||||||||||
|
Definition at line 135 of file restore_main.cpp. References _print, _print_data, _print_log, _print_meta, _restore_data, _restore_meta, exit, ga_backupPath, ga_nParallelism, ga_print, ga_restore, get_one_option(), handle_options(), load_default_groups, load_defaults(), BackupPrinter::m_print, BackupPrinter::m_print_data, BackupPrinter::m_print_log, BackupPrinter::m_print_meta, BackupRestore::m_restore, BackupRestore::m_restore_meta, NULL, and Vector< T >::push_back(). 00136 { 00137 const char *load_default_groups[]= { "mysql_cluster","ndb_restore",0 }; 00138 load_defaults("my",load_default_groups,pargc,pargv); 00139 if (handle_options(pargc, pargv, my_long_options, get_one_option)) 00140 { 00141 exit(1); 00142 } 00143 00144 BackupPrinter* printer = new BackupPrinter(); 00145 if (printer == NULL) 00146 return false; 00147 00148 BackupRestore* restore = new BackupRestore(ga_nParallelism); 00149 if (restore == NULL) 00150 { 00151 delete printer; 00152 return false; 00153 } 00154 00155 if (_print) 00156 { 00157 ga_print = true; 00158 ga_restore = true; 00159 printer->m_print = true; 00160 } 00161 if (_print_meta) 00162 { 00163 ga_print = true; 00164 printer->m_print_meta = true; 00165 } 00166 if (_print_data) 00167 { 00168 ga_print = true; 00169 printer->m_print_data = true; 00170 } 00171 if (_print_log) 00172 { 00173 ga_print = true; 00174 printer->m_print_log = true; 00175 } 00176 00177 if (_restore_data) 00178 { 00179 ga_restore = true; 00180 restore->m_restore = true; 00181 } 00182 00183 if (_restore_meta) 00184 { 00185 // ga_restore = true; 00186 restore->m_restore_meta = true; 00187 } 00188 00189 { 00190 BackupConsumer * c = printer; 00191 g_consumers.push_back(c); 00192 } 00193 { 00194 BackupConsumer * c = restore; 00195 g_consumers.push_back(c); 00196 } 00197 // Set backup file path 00198 if (*pargv[0] != NULL) 00199 { 00200 ga_backupPath = *pargv[0]; 00201 } 00202 00203 return true; 00204 }
|
|
|
Definition at line 97 of file restore_main.cpp. References my_progname. 00098 { 00099 printf("Usage: %s [OPTIONS] [<path to backup files>]\n", my_progname); 00100 }
|
|
|
Definition at line 101 of file restore_main.cpp. References my_print_help(), my_print_variables(), ndb_std_print_version(), and short_usage_sub(). 00102 { 00103 short_usage_sub(); 00104 ndb_std_print_version(); 00105 my_print_help(my_long_options); 00106 my_print_variables(my_long_options); 00107 }
|
|
|
Definition at line 46 of file restore_main.cpp. Referenced by NDBT_TestSuite::execute(), main(), and readArguments(). |
|
|
Definition at line 48 of file restore_main.cpp. Referenced by readArguments(). |
|
|
Definition at line 49 of file restore_main.cpp. Referenced by readArguments(). |
|
|
Definition at line 47 of file restore_main.cpp. Referenced by readArguments(). |
|
|
Definition at line 50 of file restore_main.cpp. Referenced by readArguments(). |
|
|
Definition at line 51 of file restore_main.cpp. Referenced by readArguments(). |
|
|
Definition at line 1 of file example2.c. |
|
|
|
|
|
Definition at line 231 of file restore_main.cpp. Referenced by BackupRestore::init(). |
|
|
Definition at line 35 of file restore_main.cpp. |
|
|
Definition at line 33 of file restore_main.cpp. Referenced by get_one_option(), and main(). |
|
|
Definition at line 37 of file restore_main.cpp. Referenced by main(), and readArguments(). |
|
|
Definition at line 34 of file restore_main.cpp. Referenced by checkSysTable(). |
|
|
Definition at line 31 of file restore_main.cpp. Referenced by get_one_option(), and main(). |
|
|
Definition at line 32 of file restore_main.cpp. Referenced by readArguments(). |
|
|
Definition at line 45 of file restore_main.cpp. Referenced by main(), and readArguments(). |
|
|
print and restore flags Definition at line 44 of file restore_main.cpp. Referenced by main(), and readArguments(). |
|
|
|
|
|
Definition at line 53 of file restore_main.cpp. |
|
|
Definition at line 39 of file restore_main.cpp. |
1.4.3