Skip to content

Instantly share code, notes, and snippets.

@deyvisonrocha
Created May 19, 2016 12:53
Show Gist options
  • Save deyvisonrocha/6fb4a47ff79f42ad325fb462f8449646 to your computer and use it in GitHub Desktop.
Save deyvisonrocha/6fb4a47ff79f42ad325fb462f8449646 to your computer and use it in GitHub Desktop.
MySQL - Script de Backup
#!/bin/bash
#################### SCRIPT PARA BACKUP MYSQL ####################
# Jeferson R. Costa <[email protected]> #
# Created Feb, 2013 #
# Update Feb, 2013 #
# Definindo parametros do MySQL
echo " -- Definindo parametros do MySQL ..."
DB_NAME='dbname'
DB_USER='dbuser'
DB_PASS='dbpass'
DB_PARAM='--add-drop-table --add-locks --extended-insert --single-transaction -quick'
# Definindo parametros do sistema
echo " -- Definindo parametros do sistema ..."
DATE=`date +%Y-%m-%d`
MYSQLDUMP=/usr/bin/mysqldump
BACKUP_DIR=/backup/mysql
BACKUP_NAME=mysql-$DATE.sql
BACKUP_TAR=mysql-$DATE.tar
#Gerando arquivo sql
echo " -- Gerando Backup da base de dados $DB_NAME em $BACKUP_DIR/$BACKUP_NAME ..."
$MYSQLDUMP $DB_NAME $DB_PARAM -u $DB_USER -p$DB_PASS > $BACKUP_DIR/$BACKUP_NAME
# Compactando arquivo em tar
echo " -- Compactando arquivo em tar ..."
tar -cf $BACKUP_DIR/$BACKUP_TAR -C $BACKUP_DIR $BACKUP_NAME
# Compactando arquivo em bzip2
echo " -- Compactando arquivo em bzip2 ..."
bzip2 $BACKUP_DIR/$BACKUP_TAR
# Excluindo arquivos desnecessarios
echo " -- Excluindo arquivos desnecessarios ..."
rm -rf $BACKUP_DIR/$BACKUP_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment