#!/bin/sh
DATE=`/bin/date "+%Y%m%d-%H.%M.%S"`
dest_dir="/var/lib/mongo_backup"
/bin/mkdir -p $dest_dir/mongo.$DATE
mongodump $dump_flags -o $dest_dir/mongo.$DATE
cd $dest_dir/mongo.$DATE && for i in `ls`; do tar czvf $i.tar.gz $i; done
cd $dest_dir/mongo.$DATE && for i in `ls -l | grep -E '^d'`; do rm -rf $i; done
echo "mongo.$DATE.tgz moved to backup-server."
find ${dect_dir} -type f -mtime +21 -exec rm {} \;
exit