El siguiente script permite respaldar los procedimientos, y/o funciones de una base de datos dada como parámetro, y dejando el respaldo parseado y listo para ser registrado.
Este fue creado con la necesidad de respaldar de uno por uno de los procedimientos, en archivos separados y formateado de tal manera que se pudiera registrar sin necesidad de mover.
#!/bin/bash## Dump procedures infiles individuals._database=$1;# i put a default, coudl be a parameter# _dir=$2_dir="/home/clickbal/respaldos/procedures/"$2/;if [ -z ${2+x} ];then# If not sent the second parameter, take the first one, to the destination file._dir=${_dir}/$1/fiif [ -z ${1+x} ];thenecho ''echo ' + At least one parameter, database name + 'echo ' + the second one is the directory + 'echo ''exitfiif [[ ! -e $_dir ]]; thenmkdir $_direlif [[ ! -d $_dir ]]; thenecho "$_dir already exists but is not a directory" 1>&2fiecho "Database of procedures: " ${_database}# "Obtain the grooup of procedures to dump, in database."echo "SELECT routine_name FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = '${_database}' AND ROUTINE_TYPE = 'PROCEDURE';" | mysql -A ${_database} --skip-column-names --raw --batch > list_routines.txt# While to record alld the procedures.while IFS='' read -r line || [[ -n "$line" ]]; doecho "Store procedure to backup: $line"echo "SELECT CONCAT('DROP PROCEDURE IF EXISTS \`', specific_name, '\`;\n DELIMITER \$\$\nCREATE PROCEDURE \`', specific_name, '\`(', param_list, ') %ending% \n', body_utf8, ' \$\$\nDELIMITER ;\n') FROM mysql.proc WHERE db = '${_database}' AND specific_name = '$line';" | mysql -A ${_database} --skip-column-names --raw --batch > ${_dir}$line.sqldone < list_routines.txtecho "End of dump "
No hay comentarios.:
Publicar un comentario