#!/bin/sh
USER="user"
PASSWD="pass"
DATABASE="db"
COMMAND="/usr/bin/mysqldump"
DIR="/somo dir/"
FILE="$DIR/backup`date +"%F_%H-%M-%S"`.sql";
GFILE="$FILE.gz"
#here is the magic. this array have the tables in the same order of creation,
# only modify the tables with your scheme and is ready for use.......
declare -a TABLES
TABLES_DB1=(dbClientes dbCicloProducto dbEstadoCicloProducto dbEstados dbPersonas dbTelefonos dbRegiones dbOficinas dbDistribuidores dbUsuarios dbGrupos dbSubGrupos dbOperaciones dbServicios dbAclGroups dbAclMapService dbAclMapUser dbOficinasClientes dbContactosClientes dbCamadas dbCiudades dbComunas dbDirecciones dbMandantes dbCrossDirecciones dbCrossTelefonos dbCarpetas dbAgendar dbAcciones dbLogAcciones dbErrores dbLogErrores dbLogCarpeta dbParsedFiles dbFastInput dbGeneralSpool)
#echo "deleting old files"
/usr/bin/rm -f "$DIR/*.sql.gz"
echo " " > $FILE
echo "CREATE DATABASE IF NOT EXISTS $DATABASE" >> $FILE
echo "USE $DATABASE;" >> $FILE
#counting element of the array
k=0;
for j in ${TABLES_DB1[@]}; do
k=$[$k+1]
done
# dros the tables, only for secure
while [ $k -gt 0 ]
do
echo "DROP TABLE IF EXISTS ${TABLES_DB1[$j]};" >> $FILE
k=$[$k-1]
done
#make a mysqldump for each table in the orden of creation of tables ,
#no in alfabetics order , son you dont have any constrains error
for i in ${TABLES[@]}; do
$COMMAND -u $USER -p$PASS -a -Q -c --no-autocommit $DATABASE ${i} >> $FILE
echo " " >> $FILE
done
# simple
# enjoy it
# Rafael Avaria G.
# any commnet to :
ravaria@excelsium.cl