A simple backupninja script for mongodb
After reading this stuff about corruption of mongodb http://ivoras.sharanet.org/blog/tree/2009-11-05.a-short-time-with-mongodb.html, I thought it was time to write a small script to backup our brand new mongodb databases at YeastyMobs
Here is the handler (in /usr/share/backupninja/mongodb):
getconf host localhost
getconf backupdir
getconf mongodump_path /opt/mongodb/bin/mongodump
info "Going to backup mongodb of $host in $backupdir"
if [ ! -f $mongodump_path ]; then
fatal "$mongodump_path does not exists"
fi
if [ ! -d $backupdir ]; then
fatal "$backupdir does not exists"
fi
if [ ! -w $backupdir ]; then
fatal "$backupdir is not writable by you"
fi
if [ ! $test ]; then
output=`$mongodump_path -h $host -o $backupdir`
code=$?
if [ "$code" == "0" ]; then
debug $output
info "Successfully finished dump of all mongodb databases"
else
warning $output
warning "Failed to dump all mongodb databases"
fi
else
debug "running $mongodump_path -h $host -o $backupdir"
fi
and the backup script (in /etc/backup.d/10-action.mongodb):
backupdir = /var/backups/mongodb
mongodump_path = /opt/mongodb/bin/mongodump