#!/bin/bash # ================================================== # Nom : my_exp_database.sh # Objet : export database # Auteur : N.LAMOTTE # Cree le : 08/02/2012 # Syntaxe : my_exp_database.sh user pwd database_name (otheroption1, otheroption2, otheroption1otheroption3 not mandatory) # ==================================================
user=$1 pwd=$2 database=$3 host=$4 otheroption1=$5 otheroption2=$6 otheroption3=$7
w_date=$(date '+%Y_%m_%d_%H_%M_%S') logpath=/exploit/logs dumppath=/exploit/dumps logfile=my_exp_${database}_${w_date}.log dumpfile=my_exp_${database}.sql
# ---------------------------------- # Fonction d'affichage de la syntaxe # ---------------------------------- syntaxe() { echo "Usage : $0 $1 user $2 pwd $3 database_name $4 host ($5 otheroption1 $6 otheroption2 $7 otheroption3 not mandatory)" } # ----------------------------------
# -------------------------- # Verification de la syntaxe # -------------------------- #if [ $# -ne 3 -a $# -ne 4 ] if [ $# -lt 4] then echo "==================================================" echo "ERREUR : Nombre d'arguments incorrects !" syntaxe echo "==================================================" exit 1 fi
if [ $# -gt 5 ] then echo "mysql with option $otheroption1 $otheroption2 $otheroption3" dumpfile=my_exp_${database}_withoption.sql logfile=my_exp_${database}_withoption_${w_date}.log fi
#mysqldump -u $user -p${pwd} $database $otheroption1 $otheroption2 $otheroption3 --log-error=$logpath/$logfile > $dumppath/$dumpfile mysqldump -h $host -u $user -p${pwd} -v $database $otheroption1 $otheroption2 $otheroption3 > $dumppath/$dumpfile