Created
June 30, 2015 14:54
-
-
Save kiantabrizi/9dc1dc5cfb1e655a1841 to your computer and use it in GitHub Desktop.
MongoDB Cloud Manager Backup: calculating how much you will be charged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dbNames = []; | |
var sum = 0; | |
var dblist = db.getMongo().getDBs(); | |
for (var key in dblist) { | |
if(key === "databases") { | |
for (var i = 0; i < dblist.databases.length; i++){ | |
if (dblist.databases[i].name !== "local") { | |
dbNames.push(dblist.databases[i].name); | |
} | |
} | |
} | |
} | |
function formatSizeUnits(bytes){ | |
if (bytes>=1000000000) {bytes=(bytes/1000000000).toFixed(2)+' GB';} | |
else if (bytes>=1000000) {bytes=(bytes/1000000).toFixed(2)+' MB';} | |
else if (bytes>=1000) {bytes=(bytes/1000).toFixed(2)+' KB';} | |
else if (bytes>1) {bytes=bytes+' bytes';} | |
else {bytes='0 byte';} | |
return bytes; | |
} | |
for (var i = 0; i < dbNames.length; i++) { | |
var indexSize = db.getMongo().getDB(dbNames[i]).stats().indexSize; | |
var dataSize = db.getMongo().getDB(dbNames[i]).stats().dataSize; | |
var total = indexSize + dataSize; | |
sum += total; | |
print("db name: " + dbNames[i] + " | indexSize: " + formatSizeUnits(indexSize) + " | dataSize: " + formatSizeUnits(dataSize) + " | total: " + formatSizeUnits(total)); | |
} | |
print("total size of all dbs: " + formatSizeUnits(sum)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For every primary in the deployment (including every primary for every shard in a sharded cluster), sum the total dataSize and indexSize. Here’s a little script that does this.