# Back Up Mysql Database phproject By oTTo
#!/bin/bash

#MONGODB:
# NOWMONGOFILE="SERVERENG_MONGODB_$(date +"%d-%m-%Y-%H-%M")"

NOWMONGOFILE="SERVERENG_MONGODB_H_$(date +"%H")"

NOWMONGOFILE_MONTH="SERVERENG_MONGODB_MONTH_$(date +"%m")"

NOWMONGOFILE_WEEK="SERVERENG_MONGODB_WEEK_$(date +"%u")"

NOWMONGOFILE_SERVER="SERVERENG_MONGODB_SERVER_H_$(date +"%H")"


FILEMONGODB=/root/backups/$NOWMONGOFILE

echo "Dump del DB..."
mongodump --db FreePlanet --out $FILEMONGODB
sleep 1
echo "Targz del DB..."
cd /root/backups/
echo "sudo tar cvfz $NOWMONGOFILE.tar.gz $NOWMONGOFILE/"

sudo tar cvfz $NOWMONGOFILE.tar.gz $NOWMONGOFILE/ 

sleep 1

rm $NOWMONGOFILE.tar.gz.nc

sleep 1

mcrypt -f /root/batch/cfgfiles/mycfg.ini $NOWMONGOFILE.tar.gz

sleep 1

rm -R $NOWMONGOFILE/
rm $NOWMONGOFILE.tar.gz

echo "File" $NOWMONGOFILE.tar.gz.mc

cp -R $NOWMONGOFILE.tar.gz.nc /root/backups/$NOWMONGOFILE_MONTH.tar.gz.nc

sleep 1
cp -R $NOWMONGOFILE.tar.gz.nc /root/backups/$NOWMONGOFILE_WEEK.tar.gz.nc

sleep 1
cp -R $NOWMONGOFILE.tar.gz.nc /root/backups/$NOWMONGOFILE_SERVER.tar.gz.nc

cp -R $NOWMONGOFILE.tar.gz.nc /home/paolo/backups/$NOWMONGOFILE.tar.gz.nc

chown paolo:paolo /home/paolo/backups/$NOWMONGOFILE.tar.gz.nc

echo "Fine"

