summaryrefslogtreecommitdiff
path: root/jstests/tool/dumpsecondary.js
blob: 15bd25f474597a1891a66eca18aff0ec6d6d9ed5 (plain)
1
2
3
4
5
6
7
8
9
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
var replTest = new ReplSetTest({name: 'testSet', nodes: 2});

var nodes = replTest.startSet();
replTest.initiate();

var master = replTest.getPrimary();
db = master.getDB("foo");
db.foo.save({a: 1000});
replTest.awaitReplication();
replTest.awaitSecondaryNodes();

assert.eq(1, db.foo.count(), "setup");

var slaves = replTest.liveNodes.slaves;
assert(slaves.length == 1, "Expected 1 slave but length was " + slaves.length);
slave = slaves[0];

var commonOptions = {};
if (jsTest.options().keyFile) {
    commonOptions.username = jsTest.options().authUser;
    commonOptions.password = jsTest.options().authPassword;
}

var exitCode =
    MongoRunner.runMongoTool("mongodump",
                             Object.extend({
                                 host: slave.host,
                                 out: MongoRunner.dataDir + "/jstests_tool_dumpsecondary_external/",
                             },
                                           commonOptions));
assert.eq(0, exitCode, "mongodump failed to dump data from the secondary");

db.foo.drop();
assert.eq(0, db.foo.count(), "after drop");

exitCode =
    MongoRunner.runMongoTool("mongorestore",
                             Object.extend({
                                 host: master.host,
                                 dir: MongoRunner.dataDir + "/jstests_tool_dumpsecondary_external/",
                             },
                                           commonOptions));
assert.eq(0, exitCode, "mongorestore failed to restore data to the primary");

assert.soon("db.foo.findOne()", "no data after sleep");
assert.eq(1, db.foo.count(), "after restore");
assert.eq(1000, db.foo.findOne().a, "after restore 2");

resetDbpath(MongoRunner.dataDir + '/jstests_tool_dumpsecondary_external');

replTest.stopSet(15);