Skip to content

Instantly share code, notes, and snippets.

View dbmurphy's full-sized avatar

David Murphy dbmurphy

View GitHub Profile
@dbmurphy
dbmurphy / FreezeRepl-then-AddIndex.js
Created December 18, 2014 22:13
Adding index and freeze all members of a replSet
user='XXXX';
pass='XXXX';
indexPattern={ 'Key' : 1 };
indexOptions={};
db.getSiblingDB('config').shards.find({},{host:1,_id:0}).forEach(function(shard){
tHosts = shard.host.split('/')[1].split(',')
tHosts.forEach(function(host){
print("Freezing "+ host);
x= new Mongo(host);
x.getDB('admin').auth(user,pass);
@dbmurphy
dbmurphy / MongoToCF.sh
Last active August 29, 2015 14:11
ClouldFiles Uploading of a backup....
CloudFilesUser="XXXX"
CloudFilesKey="XXXXXX"
mongoshost="XXXXXX"
mongosport=99999
mongouser="XXXXXX"
mongopass="XXXXX"
#Path to you mongo binaries
mongobinpath=~/mongodb-linux-x86_64-2.4.6/bin
db=$(echo `date +"stats_%d%m%Y"`)
@dbmurphy
dbmurphy / gist:f5b9ad881c5899cf1902
Created October 11, 2014 01:40
ChangeLog Example Queries
//Get last 10 actions
db.getSiblingDB('config').changelog.find().sort({time:-1}).limit(10)
//Get Last 10 attempted moves
db.getSiblingDB('config').changelog.find({what:/moveChunk.start/}).sort({time:-1}).limit(10)
//Get Last 10 completed moves
db.getSiblingDB('config').changelog.find({what:/moveChunk.commit/}).sort({time:-1}).limit(10)
//Get Chunk Actions by hour/day (What can be moveChunk.start, moveChunk.commit, moveChunk.from, split
@dbmurphy
dbmurphy / gist:991617195f10cda61ffe
Created October 10, 2014 22:21
ChunkHunter example commands
//All Jumbo Chunks
db.foo.find({jumbo:true});
//Order By documents
db.foo.find({jumbo:true}).sort({docs:-1});
//Order By size
db.foo.find({jumbo:true}).sort({size:-1});
//Aggregate looking for jumbos by shard ( Set size and docs lower from 64/250k due to test size)
@dbmurphy
dbmurphy / gist:f2619088bd853f3f883e
Last active August 29, 2015 14:07
Move Chunk (assumes) 2.4+
function MoveChunk(chunk,count){
good_shards=["shard4","shard5","shard6","shard7"];
printjson(chunk);
moveObject= { moveChunk : chunk.ns, find: chunk.min , to : good_shards[count % good_shards.length], __waitForDelete:false,__secondaryThrottle:true}
printjson(moveObject);
printjson("++++++++++++++++++++++");
printjson(db.adminCommand(moveObject));
printjson("++++++++++++++++++++++");
}
@dbmurphy
dbmurphy / gist:3c1f9d3e608fab9f4de3
Created October 10, 2014 18:21
Chunk Collection Aggregations
mongos> chunksPerShard_Aggregation
{ "$group" : { "_id" : "$shard", "count" : { "$sum" : 1 } } }
mongos> chunksPerShardByNS_Aggregation
{
"$group" : {
"_id" : {
"shard" : "$shard",
"ns" : "$ns"
},
"count" : {