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";
96 bool one_shot =
false;
97 enum { NORMAL, VERBOSE, QUIET } verbosity = NORMAL;
98 bool force_copy =
false;
110 (port < 1 || port > 65535)) {
111 cerr <<
"Error: must specify a valid port number "
112 "(between 1 and 65535). \n";
122 cout <<
"Interval must be a non-negative integer\n";
130 unsigned int reader_time;
132 cout <<
"reader close time must be a "
133 "non-negative integer\n";
137 reader_close_time = reader_time;
141 unsigned int socket_timeout;
143 cout <<
"timeout must be a non-negative integer\n";
147 timeout = socket_timeout;
180 cout <<
"Host required - specify with --host=HOST\n\n";
186 cout <<
"Port required - specify with --port=PORT\n\n";
192 string dbpath(argv[
optind]);
194 if (masterdb.empty())
199 if (verbosity == VERBOSE) {
200 cout <<
"Connecting to " << host <<
":" << port <<
'\n';
202 ReplicateTcpClient client(host, port, 10.0, timeout);
203 if (verbosity == VERBOSE) {
204 cout <<
"Getting update for " << dbpath <<
" from "
208 client.update_from_master(dbpath, masterdb, info,
209 reader_close_time, force_copy);
210 if (verbosity == VERBOSE) {
211 cout <<
"Update complete: "
214 << (info.
changed ?
"new live database"
215 :
"no changes to live database")
218 if (verbosity != QUIET) {
221 "Replication using a full copy failed. This usually means that the master\n"
222 "database is changing too frequently. Ensure that sufficient changesets are\n"
223 "present by setting XAPIAN_MAX_CHANGESETS on the master.\n";
241 }
catch (
const exception &e) {
242 cerr <<
"Caught standard exception: " << e.what() <<
'\n';
245 cerr <<
"Caught unknown exception\n";
All exceptions thrown by Xapian are subclasses of Xapian::Error.
std::string get_description() const
Return a string describing this object.
Indicates a problem communicating with a remote database.
Wrappers to allow GNU getopt to be used cleanly from C++ code.
#define required_argument
int gnu_getopt_long(int argc_, char *const *argv_, const char *shortopts_, const struct option *longopts_, int *optind_)
void sleep(double t)
Sleep until the time represented by this object.
Parse signed and unsigned type from string and check for trailing characters.
bool parse_signed(const char *p, T &res)
bool parse_unsigned(const char *p, T &res)
TCP/IP replication client class.
<unistd.h>, but with compat.
Various handy string-related helpers.
#define STRINGIZE(X)
The STRINGIZE macro converts its parameter into a string constant.
Information about the steps involved in performing a replication.
bool changed
True if and only if the replication corresponds to a change in the live version of the database.
int fullcopy_count
Number of times a full database copy was performed.
int changeset_count
Number of changesets applied.
static const struct option long_opts[]
int main(int argc, char **argv)
#define READER_CLOSE_TIME
Public interfaces for the Xapian library.