34 namespace bpo = boost::program_options;
36 static const char* OPT_BLOCK_NUM =
"snapshot-at-block";
37 static const char* OPT_BLOCK_TIME =
"snapshot-at-time";
38 static const char* OPT_DEST =
"snapshot-to";
40 void snapshot_plugin::plugin_set_program_options(
41 boost::program_options::options_description& command_line_options,
42 boost::program_options::options_description& config_file_options)
44 command_line_options.add_options()
45 (OPT_BLOCK_NUM, bpo::value<uint32_t>(),
"Block number after which to do a snapshot")
46 (OPT_BLOCK_TIME, bpo::value<string>(),
"Block time (ISO format) after which to do a snapshot")
47 (OPT_DEST, bpo::value<string>(),
"Pathname of JSON file where to store the snapshot")
49 config_file_options.add(command_line_options);
52 std::string snapshot_plugin::plugin_name()
const
57 std::string snapshot_plugin::plugin_description()
const
59 return "Create snapshots at a specified time or block number.";
62 void snapshot_plugin::plugin_initialize(
const boost::program_options::variables_map& options)
64 ilog(
"snapshot plugin: plugin_initialize() begin");
66 if( options.count(OPT_BLOCK_NUM) > 0 || options.count(OPT_BLOCK_TIME) > 0 )
69 "Must specify snapshot-to in addition to snapshot-at-block or snapshot-at-time!" );
70 dest = options[OPT_DEST].as<std::string>();
71 if( options.count(OPT_BLOCK_NUM) > 0 )
72 snapshot_block = options[OPT_BLOCK_NUM].as<uint32_t>();
73 if( options.count(OPT_BLOCK_TIME) > 0 )
81 ilog(
"snapshot plugin is not enabled because neither snapshot-at-block nor snapshot-at-time is specified");
83 ilog(
"snapshot plugin: plugin_initialize() end");
88 ilog(
"snapshot plugin: creating snapshot");
96 wlog(
"Failed to open snapshot destination: ${ex}", (
"ex",e) );
99 for( uint32_t space_id = 0; space_id < 256; space_id++ )
100 for( uint32_t type_id = 0; type_id < 256; type_id++ )
104 db.
get_index( (uint8_t)space_id, (uint8_t)type_id );
106 catch (fc::assert_exception& e)
110 auto&
index = db.
get_index( (uint8_t)space_id, (uint8_t)type_id );
116 ilog(
"snapshot plugin: created snapshot");
122 if( (last_block < snapshot_block && snapshot_block <= current_block)
123 || (last_time < snapshot_time && snapshot_time <= b.
timestamp) )
124 create_snapshot(
database(), dest );
125 last_block = current_block;