10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/oplogreplayer/replayer.rb', line 10
def self.m2m(options)
config = options[:config]
timestamp = options[:timestamp]
log = Log4r::Logger.new('Oplogreplayer::Replayer')
log.outputters = Log4r::StdoutOutputter.new(STDERR)
log.level = Log4r::INFO
self.parseConfig(@_config, config)
sourceConfig = @_config["source"]
connect_uri = "mongodb://"
connect_uri += "#{sourceConfig["username"]}:#{sourceConfig["password"]}@" if sourceConfig["username"] and sourceConfig["password"]
connect_uri += "#{sourceConfig["host"]}"
connect_uri += "?replicaSet=#{sourceConfig["replicaSet"]}"
log.info("Setting up client for source")
rsClient = Mongo::MongoReplicaSetClient.from_uri(connect_uri)
log.info("Configuring tailer")
tailer = Mongoriver::Tailer.new([rsClient], :existing)
log.info("Creating mongo2mongo bridge")
bridge = Oplogreplayer::Mongobridge.new(@_config["dest"])
log.info("Creating a stream between tailer and bridge")
stream = Mongoriver::Stream.new(tailer, bridge)
if timestamp
log.info("Replaying. Timestamp provided, overriding and starting at #{timestamp}")
stream.run_forever(timestamp)
elsif @_config["resume"]
log.info("Replaying. No timestamp provided but resume is enabled, will resume based on target's last timestamp")
stream.run_forever(bridge.getOplogTimestamp)
else
log.info("Replaying. No resume and no timestamp - full oplog replay.")
stream.run_forever()
end
end
|