4
I have a running cron task that calls a shell script. This sh file backs up the database and saves it to a folder on the server. So far it’s working.
I know that at the time of generating the backup and/or saving can happen an error. I would like to send this error to an email or generate some error log, something like that. Does anyone know how to do this?
Follows the script:
#!/bin/bash
# bkpDBData.sh
#
# gera um dump da base de dados, somente dos dados para um zip no servidor
#
# echo 'Iniciando backup SGI!';
local_save_backup=/local/salvar/backups
ano=`date +%Y`
path_complete=$local_save_backup'/'$ano
# verifica se existe a pasta do local_save_backup+ano
# se nao existe, entao cria a pasta
if [ ! -d $path_complete ]; then
# echo "criar pasta";
mkdir $path_complete
# echo "pasta criada";
fi
mysqldump -h localhost -u user -psenha -x -e -t nome_da_base | gzip > $path_complete/`date +%Y%m%d_%H%M`_mysql.gz;
# echo 'Fim do backup SGI!';
Very good, something I did not know and I will study about. I already did the test and generated an error (in case I put a wrong password to generate). I had no idea whether it was in the cron or in the shell that I had to make that check, but now it has opened me more mind to it.
– Marcelo Diniz