#####################################################################
#!/bin/sh -x
PATH2DB=/var/lib/mysql
PATH2BACKUP=/mnt/backup/intranet
MY_USER='admin'
MY_PASSWD='MonMotDePasse'
DATE=`/bin/date -I`
echo $DATE
#Arret des services http pour la sauvegarde
/sbin/service httpd stop
#Montage du disque de sauvegarde
/bin/mount -t smbfs //serveur-data/users /mnt/backup -o username=admin,password=MonMotDePasse
#verifie si le ficier existe deja
if [ -f /mnt/backup/intranet/backup_$DATE.tar.gz ]
then
/bin/rm --force /mnt/backup/intranet/backup_$DATE.tar.gz
fi
#Cree l'archive du systeme
/bin/tar -czf /mnt/backup/intranet/backup_$DATE.tar.gz /home/e-smith/ /root/ /etc/e-smith/templates-custom/ /etc/e-smith/templates-user-custom/ /etc/samba/ /etc/ssh
#verifie si la base mysql existe
if [ -f /mnt/backup/intranet/backup-base-$DATE.sql ]
then
/bin/rm --force /mnt/backup/intranet/backup-base-$DATE.sql
fi
#Creation de la sauvegarde mysql
/usr/bin mysqldump -f --opt -u $MY_USER --password=$MY_PASSWD egroupware>$PATH2BACKUP/backup-base-$DATE.sql
#verification si le rapport existe deja
if [ -f /root/result ]
then
/bin/rm --force /root/result
fi
#verification si la sauvegarde a reussi et creation du rapport
if [ -f /mnt/backup/intranet/backup_$DATE.tar.gz -a -f /mnt/backup/intranet/backup-base-$DATE.sql ]
then
#si sauvegarde reussi...
echo "===== Rapport de sauvegarde =====" > /root/result
date >> /root/result
/bin/ls /mnt/backup/intranet/backup* >> /root/result
echo "La sauvegarde a bien reussie !" >> /root/result
else
#si sauvegarde echoue...
echo "===== Rapport de sauvegarde =====" > /root/result
/bin/date >> /root/result
/bin/ls /mnt/backup/intranet/backup* >> /root/result
echo "La sauvegarde a echouee" >> /root/result
fi
#Demontage du disque
/bin/umount /mnt/backup
#Lancement des services hddp et mysql
/sbin/service httpd start
#Envoi du resultat
/bin/mail -s Sauvegarde_$DATE admin
intranet@monentreprise.local < /root/result
#Fin
exit