Configurer les sauvegardes de MYSQL

On va voir comment avec un simple petit utilitaire Linux, on peut automatiser les backups de MYSQL ainsi qu’un envoi par mail de son état

il s’agit de automysqlbackup

on l’installe via :

apt-get install automysqlbackup
Lecture des listes de paquets... Fait
Construction de l'arbre des dépendances       
Lecture des informations d'état... Fait
Les paquets supplémentaires suivants seront installés : 
  exim4-base exim4-config exim4-daemon-light libgpgme11 libpth20 libtokyocabinet9 mutt
Paquets suggérés :
  eximon4 exim4-doc-html exim4-doc-info spf-tools-perl swaks gpgsm gnupg2 urlview mixmaster
Paquets recommandés :
  default-mta mail-transport-agent
Les NOUVEAUX paquets suivants seront installés :
  automysqlbackup exim4-base exim4-config exim4-daemon-light libgpgme11 libpth20 libtokyocabinet9 mutt
0 mis à jour, 8 nouvellement installés, 0 à enlever et 0 non mis à jour.
Il est nécessaire de prendre 4 143 ko dans les archives.
Après cette opération, 11,0 Mo d'espace disque supplémentaires seront utilisés.
Souhaitez-vous continuer [O/n] ? 

les dépendances seront corrigés automatiquement via apt-get

pour ce qui est de la configuration, rie nde plus simple, tout est dans le fichier de configuration situé ici


le fichier est lancé dans le cron tout les jour

son contenu

# By default, the Debian version of automysqlbackup will use:
# mysqldump --defaults-file=/etc/mysql/debian.cnf
# but you might want to overwrite with a specific user & pass.
# To do this, simply edit bellow.

# Username to access the MySQL server e.g. dbuser
#USERNAME=`grep user /etc/mysql/debian.cnf | tail -n 1 | cut -d"=" -f2 | awk '{print $1}'`

# Username to access the MySQL server e.g. password
#PASSWORD=`grep password /etc/mysql/debian.cnf | tail -n 1 | cut -d"=" -f2 | awk '{print $1}'`

# Host name (or IP address) of MySQL server e.g localhost

# List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3"
# Note that it's absolutely normal that the db named "mysql" is not in this
# list, as it's added later by the script. See the MDBNAMES directives below
# in this file (advanced options).
# This is ONLY a convenient default, if you don't like it, don't complain
# and write your own.
# The following is a quick hack that will find the names of the databases by
# reading the mysql folder content. Feel free to replace by something else.
# DBNAMES=`find /var/lib/mysql -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f5 | grep -v ^mysql\$ | tr \\\r\\\n ,\ `
# This one does a list of dbs using a MySQL statement.
DBNAMES=`mysql --defaults-file=/etc/mysql/debian.cnf --execute="SHOW DATABASES" | awk '{print $1}' | grep -v ^Database$ | grep -v ^mysql$ | grep -v ^performance_schema$ | grep -v ^information_schema$ | tr \\\r\\\n ,\ `

# Backup directory location e.g /backups
# Folders inside this one will be created (daily, weekly, etc.), and the
# subfolders will be database names. Note that backups will be owned by
# root, with Unix rights 0600.

# Mail setup
# What would you like to be mailed to you?
# - log   : send only log file
# - files : send log file and sql files as attachments (see docs)
# - stdout : will simply output the log to the screen if run manually.
# - quiet : Only send logs if an error occurs to the MAILADDR.

# Set the maximum allowed email size in k. (4000 = approx 5MB email [see
# docs])

# Email Address to send mail to? (

# ============================================================
# === ADVANCED OPTIONS ( Read the doc's below for details )===

# List of DBBNAMES for Monthly Backups.

# List of DBNAMES to EXLUCDE if DBNAMES are set to all (must be in " quotes)

# Include CREATE DATABASE in backup?

# Separate backup directory and file for each DB? (yes or no)

# Which day do you want weekly backups? (1 to 7 where 1 is Monday)

# Choose Compression type. (gzip or bzip2)

# Compress communications between backup server and MySQL server?

# Additionally keep a copy of the most recent backup in a seperate
# directory.

#  The maximum size of the buffer for client/server communication. e.g. 16MB
#  (maximum is 1GB)

#  For connections to localhost. Sometimes the Unix socket file must be
#  specified.

# Command to run before backups (uncomment to use)

# Command run after backups (uncomment to use)

# Backup of stored procedures and routines (comment to remove)

par défault
le mail est envoyé à Root
le répertoire par défault du backup est

No Comments

Add a Comment

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *