MySQL: Difference between revisions

From Anthony Pastor Wiki Notes - Verba volant, scripta manent
Jump to navigation Jump to search
No edit summary
(Replaced content with "* List MySQL tables engines for a MYDB database: <syntaxhighlight lang="sql"> SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = 'MYDB' AND ENG...")
Line 1: Line 1:
<syntaxhighlight lang=bash>
* List MySQL tables engines for a MYDB database:
#!/bin/bash
# Sauvegarde serveur Linux


SVG_DIR='/sauvegarde/'
<syntaxhighlight lang="sql">
mkdir ${SVG_DIR}
SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = 'MYDB' AND ENGINE IS NOT NULL ORDER BY ENGINE;
 
# Définition des paramètres FTP
#FTP_MACHINE=ftpbackffffffffffffff.ovh.net
#FTP_USER=mon_utilisateur_ftp
#FTP_PASSWORD=xxxxx
 
# ================ DUMP DE TOUTES LES BASES MYSQL ==================
 
# Identification de la base
USER=root
PASSWORD=xxxxx
 
# Creation du répertoire racine
mkdir -p /var/export_sql
 
# Definition du repertoire racine
ROOT_DIRECTORY='/var/export_sql/'
 
# Definition du repertoire log
LOG_PREFIX_DIRECTORY='log/'
LOG_FILENAME='dump_databases.log'
 
# Persistance des sauvegardes en nombres de jours
MTIME=100
 
# Variable globale concernant le répertoire cible des dumps
TARGET_PATH=${ROOT_DIRECTORY}
 
# Variable globale concernant les LOGS
LOG_DIRECTORY=${ROOT_DIRECTORY}${LOG_PREFIX_DIRECTORY}
LOG_PATH=${LOG_DIRECTORY}${LOG_FILENAME}
 
# Exportation des bases de donnees
 
# Suppression des sauvegardes datant de plus de ${MTIME} jours
find ${TARGET_PATH}/* -mtime ${MTIME} -delete
 
# Définition du nom de fichier (pour dump complet)
DUMP_NAME=MySQL_Dump`date '+%Y%m%d_%H%M%S'`.sql
/usr/bin/mysqldump -u ${USER} -p${PASSWORD} --all-databases > ${TARGET_PATH}/${DUMP_NAME}
# Copie du dernier dump dans le dossier de sauvegarde
cp -a ${TARGET_PATH}/${DUMP_NAME} ${SVG_DIR}/${DUMP_NAME}
 
# ============= Copie des dossiers/fichiers a sauvegarder ============
 
# Copie des fichiers de configuration d'apache
cp -a /opt/prod/apache ${SVG_DIR}/apache2_conf
 
# Copie des sites
cp -a /sites/ ${SVG_DIR}/
 
# Copie de la configuration de Bind
# cp -a /etc/bind ${SVG_DIR}/bind_conf
# cp -a /var/bind/ ${SVG_DIR}/var/bind/bind_conf
# cp -a /etc/hosts  ${SVG_DIR}/hosts
 
# Copie du resolv.conf
cp -a /etc/resolv.conf ${SVG_DIR}/resolv.conf
 
# Copie des utilisateurs
cp -a /etc/passwd ${SVG_DIR}/passwd
 
# Copie des groupes
cp -a /etc/group ${SVG_DIR}/group
 
cp -a /etc/postfix ${SVG_DIR}/postfix
cp -a /etc/amavis ${SVG_DIR}/amavis
cp -a /etc/clamav ${SVG_DIR}/clamav
cp -a /etc/courier ${SVG_DIR}/courier
#cp -a /home ${SVG_DIR}/home
#cp -a /etc/proftpd ${SVG_DIR}/proftpd
cp -a /etc/hostname ${SVG_DIR}/hostname
 
 
# ========= Archivage et suppression du dossier de backup =============
SVG_FILE=Backup_`date '+%Y%m%d_%H%M%S'`.tar.gz
tar -czf ${SVG_FILE} ${SVG_DIR}
rm -rf ${SVG_DIR}
 
# ========== Envoi du fichier en FTP et nettoyage =====================
ftp -vin ${FTP_MACHINE}<<EOF
user ${FTP_USER} ${FTP_PASSWORD}
binary
mput ${SVG_FILE}
Bye
EOF
 
# Suppression du fichier de sauvegarde
rm -f ${SVG_FILE}
</syntaxhighlight>
</syntaxhighlight>

Revision as of 10:47, 16 April 2015

  • List MySQL tables engines for a MYDB database:
SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = 'MYDB' AND ENGINE IS NOT NULL ORDER BY ENGINE;