diff options
-rw-r--r-- | jstests/disk/directoryperdb.js | 14 | ||||
-rwxr-xr-x | jstests/dur/dur1_tool.js | 13 | ||||
-rw-r--r-- | jstests/tool/dumprestore2.js | 29 | ||||
-rw-r--r-- | jstests/tool/dumprestore_auth3.js | 418 | ||||
-rw-r--r-- | jstests/tool/dumprestore_repair.js | 47 | ||||
-rw-r--r-- | jstests/tool/exportimport2.js | 24 | ||||
-rw-r--r-- | jstests/tool/shim1.js | 240 | ||||
-rw-r--r-- | jstests/tool/tool1.js | 22 | ||||
-rw-r--r-- | jstests/tool/tool_replset.js | 13 |
9 files changed, 199 insertions, 621 deletions
diff --git a/jstests/disk/directoryperdb.js b/jstests/disk/directoryperdb.js index c14091cfdb2..dc21860caba 100644 --- a/jstests/disk/directoryperdb.js +++ b/jstests/disk/directoryperdb.js @@ -40,20 +40,6 @@ var backupDir = dbpath + "/backup_repairDatabase_0/"; checkDir( backupDir ); assert.eq( 1, db[ baseName ].count() , "C" ); -// tool test -stopMongod( port ); - -externalPath = MongoRunner.dataPath + baseDir + "_external/"; - -runMongoProgram( "mongodump", "--dbpath", dbpath, "--directoryperdb", "--out", externalPath ); -resetDbpath( dbpath ); -runMongoProgram( "mongorestore", "--dbpath", dbpath, "--directoryperdb", "--dir", externalPath ); -m = startMongodTest(port, baseDir, true, {directoryperdb : "", nohttpinterface : "", bind_ip : "127.0.0.1"}); -db = m.getDB( baseName ); -checkDir( dbpath ); -assert.eq( 1, db[ baseName ].count() , "C" ); -assert( m.getDBs().totalSize > 0, "bad size calc" ); - // drop db test db.dropDatabase(); files = listFiles( dbpath ); diff --git a/jstests/dur/dur1_tool.js b/jstests/dur/dur1_tool.js index adee933fdb4..f50c3d123c2 100755 --- a/jstests/dur/dur1_tool.js +++ b/jstests/dur/dur1_tool.js @@ -111,13 +111,14 @@ stopMongod(30001, /*signal*/9); // journal file should be present, and non-empty as we killed hard -// mongorestore with --dbpath and --journal options should do a recovery pass +// mongod with --dbpath and --journal options should do a recovery pass // empty.bson is an empty file so it won't actually insert anything -log("use mongorestore to recover"); -runMongoProgram("mongorestore", "--dbpath", path2, "--journal", "-d", "test", "-c", "empty", "jstests/dur/data/empty.bson"); - -// stopMongod seems to be asynchronous (hmmm) so we sleep here. -// sleep(5000); +log("use mongod to recover"); +conn = startMongoProgram('mongod', '--port', 30001, '--dbpath', path2, + '--journal', '--smallfiles', + '--nohttpinterface', '--noprealloc', '--bind_ip', '127.0.0.1'); +verify(); +stopMongod(30001); // at this point, after clean shutdown, there should be no journal files log("check no journal files (after presumably clean shutdown)"); diff --git a/jstests/tool/dumprestore2.js b/jstests/tool/dumprestore2.js deleted file mode 100644 index 31822e5b381..00000000000 --- a/jstests/tool/dumprestore2.js +++ /dev/null @@ -1,29 +0,0 @@ -// dumprestore2.js - -t = new ToolTest( "dumprestore2" ); - -c = t.startDB( "foo" ); -assert.eq( 0 , c.count() , "setup1" ); -c.save( { a : 22 } ); -assert.eq( 1 , c.count() , "setup2" ); -t.stop(); - -// SERVER-2501 on Windows the mongod may still be running at this point, so we wait for it to stop. -sleep( 5000 ); - -t.runTool( "dump" , "--dbpath" , t.dbpath , "--out" , t.ext ); - -resetDbpath( t.dbpath ); -assert.eq( 0 , listFiles( t.dbpath ).length , "clear" ); - -t.runTool( "restore" , "--dbpath" , t.dbpath , "--dir" , t.ext ); - -listFiles( t.dbpath ).forEach( printjson ) - -c = t.startDB( "foo" ); -assert.soon( "c.findOne()" , "no data after startup" ); -assert.eq( 1 , c.count() , "after restore 2" ); -assert.eq( 22 , c.findOne().a , "after restore 2" ); - -t.stop(); - diff --git a/jstests/tool/dumprestore_auth3.js b/jstests/tool/dumprestore_auth3.js index 295aad18dfa..6b71d51ed9f 100644 --- a/jstests/tool/dumprestore_auth3.js +++ b/jstests/tool/dumprestore_auth3.js @@ -2,231 +2,197 @@ // Tests that mongodump and mongorestore properly handle access control information when doing // single-db dumps and restores -// Runs the tool with the given name against the given mongod. If shutdownServer is true, -// first shuts down the mongod and uses the --dbpath option to the tool to operate on the data -// files directly -// XXX: Do not check tool exit code. See SERVER-5520 -function runTool(toolName, mongod, shutdownServer, options) { - if (shutdownServer) { - MongoRunner.stopMongod(mongod); - var opts = {dbpath: mongod.fullOptions.pathOpts.dbpath}; - Object.extend(opts, options); - MongoRunner.runMongoTool(toolName, opts); - mongod.fullOptions.restart = true; - return MongoRunner.runMongod(mongod.fullOptions); - } else { - var opts = {host: mongod.host}; - Object.extend(opts, options); - MongoRunner.runMongoTool(toolName, opts); - return mongod; - } +// Runs the tool with the given name against the given mongod. +function runTool(toolName, mongod, options) { + var opts = {host: mongod.host}; + Object.extend(opts, options); + MongoRunner.runMongoTool(toolName, opts); } -// If shutdownServer is true, will run tools against shut down mongod, operating on the data -// files directly -function runTest(shutdownServer) { - var mongod = MongoRunner.runMongod(); - var admindb = mongod.getDB("admin"); - var db = mongod.getDB("foo"); - var shutMessage = "(no shutdown)"; - if (shutdownServer) { - shutMessage = "(shutdown)" - } - - jsTestLog("Creating Admin user & initial data "+shutMessage); - admindb.createUser({user: 'root', pwd: 'pass', roles: ['root']}); - admindb.createUser({user: 'backup', pwd: 'pass', roles: ['backup']}); - admindb.createUser({user: 'restore', pwd: 'pass', roles: ['restore']}); - admindb.createRole({role: "dummyRole", roles: [], privileges:[]}); - db.createUser({user: 'user', pwd: 'pass', roles: jsTest.basicUserRoles}); - db.createRole({role: 'role', roles: [], privileges:[]}); - var backupActions = ['find']; - db.createRole({role: 'backupFooChester', - privileges: [{resource: {db: 'foo', collection: 'chester'}, actions: backupActions}], - roles: []}); - db.createUser({user: 'backupFooChester', pwd: 'pass', roles: ['backupFooChester']}); - - var userCount = db.getUsers().length; - var rolesCount = db.getRoles().length; - var adminUsersCount = admindb.getUsers().length; - var adminRolesCount = admindb.getRoles().length; - var systemUsersCount = admindb.system.users.count(); - var systemVersionCount = admindb.system.version.count(); - - db.bar.insert({a:1}); - - assert.eq(1, db.bar.findOne().a); - assert.eq(userCount, db.getUsers().length, "setup"); - assert.eq(rolesCount, db.getRoles().length, "setup2"); - assert.eq(adminUsersCount, admindb.getUsers().length, "setup3"); - assert.eq(adminRolesCount, admindb.getRoles().length, "setup4"); - assert.eq(systemUsersCount, admindb.system.users.count(), "setup5"); - assert.eq(systemVersionCount, admindb.system.version.count(),"system version"); - assert.eq(1, admindb.system.users.count({user: "restore"}), "Restore user is missing"); - assert.eq(1, admindb.system.users.count({user: "backup"}), "Backup user is missing"); - var versionDoc = admindb.system.version.findOne(); - - jsTestLog("Dump foo database without dumping user data "+shutMessage); - var dumpDir = MongoRunner.getAndPrepareDumpDirectory("dumprestore_auth3"); - mongod = runTool("mongodump", mongod, shutdownServer, {out: dumpDir, db: "foo"}); - db = mongod.getDB('foo'); - - db.dropDatabase(); - db.dropAllUsers(); - db.dropAllRoles(); - - jsTestLog("Restore foo database from dump that doesn't contain user data "+shutMessage); - mongod = runTool("mongorestore", mongod, shutdownServer, {dir: dumpDir + "foo/", - db: 'foo', - restoreDbUsersAndRoles: ""}); - - db = mongod.getDB('foo'); - - assert.soon(function() { return db.bar.findOne(); }, "no data after restore"); - assert.eq(1, db.bar.findOne().a); - assert.eq(0, db.getUsers().length, "Restore created users somehow"); - assert.eq(0, db.getRoles().length, "Restore created roles somehow"); - - // Re-create user data - db.createUser({user: 'user', pwd: 'password', roles: jsTest.basicUserRoles}); - db.createRole({role: 'role', roles: [], privileges:[]}); - userCount = 1; - rolesCount = 1; - - assert.eq(1, db.bar.findOne().a); - assert.eq(userCount, db.getUsers().length, "didn't create user"); - assert.eq(rolesCount, db.getRoles().length, "didn't create role"); - - jsTestLog("Dump foo database *with* user data "+shutMessage); - mongod = runTool("mongodump", mongod, shutdownServer, {out: dumpDir, - db: "foo", - dumpDbUsersAndRoles: ""}); - db = mongod.getDB('foo'); - - db.dropDatabase(); - db.dropAllUsers(); - db.dropAllRoles(); - - assert.eq(0, db.getUsers().length, "didn't drop users"); - assert.eq(0, db.getRoles().length, "didn't drop roles"); - assert.eq(0, db.bar.count(), "didn't drop 'bar' collection"); - - jsTestLog("Restore foo database without restoring user data, even though it's in the dump "+shutMessage); - mongod = runTool("mongorestore", mongod, shutdownServer, {dir: dumpDir + "foo/", db: 'foo'}); - db = mongod.getDB('foo'); - - assert.soon(function() { return db.bar.findOne(); }, "no data after restore"); - assert.eq(1, db.bar.findOne().a); - assert.eq(0, db.getUsers().length, "Restored users even though it shouldn't have"); - assert.eq(0, db.getRoles().length, "Restored roles even though it shouldn't have"); - - jsTestLog("Restore foo database *with* user data "+shutMessage); - mongod = runTool("mongorestore", mongod, shutdownServer, {dir: dumpDir + "foo/", - db: 'foo', - restoreDbUsersAndRoles: ""}); - db = mongod.getDB('foo'); - admindb = mongod.getDB('admin'); - - assert.soon(function() { return db.bar.findOne(); }, "no data after restore"); - assert.eq(1, db.bar.findOne().a); - assert.eq(userCount, db.getUsers().length, "didn't restore users"); - assert.eq(rolesCount, db.getRoles().length, "didn't restore roles"); - assert.eq(1, admindb.system.users.count({user: "restore", db: "admin"}), "Restore user is missing"); - assert.docEq(versionDoc, - db.getSiblingDB('admin').system.version.findOne(), - "version doc was changed by restore"); - - jsTestLog("Make modifications to user data that should be overridden by the restore "+shutMessage); - db.dropUser('user') - db.createUser({user: 'user2', pwd: 'password2', roles: jsTest.basicUserRoles}); - db.dropRole('role') - db.createRole({role: 'role2', roles: [], privileges:[]}); - - jsTestLog("Restore foo database (and user data) with --drop so it overrides the changes made "+shutMessage); - // Restore with --drop to override the changes to user data - mongod = runTool("mongorestore", mongod, shutdownServer, {dir: dumpDir + "foo/", - db: 'foo', - drop: "", - restoreDbUsersAndRoles: ""}); - db = mongod.getDB('foo'); - admindb = mongod.getDB('admin'); - - assert.soon(function() { return db.bar.findOne(); }, "no data after restore"); - assert.eq(adminUsersCount, admindb.getUsers().length, "Admin users were dropped"); - assert.eq(adminRolesCount, admindb.getRoles().length, "Admin roles were dropped"); - assert.eq(1, db.bar.findOne().a); - assert.eq(userCount, db.getUsers().length, "didn't restore users"); - assert.eq("user", db.getUser('user').user, "didn't update user"); - assert.eq(rolesCount, db.getRoles().length, "didn't restore roles"); - assert.eq("role", db.getRole('role').role, "didn't update role"); - assert.docEq(versionDoc, - db.getSiblingDB('admin').system.version.findOne(), - "version doc was changed by restore"); - - - jsTestLog("Dump just the admin database. User data should be dumped by default "+shutMessage); - // Make a user in another database to make sure it is properly captured - db.getSiblingDB('bar').createUser({user: "user", pwd: 'pwd', roles: []}); - db.getSiblingDB('admin').createUser({user: "user", pwd: 'pwd', roles: []}); - adminUsersCount += 1; - mongod = runTool("mongodump", mongod, shutdownServer, {out: dumpDir, db: "admin"}); - db = mongod.getDB('foo'); - - // Change user data a bit. - db.dropAllUsers(); - db.getSiblingDB('bar').createUser({user: "user2", pwd: 'pwd', roles: []}); - db.getSiblingDB('admin').dropAllUsers(); - - jsTestLog("Restore just the admin database. User data should be restored by default "+shutMessage); - mongod = runTool("mongorestore", mongod, shutdownServer, {dir: dumpDir + "admin/", - db: 'admin', - drop: ""}); - db = mongod.getDB('foo'); - var otherdb = db.getSiblingDB('bar'); - var admindb = db.getSiblingDB('admin'); - - assert.soon(function() { return db.bar.findOne(); }, "no data after restore"); - assert.eq(1, db.bar.findOne().a); - assert.eq(userCount, db.getUsers().length, "didn't restore users"); - assert.eq("user", db.getUser('user').user, "didn't restore user"); - assert.eq(rolesCount, db.getRoles().length, "didn't restore roles"); - assert.eq("role", db.getRole('role').role, "didn't restore role"); - assert.eq(1, otherdb.getUsers().length, "didn't restore users for bar database"); - assert.eq("user", otherdb.getUsers()[0].user, "didn't restore user for bar database"); - assert.eq(adminUsersCount, admindb.getUsers().length, "didn't restore users for admin database"); - assert.eq("user", admindb.getUser("user").user, "didn't restore user for admin database"); - assert.eq(6, admindb.system.users.count(), "has the wrong # of users for the whole server"); - assert.eq(2, admindb.system.roles.count(), "has the wrong # of roles for the whole server"); - assert.docEq(versionDoc, - db.getSiblingDB('admin').system.version.findOne(), - "version doc was changed by restore"); - - jsTestLog("Dump all databases "+shutMessage); - mongod = runTool("mongodump", mongod, shutdownServer, {out: dumpDir}); - db = mongod.getDB('foo'); - - db.dropDatabase(); - db.dropAllUsers(); - db.dropAllRoles(); - - assert.eq(0, db.getUsers().length, "didn't drop users"); - assert.eq(0, db.getRoles().length, "didn't drop roles"); - assert.eq(0, db.bar.count(), "didn't drop 'bar' collection"); - - jsTestLog("Restore all databases "+shutMessage); - mongod = runTool("mongorestore", mongod, shutdownServer, {dir: dumpDir}); - db = mongod.getDB('foo'); - - assert.soon(function() { return db.bar.findOne(); }, "no data after restore"); - assert.eq(1, db.bar.findOne().a); - assert.eq(1, db.getUsers().length, "didn't restore users"); - assert.eq(1, db.getRoles().length, "didn't restore roles"); - assert.docEq(versionDoc, - db.getSiblingDB('admin').system.version.findOne(), - "version doc was changed by restore"); - - MongoRunner.stopMongod(mongod); -} - -runTest(false); -runTest(true); +var mongod = MongoRunner.runMongod(); +var admindb = mongod.getDB("admin"); +var db = mongod.getDB("foo"); + +jsTestLog("Creating Admin user & initial data"); +admindb.createUser({user: 'root', pwd: 'pass', roles: ['root']}); +admindb.createUser({user: 'backup', pwd: 'pass', roles: ['backup']}); +admindb.createUser({user: 'restore', pwd: 'pass', roles: ['restore']}); +admindb.createRole({role: "dummyRole", roles: [], privileges:[]}); +db.createUser({user: 'user', pwd: 'pass', roles: jsTest.basicUserRoles}); +db.createRole({role: 'role', roles: [], privileges:[]}); +var backupActions = ['find']; +db.createRole({role: 'backupFooChester', + privileges: [{resource: {db: 'foo', collection: 'chester'}, actions: backupActions}], + roles: []}); +db.createUser({user: 'backupFooChester', pwd: 'pass', roles: ['backupFooChester']}); + +var userCount = db.getUsers().length; +var rolesCount = db.getRoles().length; +var adminUsersCount = admindb.getUsers().length; +var adminRolesCount = admindb.getRoles().length; +var systemUsersCount = admindb.system.users.count(); +var systemVersionCount = admindb.system.version.count(); + +db.bar.insert({a:1}); + +assert.eq(1, db.bar.findOne().a); +assert.eq(userCount, db.getUsers().length, "setup"); +assert.eq(rolesCount, db.getRoles().length, "setup2"); +assert.eq(adminUsersCount, admindb.getUsers().length, "setup3"); +assert.eq(adminRolesCount, admindb.getRoles().length, "setup4"); +assert.eq(systemUsersCount, admindb.system.users.count(), "setup5"); +assert.eq(systemVersionCount, admindb.system.version.count(),"system version"); +assert.eq(1, admindb.system.users.count({user: "restore"}), "Restore user is missing"); +assert.eq(1, admindb.system.users.count({user: "backup"}), "Backup user is missing"); +var versionDoc = admindb.system.version.findOne(); + +jsTestLog("Dump foo database without dumping user data"); +var dumpDir = MongoRunner.getAndPrepareDumpDirectory("dumprestore_auth3"); +runTool("mongodump", mongod, {out: dumpDir, db: "foo"}); +db = mongod.getDB('foo'); + +db.dropDatabase(); +db.dropAllUsers(); +db.dropAllRoles(); + +jsTestLog("Restore foo database from dump that doesn't contain user data "); +runTool("mongorestore", mongod, {dir: dumpDir + "foo/", db: 'foo', restoreDbUsersAndRoles: ""}); + +db = mongod.getDB('foo'); + +assert.soon(function() { return db.bar.findOne(); }, "no data after restore"); +assert.eq(1, db.bar.findOne().a); +assert.eq(0, db.getUsers().length, "Restore created users somehow"); +assert.eq(0, db.getRoles().length, "Restore created roles somehow"); + +// Re-create user data +db.createUser({user: 'user', pwd: 'password', roles: jsTest.basicUserRoles}); +db.createRole({role: 'role', roles: [], privileges:[]}); +userCount = 1; +rolesCount = 1; + +assert.eq(1, db.bar.findOne().a); +assert.eq(userCount, db.getUsers().length, "didn't create user"); +assert.eq(rolesCount, db.getRoles().length, "didn't create role"); + +jsTestLog("Dump foo database *with* user data"); +runTool("mongodump", mongod, {out: dumpDir, db: "foo", dumpDbUsersAndRoles: ""}); +db = mongod.getDB('foo'); + +db.dropDatabase(); +db.dropAllUsers(); +db.dropAllRoles(); + +assert.eq(0, db.getUsers().length, "didn't drop users"); +assert.eq(0, db.getRoles().length, "didn't drop roles"); +assert.eq(0, db.bar.count(), "didn't drop 'bar' collection"); + +jsTestLog("Restore foo database without restoring user data, even though it's in the dump"); +runTool("mongorestore", mongod, {dir: dumpDir + "foo/", db: 'foo'}); +db = mongod.getDB('foo'); + +assert.soon(function() { return db.bar.findOne(); }, "no data after restore"); +assert.eq(1, db.bar.findOne().a); +assert.eq(0, db.getUsers().length, "Restored users even though it shouldn't have"); +assert.eq(0, db.getRoles().length, "Restored roles even though it shouldn't have"); + +jsTestLog("Restore foo database *with* user data"); +runTool("mongorestore", mongod, {dir: dumpDir + "foo/", db: 'foo', restoreDbUsersAndRoles: ""}); +db = mongod.getDB('foo'); +admindb = mongod.getDB('admin'); + +assert.soon(function() { return db.bar.findOne(); }, "no data after restore"); +assert.eq(1, db.bar.findOne().a); +assert.eq(userCount, db.getUsers().length, "didn't restore users"); +assert.eq(rolesCount, db.getRoles().length, "didn't restore roles"); +assert.eq(1, admindb.system.users.count({user: "restore", db: "admin"}), "Restore user is missing"); +assert.docEq(versionDoc, + db.getSiblingDB('admin').system.version.findOne(), + "version doc was changed by restore"); + +jsTestLog("Make modifications to user data that should be overridden by the restore"); +db.dropUser('user') +db.createUser({user: 'user2', pwd: 'password2', roles: jsTest.basicUserRoles}); +db.dropRole('role') +db.createRole({role: 'role2', roles: [], privileges:[]}); + +jsTestLog("Restore foo database (and user data) with --drop so it overrides the changes made"); +// Restore with --drop to override the changes to user data +runTool("mongorestore", mongod, + {dir: dumpDir + "foo/", db: 'foo', drop: "", restoreDbUsersAndRoles: ""}); +db = mongod.getDB('foo'); +admindb = mongod.getDB('admin'); + +assert.soon(function() { return db.bar.findOne(); }, "no data after restore"); +assert.eq(adminUsersCount, admindb.getUsers().length, "Admin users were dropped"); +assert.eq(adminRolesCount, admindb.getRoles().length, "Admin roles were dropped"); +assert.eq(1, db.bar.findOne().a); +assert.eq(userCount, db.getUsers().length, "didn't restore users"); +assert.eq("user", db.getUser('user').user, "didn't update user"); +assert.eq(rolesCount, db.getRoles().length, "didn't restore roles"); +assert.eq("role", db.getRole('role').role, "didn't update role"); +assert.docEq(versionDoc, + db.getSiblingDB('admin').system.version.findOne(), + "version doc was changed by restore"); + + +jsTestLog("Dump just the admin database. User data should be dumped by default"); +// Make a user in another database to make sure it is properly captured +db.getSiblingDB('bar').createUser({user: "user", pwd: 'pwd', roles: []}); +db.getSiblingDB('admin').createUser({user: "user", pwd: 'pwd', roles: []}); +adminUsersCount += 1; +runTool("mongodump", mongod, {out: dumpDir, db: "admin"}); +db = mongod.getDB('foo'); + +// Change user data a bit. +db.dropAllUsers(); +db.getSiblingDB('bar').createUser({user: "user2", pwd: 'pwd', roles: []}); +db.getSiblingDB('admin').dropAllUsers(); + +jsTestLog("Restore just the admin database. User data should be restored by default"); +runTool("mongorestore", mongod, {dir: dumpDir + "admin/", db: 'admin', drop: ""}); +db = mongod.getDB('foo'); +var otherdb = db.getSiblingDB('bar'); +var admindb = db.getSiblingDB('admin'); + +assert.soon(function() { return db.bar.findOne(); }, "no data after restore"); +assert.eq(1, db.bar.findOne().a); +assert.eq(userCount, db.getUsers().length, "didn't restore users"); +assert.eq("user", db.getUser('user').user, "didn't restore user"); +assert.eq(rolesCount, db.getRoles().length, "didn't restore roles"); +assert.eq("role", db.getRole('role').role, "didn't restore role"); +assert.eq(1, otherdb.getUsers().length, "didn't restore users for bar database"); +assert.eq("user", otherdb.getUsers()[0].user, "didn't restore user for bar database"); +assert.eq(adminUsersCount, admindb.getUsers().length, "didn't restore users for admin database"); +assert.eq("user", admindb.getUser("user").user, "didn't restore user for admin database"); +assert.eq(6, admindb.system.users.count(), "has the wrong # of users for the whole server"); +assert.eq(2, admindb.system.roles.count(), "has the wrong # of roles for the whole server"); +assert.docEq(versionDoc, + db.getSiblingDB('admin').system.version.findOne(), + "version doc was changed by restore"); + +jsTestLog("Dump all databases"); +runTool("mongodump", mongod, {out: dumpDir}); +db = mongod.getDB('foo'); + +db.dropDatabase(); +db.dropAllUsers(); +db.dropAllRoles(); + +assert.eq(0, db.getUsers().length, "didn't drop users"); +assert.eq(0, db.getRoles().length, "didn't drop roles"); +assert.eq(0, db.bar.count(), "didn't drop 'bar' collection"); + +jsTestLog("Restore all databases"); +runTool("mongorestore", mongod, {dir: dumpDir}); +db = mongod.getDB('foo'); + +assert.soon(function() { return db.bar.findOne(); }, "no data after restore"); +assert.eq(1, db.bar.findOne().a); +assert.eq(1, db.getUsers().length, "didn't restore users"); +assert.eq(1, db.getRoles().length, "didn't restore roles"); +assert.docEq(versionDoc, + db.getSiblingDB('admin').system.version.findOne(), + "version doc was changed by restore"); + +MongoRunner.stopMongod(mongod); diff --git a/jstests/tool/dumprestore_repair.js b/jstests/tool/dumprestore_repair.js deleted file mode 100644 index bf636b9361c..00000000000 --- a/jstests/tool/dumprestore_repair.js +++ /dev/null @@ -1,47 +0,0 @@ -/* dumprestore_repair.js - * create collection that spans more than one extent. - * mongodump using both --repair and normal - * restore both dumps and assert they're equal - * assert that the --repair dump is 2 times the size of the non --repair dump - */ -t = new ToolTest( "dumprestore_repair" ); -c = t.startDB( "foo" ); -dbName = t.db; -assert.eq( 0 , c.count() , "foo" ); -for (i=0; i<100; i++) { c.save( { x : i } ); } -assert.eq( 100 , c.count() , "foo" ); -t.stop(); - -// normal -normalDumpPath = t.ext + 'normal' -t.runTool( "dump", "--dbpath", t.dbpath, "-d", t.baseName, "-c", "foo", "--out", normalDumpPath ); - -// with repair -repairDumpPath = t.ext + 'repair' -t.runTool( "dump", "--repair", "--dbpath", t.dbpath, "-d", t.baseName, "-c", "foo", "--out", repairDumpPath ); - -c = t.startDB( "foo" ); - -function restore(path, toolTest, coll) { - coll.drop(); - assert.eq( 0 , coll.count() , "after drop" ); - toolTest.runTool( "restore" , "--dir" , path ); - assert.soon( "c.findOne()" , "no data after sleep" ); - assert.eq( 100 , c.count() , "after restore" ); -} - -restore(normalDumpPath, t, c); -restore(repairDumpPath, t, c); - -// get the dumped bson files -normalFiles = listFiles( normalDumpPath + '/' + t.baseName ) - -// filter out the metadata.json file -normalFiles = normalFiles.filter( function(x) { if ( x.name.match( /bson$/ ) ) return x; } ) -assert.eq( normalFiles[0].baseName, "foo.bson", "unexpected file name") -repairFiles = listFiles( repairDumpPath + '/' + t.baseName ) -assert.eq( repairFiles[0].baseName, "foo.bson", "unexpected file name") - -// the --repair bson file should be exactly twice the size of the normal dump file -assert.eq( normalFiles[0].size * 2, repairFiles[0].size ); -t.stop(); diff --git a/jstests/tool/exportimport2.js b/jstests/tool/exportimport2.js deleted file mode 100644 index fbcf2399d8c..00000000000 --- a/jstests/tool/exportimport2.js +++ /dev/null @@ -1,24 +0,0 @@ -// exportimport2.js - -t = new ToolTest( "exportimport2" ); - -c = t.startDB( "foo" ); -assert.eq( 0 , c.count() , "setup1" ); -c.save( { a : 22 } ); -assert.eq( 1 , c.count() , "setup2" ); -t.stop(); - -t.runTool( "export" , "--dbpath" , t.dbpath , "--out" , t.extFile , "-d" , t.baseName , "-c" , "foo" ); - -resetDbpath( t.dbpath ); -assert.eq( 0 , listFiles( t.dbpath ).length , "clear" ); - -t.runTool( "import" , "--dbpath" , t.dbpath , "--file" , t.extFile , "-d" , t.baseName , "-c" , "foo" ); - -c = t.startDB( "foo" ); -assert.soon( "c.findOne()" , "no data after startup" ); -assert.eq( 1 , c.count() , "after restore 2" ); -assert.eq( 22 , c.findOne().a , "after restore 2" ); - -t.stop(); - diff --git a/jstests/tool/shim1.js b/jstests/tool/shim1.js deleted file mode 100644 index 44f2aa33bc2..00000000000 --- a/jstests/tool/shim1.js +++ /dev/null @@ -1,240 +0,0 @@ -// Mongoshim is a tool to read/write the stored format directly. -// Intended to be used by other mongo tools that support the --dbpath option -// to access the data directory in the absence of a running mongod server. -// -// Mongoshim runs in a few modes: -// -// --mode=find: -// Reads contents of a collection and writes the documents in BSON format to stdout. -// Documents may be filtered using the --query option. -// Another mongo tool "bsondump" may be used to convert the written BSON to a human-readable -// format. -// -// --mode=insert: -// Reads BSON documents from stdin and inserts them in a collection. -// Input documents may be filtered using the --filter option. -// -// --mode=upsert: -// A variation of "insert" where existing documents will be updated with -// the BSON data read from stdin. The existing documents are identified -// by matching the _id field or fields specified in --upsertFields. -// -// --mode=remove: -// Removes documents from an existing collection matching the predicate in --filter. -// If --filter is not specified, all documents will be removed from the collection. -// -// --mode=repair: -// Reads record store for collection. Outputs valid documents. -// -// --mode=command: -// Invokes db.runCommand() using command objects read from input. - -var baseName = 'jstests_tool_shim1'; -var dbPath = MongoRunner.dataPath + baseName + '/'; -var externalPath = MongoRunner.dataPath + baseName + '_external/'; -var externalBaseName = 'shim1.bson'; -var externalFile = externalPath + externalBaseName; -var externalOperationsBaseName = 'shim1_operations.bson'; -var externalOperationsFile = externalPath + externalOperationsBaseName; - -var dbName = 'test'; -var collectionName = 'shim1'; -var operationsCollectionName = 'shim1operations'; - -var port = allocatePorts(1)[0]; - -resetDbpath(dbPath); -resetDbpath(externalPath); - -// Queries filesystem for size of 'externalFile' in bytes. -// Returns -1 if file is not found. -function fileSize(baseName){ - var files = listFiles(externalPath); - for (var i=0; i<files.length; i++) { - if (files[i].baseName == baseName) - return files[i].size; - } - assert(false, 'BSON file not found: ' + externalFile); -} - -// Starts mongod server without wiping out data directory -function startServer() { - return startMongoProgram('mongod', '--port', port, '--dbpath', dbPath, - '--nohttpinterface', '--noprealloc', '--bind_ip', '127.0.0.1'); -} - -// Stops mongod server. -function stopServer() { - stopMongod(port); -} - -// -// Invalid command line option and mode combinations -// - -// Missing --mode option. -assert.neq(0, runMongoProgram('mongoshim', '--dbpath', dbPath, - '--db', dbName, - '--collection', collectionName), - 'expected non-zero error code when required --mode option is omitted'); - -// Missing --dbpath option. -assert.neq(0, runMongoProgram('mongoshim', - '--db', dbName, - '--collection', collectionName, - '--mode', 'find'), - 'expected non-zero error code when required --dbpath option is omitted'); - -// Missing --collection option when mode is not "command". -assert.neq(0, runMongoProgram('mongoshim', '--dbpath', dbPath, - '--db', dbName, - '--mode', 'find'), - 'expected non-zero error code when required --collection option is omitted'); - -// --collection and --mode=command are incompatible. -assert.neq(0, runMongoProgram('mongoshim', '--dbpath', dbPath, - '--db', dbName, '--collection', collectionName, - '--mode', 'command'), - 'expected non-zero error code when incompatible options --collection and ' + - '--mode=command are used'); - -// --drop cannot be used with non-insert mode. -assert.neq(0, runMongoProgram('mongoshim', '--dbpath', dbPath, - '--db', dbName, - '--mode', 'command', - '--drop'), - 'expected non-zero error code when incompatible options --drop and ' + - '--mode=command are used'); - -// --upsertFields cannot be used with non-upsert mode. -assert.neq(0, runMongoProgram('mongoshim', '--dbpath', dbPath, - '--db', dbName, '--collection', collectionName, - '--mode', 'insert', - '--upsertFields', 'a,b,c'), - 'expected non-zero error code when incompatible options --upsertFields and ' + - '--mode=insert are used'); - -// -// Basic tests for each mode. -// - -// Initialize collection. -var mongod = startServer(); -var collection = mongod.getDB(dbName).getCollection(collectionName); -collection.save({a: 1}); -var doc = collection.findOne(); -stopServer(); - -// "find" mode - read collection with single document and write results to file. -// XXX: Do not check tool exit code. See SERVER-5520 -runMongoProgram('mongoshim', '--dbpath', dbPath, - '--db', dbName, '--collection', collectionName, - '--mode', 'find', - '--out', externalFile); -assert.eq(Object.bsonsize(doc), fileSize(externalBaseName), - 'output BSON file size does not match size of document returned from find()'); - -// "insert" mode - insert document from file into collection. -resetDbpath(dbPath); -runMongoProgram('mongoshim', '--dbpath', dbPath, - '--db', dbName, '--collection', collectionName, - '--mode', 'insert', - '--in', externalFile); -mongod = startServer(); -collection = mongod.getDB(dbName).getCollection(collectionName); -assert.eq(1, collection.count(), 'test document was not added to collection'); -var newDoc = collection.findOne(); -assert.eq(doc, newDoc, 'invalid document saved by mongoshim --mode=insert') -stopServer(); -// drop collection before inserting new document. -resetDbpath(dbPath); -runMongoProgram('mongoshim', '--dbpath', dbPath, - '--db', dbName, '--collection', collectionName, - '--mode', 'insert', - '--drop', - '--inputDocuments', tojson({in: [{a: 1, c: 1}]})); -mongod = startServer(); -collection = mongod.getDB(dbName).getCollection(collectionName); -assert.eq(1, collection.count(), 'collection was not dropped before insertion'); -var newDoc = collection.findOne(); -assert.eq(1, newDoc.c, 'invalid document saved by mongoshim --mode=insert') -stopServer(); - -// "upsert" mode - upsert document from file into collection. -// Since document already exists in collection, this upsert operation will -// have no effect. -runMongoProgram('mongoshim', '--dbpath', dbPath, - '--db', dbName, '--collection', collectionName, - '--mode', 'upsert', - '--upsertFields', 'a', - '--inputDocuments', tojson({in: [{a: 1, b: 1}]})); -mongod = startServer(); -collection = mongod.getDB(dbName).getCollection(collectionName); -assert.eq(1, collection.count(), 'test document was not added to collection'); -var newDoc = collection.findOne({}, {_id: 0, a: 1, b: 1}); -assert.eq({a: 1, b: 1}, newDoc, 'invalid document saved by mongoshim --mode=upsert') -stopServer(); - -// "remove" mode - remove documents from collection. -resetDbpath(dbPath); -runMongoProgram('mongoshim', '--dbpath', dbPath, - '--db', dbName, '--collection', collectionName, - '--mode', 'remove'); -mongod = startServer(); -collection = mongod.getDB(dbName).getCollection(collectionName); -assert.eq(0, collection.count(), 'test document was not removed from collection'); -stopServer(); - -// "applyOps" mode - apply oplog entries to collection. -// Simulated using "command" mode. -// If operation was applied successfully, we should see a document in -// 'collectionName' collection (not 'operationsCollectionName'). -var collectionFullName = dbName + '.' + collectionName; -runMongoProgram('mongoshim', '--dbpath', dbPath, - '--db', dbName, - '--mode', 'command', - '--inputDocuments', - tojson({in: [{applyOps: [ - {op: 'i', ns: collectionFullName, o: {_id: 1, a: 1}}]}]})); -mongod = startServer(); -collection = mongod.getDB(dbName).getCollection(collectionName); -assert.eq({_id: 1, a: 1 }, collection.findOne(), - 'mongoshim failed to apply operaton to ' + collectionName); -stopServer(); - -// "command" mode - invoke db.runCommand with command object read from input. -// Command result written to output. -// First "command" test case uses the "ping" command and saves the command -// result into the test collection for verification. -// Collection parameter is ignored in "command" mode. -runMongoProgram('mongoshim', '--dbpath', dbPath, - '--db', dbName, - '--mode', 'command', - '--inputDocuments', tojson({in: [{ping: 1}]}), - '--out', externalFile); -runMongoProgram('mongoshim', '--dbpath', dbPath, - '--db', dbName, '--collection', collectionName, - '--mode', 'insert', - '--drop', - '--in', externalFile); -mongod = startServer(); -collection = mongod.getDB(dbName).getCollection(collectionName); -assert.commandWorked(collection.findOne(), - 'mongoshim failed to run "ping" command'); -stopServer(); -// Second "command" test case runs a non-existent command. -runMongoProgram('mongoshim', '--dbpath', dbPath, - '--db', dbName, - '--mode', 'command', - '--inputDocuments', tojson({in: [{noSuchCommand: 1}]}), - '--out', externalFile); -runMongoProgram('mongoshim', '--dbpath', dbPath, - '--db', dbName, '--collection', collectionName, - '--mode', 'insert', - '--drop', - '--in', externalFile); -mongod = startServer(); -collection = mongod.getDB(dbName).getCollection(collectionName); -assert.commandFailed(collection.findOne(), - 'mongoshim should get a failed status from running "noSuchCommand" command'); -stopServer(); diff --git a/jstests/tool/tool1.js b/jstests/tool/tool1.js index 8c463c8e1df..5bd191faa49 100644 --- a/jstests/tool/tool1.js +++ b/jstests/tool/tool1.js @@ -41,25 +41,3 @@ c.drop(); runMongoProgram( "mongoimport", "--host", "127.0.0.1:" + port, "-d", baseName, "-c", baseName, "--file", externalFile ); assert.soon( "c.findOne()" , "mongo import json A" ); assert( c.findOne() && 1 == c.findOne().a , "mongo import json B" ); - -stopMongod( port ); -resetDbpath( externalPath ); - -runMongoProgram( "mongodump", "--dbpath", dbPath, "--out", externalPath ); -resetDbpath( dbPath ); -runMongoProgram( "mongorestore", "--dbpath", dbPath, "--dir", externalPath ); -m = startMongoProgram( "mongod", "--port", port, "--dbpath", dbPath, "--nohttpinterface", "--bind_ip", "127.0.0.1" ); -c = m.getDB( baseName ).getCollection( baseName ); -assert.soon( "c.findOne()" , "object missing a" ); -assert( 1 == c.findOne().a, "object wrong" ); - -stopMongod( port ); -resetDbpath( externalPath ); - -runMongoProgram( "mongoexport", "--dbpath", dbPath, "-d", baseName, "-c", baseName, "--out", externalFile ); -resetDbpath( dbPath ); -runMongoProgram( "mongoimport", "--dbpath", dbPath, "-d", baseName, "-c", baseName, "--file", externalFile ); -m = startMongoProgram( "mongod", "--port", port, "--dbpath", dbPath, "--nohttpinterface", "--bind_ip", "127.0.0.1" ); -c = m.getDB( baseName ).getCollection( baseName ); -assert.soon( "c.findOne()" , "object missing b" ); -assert( 1 == c.findOne().a, "object wrong" ); diff --git a/jstests/tool/tool_replset.js b/jstests/tool/tool_replset.js index 5c219c79a27..b38dcb95806 100644 --- a/jstests/tool/tool_replset.js +++ b/jstests/tool/tool_replset.js @@ -82,19 +82,6 @@ print("running mongooplog to replay the oplog") assert.eq(101, master.getDB("foo").getCollection("bar").count(), "count after running mongooplog " + "was not 101 as expected") -// Dump local oplog with --dbpath option (SERVER-14249) -replTest.stop(0); -var dataDir = MongoRunner.dataDir + "/tool_replset-0/"; -data = MongoRunner.dataDir + "/tool_replset-dump-dbpath/"; -print("dump oplog with --dbpath"); -clearRawMongoProgramOutput(); -runMongoProgram("mongodump", "--dbpath", dataDir, "--out", data + "oplog", "-d", "local"); -assert.isnull(rawMongoProgramOutput().match(/assert/)); -// mongodump with --dbpath -d local & -c oplog.rs -runMongoProgram("mongodump", "--dbpath", dataDir, "--out", data + "oplog", "-d", "local", - "-c", "oplog.rs"); -assert.isnull(rawMongoProgramOutput().match(/assert/)); - print("all tests successful, stopping replica set") replTest.stopSet(); |