#!/bin/bash

DBUSER="rafael"
DBPASS="restepa"
DBHOST="localhost"
DBNAME="redes"

FOLDER="/home/labredes/configuraciones/usuarios/"

BACKUPDIR="/backup/labredes"
NOW=`date +%Y-%m-%d`
FILENAME="labredes-"$NOW.tgz

STARTDIR=`pwd`

cd $BACKUPDIR
mkdir temp
cd $BACKUPDIR/temp

tar cf configuraciones.tar $FOLDER

mysqldump --user=$DBUSER --host=$DBHOST --password=$DBPASS --add-drop-table $DBNAME > redes_database.sql

tar czf $BACKUPDIR/$FILENAME configuraciones.tar redes_database.sql

rm -r $BACKUPDIR/temp

find $BACKUPDIR -mtime +140 -type f -name "labredes*" -exec rm '{}' \;

cd $STARTDIR
