pavel_ch

mongodb

Mar 12th, 2018 (edited)
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. for i in username password address;do kubectl -n octarine-cp get secrets docdb -o "jsonpath={.data.$i}" | base64 --decode | xargs echo " --$i "; done
  2.  
  3. echo "apiVersion: v1
  4. kind: Pod
  5. metadata:
  6. name: pavel-test-mongo
  7. spec:
  8. containers:
  9. - name: pavel-test-mongo
  10. image: mongo:6.0
  11. imagePullPolicy: Always
  12. command: ["/bin/sh", "-c"]
  13. args:
  14. - apt-get -y update && apt-get -y install wget;
  15. while true; do sleep 86400; done;" | kubectl apply -f -
  16.  
  17. ; wait 60;kubectl exec -it pavel-test-mongo -- bash
  18.  
  19.  
  20. rs.initiate( {
  21. _id : "rs0",
  22. members: [
  23. { _id: 0, host: "mongodb-skyler-cook-node-0:27017" },
  24. { _id: 1, host: "mongodb-skyler-cook-node-1:27017" }
  25. ]
  26. })
  27.  
  28. rs.add( { host: "mongodb3.example.net:27017", priority: 0, votes: 0 } )
  29.  
  30. db.createUser({user: "<username>", pwd: "<password>", roles: [{ role: "clusterMonitor", db: "admin"}, { role: "read", db: "local" }]})
  31. db.createUser({user: "<username>", pwd: "<password>", roles: [{ role: "readAnyDatabase", db: "admin"}]})
  32. db.createUser({user: "<username>", pwd: "<password>", roles: [{ role: "readWriteAnyDatabase", db: "admin"}]})
  33. db.createUser({ user: "<>", pwd: "<>", roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ] })
  34. db.createUser( { user: "<>", pwd: "<>", roles: [ { role: "readWrite", db: "app-db" } , { role: "readWrite", db: "app-fs" } ] } )
  35. db.createUser( { user: "<>", pwd: "<>", roles: [ "root" ] } )
  36.  
  37. db.updateUser("platform", {roles: [ { role: "readWrite", db: "app-db" } , { role: "readWrite", db: "app-fs" } ] })
  38.  
  39. kubectl exec -it mongodb-0 -- /bin/bash -c "mongodump --db app-staging-fs --archive | mongorestore -vvvvvv --host <> --port 27017 --username <> --password <> --authenticationDatabase admin --drop --archive --db app-fs"
  40.  
  41. for i in staging release; do kubectl -n $i exec -it mongodb-0 -- bash -c 'mongo --eval "Mongo().getDB(\"app-staging-db\").dropDatabase()"';done
  42.  
  43. mongodump --host mongodb.next.svc.cluster.local --db app-fs --archive | mongorestore --host localhost --drop --archive
  44. mongodump --uri mongodb://<USER>:<PASSWORD>@127.0.0.1 --oplog --gzip --archive=/data/db/mongo_skyler.`date +%F_%H-%M-%S`.gz
  45. mongodump --host 10.47.245.51 --port 27017 --oplog --gzip --archive=/usr/mongodb/db/mongo_skyler.`date +%F_%H-%M-%S`.gz
  46. mongodump --host 10.142.0.13 --port 27017 --out /usr/mongodb/db/test12
  47.  
  48. mongorestore -vvvvvv --host 10.44.0.87 --port 27017 -j 1 --drop /usr/mongodb/db/test12/
  49.  
  50. mongodump --db app-staging-fs --archive | mongorestore --host [] --port 27017 --username [] --password [] --authenticationDatabase admin --nsFrom app-staging-fs.* --nsTo app-fs.* --drop --archive
  51.  
  52. docker run -it --rm -v ~/data:/data mongo mongodump --ssl --sslAllowInvalidCertificates --host <> --port <> --authenticationDatabase admin --username <> --password <> --db currencies --collection currencies --gzip --archive=/data/currencies.currencies.`date +%F`.gz
  53.  
  54. db = db.getSiblingDB("admin");dbs = db.runCommand({ "listDatabases": 1 }).databases;dbs.forEach(function(database) {db = db.getSiblingDB(database.name);stats = db.stats();printjson(stats)});
  55.  
  56. db.getCollection('runningCommands').find({status:'failed'}).sort({_id:-1})
  57.  
  58. var db = db.getSiblingDB("admin");
  59. var dbs = db.runCommand({ "listDatabases": 1 }).databases;
  60. var sum = 0
  61. dbs.forEach(function(database) {
  62. db = db.getSiblingDB(database.name);
  63. var size = db.stats().indexSize
  64. print(size)
  65. sum += size
  66.  
  67. });
  68. print("#######")
  69. print(sum/(1000000000));
Add Comment
Please, Sign In to add comment