From 8d943c81b94243c2c408e8f75fff4a32f05d5320 Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Tue, 30 Nov 2010 22:16:51 -0500 Subject: [PATCH] tools: added btardump for parsing backup files from command line --- ChangeLog | 1 + tools/Makefile.am | 9 +++++ tools/btardump.cc | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 tools/btardump.cc diff --git a/ChangeLog b/ChangeLog index 8fb14ab4..11488b7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22,6 +22,7 @@ Release: version 0.17.0 - 2010/01/?? and TeeParser - examples: added pipedump.cc to demo how to use some of the new builders, parsers, and pipe class + - tools: added btardump for parsing backup files from command line 2010/11/16 - doc: clarified btool -X in its man page 2010/11/09 diff --git a/tools/Makefile.am b/tools/Makefile.am index 4c8307f8..37520395 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -34,6 +34,9 @@ endif if WITH_FUSE bin_PROGRAMS += bfuse endif +if WITH_BACKUP +bin_PROGRAMS += btardump +endif sbin_PROGRAMS = bcharge breset pppob @@ -109,6 +112,12 @@ bfuse_CXXFLAGS = $(FUSE_CFLAGS) bfuse_LDADD = ../src/libbarry.la $(FUSE_LIBS) -lpthread $(LTLIBINTL) endif +if WITH_BACKUP +btardump_SOURCES = btardump.cc +btardump_LDADD = ../src/libbarry.la $(LIBUSB_LIBS) \ + ../src/libbarrybackup.la -lpthread $(LTLIBINTL) +endif + brimtrans_SOURCES = brimtrans.cc brimtrans_LDADD = $(LTLIBINTL) diff --git a/tools/btardump.cc b/tools/btardump.cc new file mode 100644 index 00000000..27fca78c --- /dev/null +++ b/tools/btardump.cc @@ -0,0 +1,119 @@ +/// +/// \file tardump.cc +/// Utility to dump tarball backup records to stdout. +/// + +/* + Copyright (C) 2010, Net Direct Inc. (http://www.netdirect.ca/) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License in the COPYING file at the + root directory of this project for more details. +*/ + +#include +#include +#include +#include +#include + +using namespace std; +using namespace Barry; + +void Usage() +{ + int major, minor; + const char *Version = Barry::Version(major, minor); + + cerr + << "btardump - Command line parser for Barry backup files\n" + << " Copyright 2010, Net Direct Inc. (http://www.netdirect.ca/)\n" + << " Using: " << Version << "\n" + << "\n" + << " -d db Name of database to dump. Can be used multiple times\n" + << " to parse multiple databases at once. If not specified\n" + << " at all, all available databases from the backup are\n" + << " dumped.\n" + << " -h This help\n" + << endl; +} + +int main(int argc, char *argv[]) +{ + try { + + vector db_names; + vector backup_files; + + // process command line options + for(;;) { + int cmd = getopt(argc, argv, "d:h"); + if( cmd == -1 ) + break; + + switch( cmd ) + { + case 'd': // show dbname + db_names.push_back(string(optarg)); + break; + + case 'h': // help + default: + Usage(); + return 0; + } + } + + // grab all backup filenames + while( optind < argc ) { + backup_files.push_back(string(argv[optind++])); + } + + if( backup_files.size() == 0 ) { + Usage(); + return 0; + } + + + + Barry::Init(); + + // create the parser, and use stdout dump objects for output + AllRecordParser parser(cout, + new HexDumpParser(cout), + new AllRecordDumpStore(cout)); + + for( size_t i = 0; i < backup_files.size(); i++ ) { + + cout << "Reading file: " << backup_files[i] << endl; + + Restore builder(backup_files[i]); + + // add desired database names + for( size_t j = 0; j < db_names.size(); j++ ) { + builder.AddDB(db_names[i]); + } + + // create the pipe to connect builder to parser and + // move the data + Pipe pipe(builder); + pipe.PumpFile(parser); + } + + } + catch( exception &e ) { + cerr << e.what() << endl; + return 1; + } + + return 0; +} + -- 2.11.4.GIT