36 #define PROG_NAME "xapian-replicate" 37 #define PROG_DESC "Replicate a database from a master server to a local copy" 43 #define DEFAULT_INTERVAL 60 46 #define READER_CLOSE_TIME 30 49 #define DEFAULT_TIMEOUT 0 52 cout <<
"Usage: " PROG_NAME " [OPTIONS] DATABASE\n\n" 54 " -h, --host=HOST host to connect to (required)\n" 55 " -p, --port=PORT port to connect to (required)\n" 56 " -m, --master=DB replicate database DB from the master (default: DATABASE)\n" 57 " -i, --interval=N wait N seconds between each connection to the master\n" 59 " -r, --reader-time=N wait N seconds to allow readers time to close before\n" 61 " -t, --timeout=N set socket timeouts (if supported) to N seconds; N=0 for\n" 63 " -f, --force-copy force a full copy of the database to be sent (and then\n" 64 " replicate as normal)\n" 65 " -o, --one-shot replicate only once and then exit\n" 66 " -q, --quiet only report errors\n" 67 " -v, --verbose be more verbose\n" 68 " --help display this help and exit\n" 69 " --version output version information and exit\n";
73 main(
int argc,
char **argv)
75 const char *
opts =
"h:p:m:i:r:t:ofqv";
76 static const struct option long_opts[] = {
96 bool one_shot =
false;
97 enum { NORMAL, VERBOSE, QUIET } verbosity = NORMAL;
98 bool force_copy =
false;
118 reader_close_time = atoi(
optarg);
154 cout <<
"Host required - specify with --host=HOST\n\n";
160 cout <<
"Port required - specify with --port=PORT\n\n";
166 string dbpath(argv[
optind]);
168 if (masterdb.empty())
173 if (verbosity == VERBOSE) {
174 cout <<
"Connecting to " << host <<
":" << port <<
'\n';
176 ReplicateTcpClient client(host, port, 10.0, timeout);
177 if (verbosity == VERBOSE) {
178 cout <<
"Getting update for " << dbpath <<
" from " 182 client.update_from_master(dbpath, masterdb, info,
183 reader_close_time, force_copy);
184 if (verbosity == VERBOSE) {
185 cout <<
"Update complete: " 188 << (info.
changed ?
"new live database" 189 :
"no changes to live database")
192 if (verbosity != QUIET) {
195 "Replication using a full copy failed. This usually means that the master\n" 196 "database is changing too frequently. Ensure that sufficient changesets are\n" 197 "present by setting XAPIAN_MAX_CHANGESETS on the master.\n";
215 }
catch (
const exception &e) {
216 cerr <<
"Caught standard exception: " << e.what() <<
'\n';
219 cerr <<
"Caught unknown exception\n";
Wrappers to allow GNU getopt to be used cleanly from C++ code.
unsigned timeout
A timeout value in milliseconds.
int gnu_getopt_long(int argc_, char *const *argv_, const char *shortopts_, const struct option *longopts_, int *optind_)
int fullcopy_count
Number of times a full database copy was performed.
int main(int argc, char **argv)
void sleep(double t)
Sleep until the time represented by this object.
#define STRINGIZE(X)
The STRINGIZE macro converts its parameter into a string constant.
TCP/IP replication client class.
Public interfaces for the Xapian library.
Information about the steps involved in performing a replication.
int changeset_count
Number of changesets applied.
#define required_argument
bool changed
True if and only if the replication corresponds to a change in the live version of the database...
std::string get_description() const
Return a string describing this object.
#define READER_CLOSE_TIME
All exceptions thrown by Xapian are subclasses of Xapian::Error.
Indicates a problem communicating with a remote database.
Various handy helpers which std::string really should provide.
<unistd.h>, but with compat.