Skip to content

Instantly share code, notes, and snippets.

@sydcanem
Last active December 20, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sydcanem/6194370 to your computer and use it in GitHub Desktop.
Save sydcanem/6194370 to your computer and use it in GitHub Desktop.
Mongo db repair
#!/bin/bash
LOCK_FILE=/var/lib/mongodb/mongo.lock
PID_FILE=/var/run/mongo.pid
DAEMON=/usr/local/bin/mongod
DBPATH=/var/lib/mongodb
mongo_running=0
if [ -f $PID_FILE ]; then
pid=`cat $PID_FILE`
ps auxww | egrep "root +$pid" > /dev/null
if [ $? == 0 ]; then
mongo_running=1
fi
fi
if [ $mongo_running == 1 ]; then
echo "Mongo already running pid:$pid"
exit 0
fi
echo "Mongo is not running. Starting to repair."
if [ -f $LOCK_FILE ]; then
echo -n "Removing lock_file:$LOCK_FILE..."
rm $LOCK_FILE
echo "done."
fi
echo "Repairing mongo db at $DBPATH..."
$DAEMON --dbpath $DBPATH --repair
echo "done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment