Skip to content

Instantly share code, notes, and snippets.

@darkk
Last active December 15, 2015 22:18
Show Gist options
  • Save darkk/5331671 to your computer and use it in GitHub Desktop.
Save darkk/5331671 to your computer and use it in GitHub Desktop.
#!/bin/sh
exec 2>/dev/null 1>/dev/null
export PATH=$PATH:%%PREFIX%%/bin
logdir=/var/db/mongodb
suffix=.bz2
prefix=mongod.log.
selflog=${prefix}rotate.`date +%Y-%m-%d`
days_to_keep=14
exec 2>>"${logdir}/${selflog}" 1>>"${logdir}/${selflog}"
echo "`date` $0[$$]: start"
mongo --host localhost --eval 'db.runCommand("logRotate")' admin
find "$logdir/" -type f -name "${prefix}*" -mtime "+${days_to_keep}" -delete
find "$logdir/" -type f -name "${prefix}*" '!' -name "$selflog" '!' -name "${prefix}*${suffix}" -exec bzip2 '{}' ';'
echo "`date` $0[$$]: Done: ${state}."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment