]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/tools/dump/rocksdb_undump.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / tools / dump / rocksdb_undump.cc
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
5
6 #if !(defined GFLAGS) || defined(ROCKSDB_LITE)
7
8 #include <cstdio>
9 int main() {
10 #ifndef GFLAGS
11 fprintf(stderr, "Please install gflags to run rocksdb tools\n");
12 #endif
13 #ifdef ROCKSDB_LITE
14 fprintf(stderr, "DbUndumpTool is not supported in ROCKSDB_LITE\n");
15 #endif
16 return 1;
17 }
18
19 #else
20
21 #include <gflags/gflags.h>
22 #include "rocksdb/convenience.h"
23 #include "rocksdb/db_dump_tool.h"
24
25 DEFINE_string(dump_location, "", "Path to the dump file that will be loaded");
26 DEFINE_string(db_path, "", "Path to the db that we will undump the file into");
27 DEFINE_bool(compact, false, "Compact the db after loading the dumped file");
28 DEFINE_string(db_options, "",
29 "Options string used to open the database that will be loaded");
30
31 int main(int argc, char **argv) {
32 GFLAGS::ParseCommandLineFlags(&argc, &argv, true);
33
34 if (FLAGS_db_path == "" || FLAGS_dump_location == "") {
35 fprintf(stderr, "Please set --db_path and --dump_location\n");
36 return 1;
37 }
38
39 rocksdb::UndumpOptions undump_options;
40 undump_options.db_path = FLAGS_db_path;
41 undump_options.dump_location = FLAGS_dump_location;
42 undump_options.compact_db = FLAGS_compact;
43
44 rocksdb::Options db_options;
45 if (FLAGS_db_options != "") {
46 rocksdb::Options parsed_options;
47 rocksdb::Status s = rocksdb::GetOptionsFromString(
48 db_options, FLAGS_db_options, &parsed_options);
49 if (!s.ok()) {
50 fprintf(stderr, "Cannot parse provided db_options\n");
51 return 1;
52 }
53 db_options = parsed_options;
54 }
55
56 rocksdb::DbUndumpTool tool;
57 if (!tool.Run(undump_options, db_options)) {
58 return 1;
59 }
60 return 0;
61 }
62 #endif // !(defined GFLAGS) || defined(ROCKSDB_LITE)