3 /// Utility to dump tarball backup records to stdout.
7 Copyright (C) 2010-2012, 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>
31 #include "barrygetopt.h"
34 using namespace Barry
;
38 int logical
, major
, minor
;
39 const char *Version
= Barry::Version(logical
, major
, minor
);
42 << "btardump - Command line parser for Barry backup files\n"
43 << " Copyright 2010-2012, Net Direct Inc. (http://www.netdirect.ca/)\n"
44 << " Using: " << Version
<< "\n"
46 << " -d db Name of database to dump. Can be used multiple times\n"
47 << " to parse multiple databases at once. If not specified\n"
48 << " at all, all available databases from the backup are\n"
51 << " -i cs International charset for string conversions\n"
52 << " Valid values here are available with 'iconv --list'\n"
53 #ifdef __BARRY_SYNC_MODE__
54 << " -V Dump records using MIME vformats where possible\n"
57 << " [files...] Backup file(s), created by btool or the backup GUI.\n"
61 class MyAllRecordDumpStore
: public AllRecordStore
67 explicit MyAllRecordDumpStore(std::ostream
&os
, bool vformat_mode
=false)
68 : m_vformat_mode(vformat_mode
)
75 #ifdef __BARRY_SYNC_MODE__
77 #define HANDLE_PARSER(tname) \
78 void operator() (const Barry::tname &r) \
80 if( m_vformat_mode ) \
81 MimeDump<tname>::Dump(m_os, r); \
83 m_os << r << std::endl; \
88 #define HANDLE_PARSER(tname) \
89 void operator() (const Barry::tname &r) \
91 m_os << r << std::endl; \
96 ALL_KNOWN_PARSER_TYPES
99 int main(int argc
, char *argv
[])
102 bool vformat_mode
= false;
104 vector
<string
> db_names
;
105 vector
<string
> backup_files
;
108 // process command line options
110 int cmd
= getopt(argc
, argv
, "d:hi:V");
116 case 'd': // show dbname
117 db_names
.push_back(string(optarg
));
120 case 'V': // vformat MIME mode
121 #ifdef __BARRY_SYNC_MODE__
124 cerr
<< "-V option not supported - no Sync "
125 "library support available\n";
130 case 'i': // international charset (iconv)
131 iconvCharset
= optarg
;
141 // grab all backup filenames
142 while( optind
< argc
) {
143 backup_files
.push_back(string(argv
[optind
++]));
146 if( backup_files
.size() == 0 ) {
155 // Create an IConverter object if needed
156 auto_ptr
<IConverter
> ic
;
157 if( iconvCharset
.size() ) {
158 ic
.reset( new IConverter(iconvCharset
.c_str(), true) );
161 // create the parser, and use stdout dump objects for output
162 AllRecordParser
parser(cout
,
163 new HexDumpParser(cout
),
164 new MyAllRecordDumpStore(cout
, vformat_mode
));
166 for( size_t i
= 0; i
< backup_files
.size(); i
++ ) {
168 cout
<< "Reading file: " << backup_files
[i
] << endl
;
170 Restore
builder(backup_files
[i
]);
172 // add desired database names
173 for( size_t j
= 0; j
< db_names
.size(); j
++ ) {
174 builder
.AddDB(db_names
[i
]);
177 // create the pipe to connect builder to parser and
180 pipe
.PumpFile(parser
, ic
.get());
184 catch( exception
&e
) {
185 cerr
<< e
.what() << endl
;