summaryrefslogtreecommitdiff
path: root/jstests/disk/repair.js
blob: 072afa3cf08e95255ec18efecfbf006268cef6b7 (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
52
53
54
55
56
57
58
59
60
61
62
// check --repairpath and --repair

var baseName = "jstests_disk_repair";
var dbpath = MongoRunner.dataPath + baseName + "/";
var repairpath = dbpath + "repairDir/";

resetDbpath( dbpath );
resetDbpath( repairpath );

var m = MongoRunner.runMongod({
    dbpath: dbpath,
    repairpath: repairpath,
    noCleanData: true,
});
db = m.getDB( baseName );
db[ baseName ].save( {} );
assert.commandWorked( db.runCommand( {repairDatabase:1, backupOriginalFiles:true} ) );
function check() {
    files = listFiles( dbpath );
    for( f in files ) {
        assert( ! new RegExp( "^" + dbpath + "backup_" ).test( files[ f ].name ), "backup dir in dbpath" );
    }

    assert.eq.automsg( "1", "db[ baseName ].count()" );
}
check();
MongoRunner.stopMongod( m.port );

resetDbpath( repairpath );
m = MongoRunner.runMongod({
    port: m.port,
    dbpath: dbpath,
    noCleanData: true,
});
db = m.getDB( baseName );
assert.commandWorked( db.runCommand( {repairDatabase:1} ) );
check();
MongoRunner.stopMongod( m.port );

resetDbpath( repairpath );
rc = runMongoProgram("mongod", "--repair", "--port", m.port, "--dbpath", dbpath,
                     "--repairpath", repairpath);
assert.eq.automsg( "0", "rc" );
m = MongoRunner.runMongod({
    port: m.port,
    dbpath: dbpath,
    noCleanData: true,
});
db = m.getDB( baseName );
check();
MongoRunner.stopMongod( m.port );

resetDbpath( repairpath );
rc = runMongoProgram("mongod", "--repair", "--port", m.port, "--dbpath", dbpath);
assert.eq.automsg( "0", "rc" );
m = MongoRunner.runMongod({
    port: m.port,
    dbpath: dbpath,
    noCleanData: true,
});
db = m.getDB( baseName );
check();