billlcosta Posted August 13, 2017 Posted August 13, 2017 #!/bin/bash # =============================================================================================================# # Backup Databases MySQL # Version.: 1.0 # Modified.: 09/07/2016 # Modified by.: PH # Contact.: Phillipe Farias | phillipe@phillipefarias.com.br # #=============================================================================================================# mysql_user="root" export MYSQL_PWD="senha" if [ $# -ne 1 ]; then echo "Sintaxe: gera_backup_mysql <dir_destino>"; exit 1; fi DIRBAK="${1}"; mkdir -p "$DIRBAK" || exit 1; cd "$DIRBAK" || exit 1; MYSQL="/opt/lamp/bin/mysql"; if [ ! -x ${MYSQL} ]; then echo "mysql (${MYSQL}) nao encontrado."; exit 1; fi echo "show databases;" | mysql -h 127.0.0.1 -u $mysql_user -s | grep -vE "information_schema" | while read BANCO; do echo ${BANCO}; nice mysqldump -h 127.0.0.1 -u $mysql_user --routines ${BANCO} | gzip -9 > ${BANCO}_`date "+%Y%m%d_%H%M%S"`.sql.gz; if [ "$?" != "0" ]; then echo "Erro ao gerar o backup do banco ${BANCO}"; echo "ERROR: ${BANCO}" >> /var/log/aeamg_backup_mysql.errorlog exit 1; fi done
Recommended Posts
Archived
This topic is now archived and is closed to further replies.