How to re-initialise MongoDB

In many cases such as disk full or mongodb database is completely damage and can not recover, we have to re-initialise it from scratch. You may simply follow these following steps.

1) service cfengine3 stop
2) backup the database files: # mv /var/cfengine/state/cfreport.* /var/cfengine/state/cfmonitor.* /var/cfengine/state/local.* /var/cfengine/state/phpcfengine.* /var/cfengine/state/cfknow.* <destination>
3) # rm /var/cfengine/state/mongod.lock
4) service cfengine3 start

The new database will be re-created with 1 week data in the next "full query". Then running the js scripts so you are able to login MP with "admin:admin"

# /var/cfengine/bin/mongo --quiet phpcfengine /var/cfengine/share/GUI/phpcfenginenova/export.js
# /var/cfengine/bin/mongo --quiet cfreport /var/cfengine/share/GUI/api/mongo-initialize.js
# /var/cfengine/bin/mongo --quiet phpcfengine /var/cfengine/share/GUI/phpcfenginenova/sql_reports.js

If you are running MongoDB replica set, you need to refresh secondary nodes too. Otherwise you will experience error "too stale to catch up".


Powered by Zendesk