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>
26 #include <barry/barrybackup.h>
30 #include "barrygetopt.h"
34 using namespace Barry
;
38 int logical
, major
, minor
;
39 const char *Version
= Barry::Version(logical
, major
, minor
);
41 #ifdef __BARRY_SYNC_MODE__
42 string sync_mode
= _(" -V Dump records using MIME vformats where possible");
47 cerr
<< string_vprintf(
48 _("btardump - Command line parser for Barry backup files\n"
49 " Copyright 2010-2012, Net Direct Inc. (http://www.netdirect.ca/)\n"
52 " -d db Name of database to dump. Can be used multiple times\n"
53 " to parse multiple databases at once. If not specified\n"
54 " at all, all available databases from the backup are\n"
57 " -i cs International charset for string conversions\n"
58 " Valid values here are available with 'iconv --list'\n"
61 " [files...] Backup file(s), created by btool or the backup GUI.\n"),
67 class MyAllRecordDumpStore
: public AllRecordStore
73 explicit MyAllRecordDumpStore(std::ostream
&os
, bool vformat_mode
=false)
74 : m_vformat_mode(vformat_mode
)
81 #ifdef __BARRY_SYNC_MODE__
83 #define HANDLE_PARSER(tname) \
84 void operator() (const Barry::tname &r) \
86 if( m_vformat_mode ) \
87 MimeDump<tname>::Dump(m_os, r); \
89 m_os << r << std::endl; \
94 #define HANDLE_PARSER(tname) \
95 void operator() (const Barry::tname &r) \
97 m_os << r << std::endl; \
102 ALL_KNOWN_PARSER_TYPES
105 int main(int argc
, char *argv
[])
110 bool vformat_mode
= false;
112 vector
<string
> db_names
;
113 vector
<string
> backup_files
;
116 // process command line options
118 int cmd
= getopt(argc
, argv
, "d:hi:V");
124 case 'd': // show dbname
125 db_names
.push_back(string(optarg
));
128 case 'V': // vformat MIME mode
129 #ifdef __BARRY_SYNC_MODE__
132 cerr
<< _("-V option not supported - no Sync library support available\n");
137 case 'i': // international charset (iconv)
138 iconvCharset
= optarg
;
148 // grab all backup filenames
149 while( optind
< argc
) {
150 backup_files
.push_back(string(argv
[optind
++]));
153 if( backup_files
.size() == 0 ) {
162 // Create an IConverter object if needed
163 auto_ptr
<IConverter
> ic
;
164 if( iconvCharset
.size() ) {
165 ic
.reset( new IConverter(iconvCharset
.c_str(), true) );
168 // create the parser, and use stdout dump objects for output
169 AllRecordParser
parser(cout
,
170 new HexDumpParser(cout
),
171 new MyAllRecordDumpStore(cout
, vformat_mode
));
173 for( size_t i
= 0; i
< backup_files
.size(); i
++ ) {
175 cout
<< _("Reading file: ") << backup_files
[i
] << endl
;
177 Restore
builder(backup_files
[i
]);
179 // add desired database names
180 for( size_t j
= 0; j
< db_names
.size(); j
++ ) {
181 builder
.AddDB(db_names
[i
]);
184 // create the pipe to connect builder to parser and
187 pipe
.PumpFile(parser
, ic
.get());
191 catch( exception
&e
) {
192 cerr
<< e
.what() << endl
;