#!/bin/bash

MONGODB_HOST=""
MONGODB_PORT="30002"
DATABASE="local"
BACKUP_PATH=/opt
SAVE_DAYS=15

BACKUP_DIR=${BACKUP_PATH}/mongodb/$(date +%Y%m%d%H%M%S)

mkdir -p ${BACKUP_DIR}

/usr/bin/mongodump -h ${MONGODB_HOST}:${MONGODB_PORT} -d ${DATABASE} -o ${BACKUP_DIR}

if [ "$?" == 0 ];then
    echo "$(date '+%Y-%m-%d %H:%M:%S') mongodb backup success." >> /tmp/edoc2_backup.log
else
    echo "$(date '+%Y-%m-%d %H:%M:%S') mongodb backup faile." >> /tmp/edoc2_backup.log
fi


#delete backufile some time ago
find ${BACKUP_DIR} -mtime +${SAVE_DAYS} -exec rm -rf {} \;

