rocksdb_undump.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. #if !(defined GFLAGS) || defined(ROCKSDB_LITE)
  6. #include <cstdio>
  7. int main() {
  8. #ifndef GFLAGS
  9. fprintf(stderr, "Please install gflags to run rocksdb tools\n");
  10. #endif
  11. #ifdef ROCKSDB_LITE
  12. fprintf(stderr, "DbUndumpTool is not supported in ROCKSDB_LITE\n");
  13. #endif
  14. return 1;
  15. }
  16. #else
  17. #include "rocksdb/convenience.h"
  18. #include "rocksdb/db_dump_tool.h"
  19. #include "util/gflags_compat.h"
  20. DEFINE_string(dump_location, "", "Path to the dump file that will be loaded");
  21. DEFINE_string(db_path, "", "Path to the db that we will undump the file into");
  22. DEFINE_bool(compact, false, "Compact the db after loading the dumped file");
  23. DEFINE_string(db_options, "",
  24. "Options string used to open the database that will be loaded");
  25. int main(int argc, char **argv) {
  26. GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
  27. if (FLAGS_db_path == "" || FLAGS_dump_location == "") {
  28. fprintf(stderr, "Please set --db_path and --dump_location\n");
  29. return 1;
  30. }
  31. ROCKSDB_NAMESPACE::UndumpOptions undump_options;
  32. undump_options.db_path = FLAGS_db_path;
  33. undump_options.dump_location = FLAGS_dump_location;
  34. undump_options.compact_db = FLAGS_compact;
  35. ROCKSDB_NAMESPACE::Options db_options;
  36. if (FLAGS_db_options != "") {
  37. ROCKSDB_NAMESPACE::Options parsed_options;
  38. ROCKSDB_NAMESPACE::Status s = ROCKSDB_NAMESPACE::GetOptionsFromString(
  39. db_options, FLAGS_db_options, &parsed_options);
  40. if (!s.ok()) {
  41. fprintf(stderr, "Cannot parse provided db_options\n");
  42. return 1;
  43. }
  44. db_options = parsed_options;
  45. }
  46. ROCKSDB_NAMESPACE::DbUndumpTool tool;
  47. if (!tool.Run(undump_options, db_options)) {
  48. return 1;
  49. }
  50. return 0;
  51. }
  52. #endif // !(defined GFLAGS) || defined(ROCKSDB_LITE)