3 /// Utility to dump tarball backup records to stdout.
7 Copyright (C) 2010-2011, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include <barry/barry.h>
23 #ifdef __BARRY_SYNC_MODE__
24 #include <barry/barrysync.h>
27 #include <barry/barrybackup.h>
33 using namespace Barry
;
38 const char *Version
= Barry::Version(major
, minor
);
41 << "btardump - Command line parser for Barry backup files\n"
42 << " Copyright 2010-2011, Net Direct Inc. (http://www.netdirect.ca/)\n"
43 << " Using: " << Version
<< "\n"
45 << " -d db Name of database to dump. Can be used multiple times\n"
46 << " to parse multiple databases at once. If not specified\n"
47 << " at all, all available databases from the backup are\n"
50 << " -i cs International charset for string conversions\n"
51 << " Valid values here are available with 'iconv --list'\n"
52 #ifdef __BARRY_SYNC_MODE__
53 << " -V Dump records using MIME vformats where possible\n"
56 << " [files...] Backup file(s), created by btool or the backup GUI.\n"
60 class MyAllRecordDumpStore
: public AllRecordStore
66 explicit MyAllRecordDumpStore(std::ostream
&os
, bool vformat_mode
=false)
67 : m_vformat_mode(vformat_mode
)
73 #define HANDLE_PARSER(tname) \
74 void operator() (const Barry::tname &r) \
76 if( m_vformat_mode ) \
77 MimeDump<tname>::Dump(m_os, r); \
79 m_os << r << std::endl; \
82 ALL_KNOWN_PARSER_TYPES
85 int main(int argc
, char *argv
[])
88 bool vformat_mode
= false;
90 vector
<string
> db_names
;
91 vector
<string
> backup_files
;
94 // process command line options
96 int cmd
= getopt(argc
, argv
, "d:hi:V");
102 case 'd': // show dbname
103 db_names
.push_back(string(optarg
));
106 case 'V': // vformat MIME mode
107 #ifdef __BARRY_SYNC_MODE__
110 cerr
<< "-V option not supported - no Sync "
111 "library support available\n";
116 case 'i': // international charset (iconv)
117 iconvCharset
= optarg
;
127 // grab all backup filenames
128 while( optind
< argc
) {
129 backup_files
.push_back(string(argv
[optind
++]));
132 if( backup_files
.size() == 0 ) {
141 // Create an IConverter object if needed
142 auto_ptr
<IConverter
> ic
;
143 if( iconvCharset
.size() ) {
144 ic
.reset( new IConverter(iconvCharset
.c_str(), true) );
147 // create the parser, and use stdout dump objects for output
148 AllRecordParser
parser(cout
,
149 new HexDumpParser(cout
),
150 new MyAllRecordDumpStore(cout
, vformat_mode
));
152 for( size_t i
= 0; i
< backup_files
.size(); i
++ ) {
154 cout
<< "Reading file: " << backup_files
[i
] << endl
;
156 Restore
builder(backup_files
[i
]);
158 // add desired database names
159 for( size_t j
= 0; j
< db_names
.size(); j
++ ) {
160 builder
.AddDB(db_names
[i
]);
163 // create the pipe to connect builder to parser and
166 pipe
.PumpFile(parser
, ic
.get());
170 catch( exception
&e
) {
171 cerr
<< e
.what() << endl
;