rocksdb_dump.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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, "DbDumpTool 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(db_path, "", "Path to the db that will be dumped");
  21. DEFINE_string(dump_location, "", "Path to where the dump file location");
  22. DEFINE_bool(anonymous, false,
  23. "Remove information like db path, creation time from dumped file");
  24. DEFINE_string(db_options, "",
  25. "Options string used to open the database that will be dumped");
  26. int main(int argc, char** argv) {
  27. GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true);
  28. if (FLAGS_db_path == "" || FLAGS_dump_location == "") {
  29. fprintf(stderr, "Please set --db_path and --dump_location\n");
  30. return 1;
  31. }
  32. ROCKSDB_NAMESPACE::DumpOptions dump_options;
  33. dump_options.db_path = FLAGS_db_path;
  34. dump_options.dump_location = FLAGS_dump_location;
  35. dump_options.anonymous = FLAGS_anonymous;
  36. ROCKSDB_NAMESPACE::Options db_options;
  37. if (FLAGS_db_options != "") {
  38. ROCKSDB_NAMESPACE::Options parsed_options;
  39. ROCKSDB_NAMESPACE::Status s = ROCKSDB_NAMESPACE::GetOptionsFromString(
  40. db_options, FLAGS_db_options, &parsed_options);
  41. if (!s.ok()) {
  42. fprintf(stderr, "Cannot parse provided db_options\n");
  43. return 1;
  44. }
  45. db_options = parsed_options;
  46. }
  47. ROCKSDB_NAMESPACE::DbDumpTool tool;
  48. if (!tool.Run(dump_options, db_options)) {
  49. return 1;
  50. }
  51. return 0;
  52. }
  53. #endif // !(defined GFLAGS) || defined(ROCKSDB_LITE)