]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
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). | |
7c673cae FG |
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 | ||
7c673cae FG |
21 | #include "rocksdb/convenience.h" |
22 | #include "rocksdb/db_dump_tool.h" | |
11fdf7f2 | 23 | #include "util/gflags_compat.h" |
7c673cae FG |
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) { | |
11fdf7f2 | 32 | GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, true); |
7c673cae FG |
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 | ||
f67539c2 | 39 | ROCKSDB_NAMESPACE::UndumpOptions undump_options; |
7c673cae FG |
40 | undump_options.db_path = FLAGS_db_path; |
41 | undump_options.dump_location = FLAGS_dump_location; | |
42 | undump_options.compact_db = FLAGS_compact; | |
43 | ||
f67539c2 | 44 | ROCKSDB_NAMESPACE::Options db_options; |
7c673cae | 45 | if (FLAGS_db_options != "") { |
f67539c2 TL |
46 | ROCKSDB_NAMESPACE::Options parsed_options; |
47 | ROCKSDB_NAMESPACE::Status s = ROCKSDB_NAMESPACE::GetOptionsFromString( | |
7c673cae FG |
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 | ||
f67539c2 | 56 | ROCKSDB_NAMESPACE::DbUndumpTool tool; |
7c673cae FG |
57 | if (!tool.Run(undump_options, db_options)) { |
58 | return 1; | |
59 | } | |
60 | return 0; | |
61 | } | |
62 | #endif // !(defined GFLAGS) || defined(ROCKSDB_LITE) |