Optimizing Mysql backup bash script
Hi,
I have created a bash script that makes full mysql backups every day, set in crontab without compression as the databases sizes are small. At the end of the script backups are copied to cifs mount point (mounted in fstab). Script runs without problem. The problem is that the script is not perfect. As you can seen, the code in bold are repetitive. Better would be to add new variables and add code with with show databases and fetch that output and add for and do loop etc, and avoid repetitive lines. Any suggestions to improve my script?? please help. Thx in advance #!/bin/sh FECHA=`date +"%d%m%Y_%H%M"` cd /var/backups/MySql/ #Borrar ficheros *.sql con 7 dias de antiguedad en la ruta local /var/backups/Mysql find -name '*.sql' -type f -mtime +7 -exec rm {} \; cd /mnt/BackupMySql/ #Borrar ficheros *.sql con 14 dias de antiguedad en la ruta cifs mountpoint /mnt/BackupMySql segun /etc/fstab find -name '*.sql' -type f -mtime +14 -exec rm {} \; #Inicio generacion backup con fecha actual mysqldump -uroot -ppassword --opt bugtracker > /var/backups/MySql/bugtracker_$FECHA.sql mysqldump -uroot -ppassword --opt mysql > /var/backups/MySql/mysql_$FECHA.sql mysqldump -uroot -password --opt --single-transaction information_schema > /var/backups/MySql/information_schema_$FECHA.sql mysqldump -uroot -password --opt qstock > /var/backups/MySql/qstock_$FECHA.sql mysqldump -uroot -ppassword --opt wiqui > /var/backups/MySql/wiqui_$FECHA.sql mysqldump -uroot -password --opt wordpress > /var/backups/MySql/wordpress_$FECHA.sql cp -f /var/backups/MySql/*.sql /mnt/BackupMySql/ |
mysql -uroot -ppassword --batch -e "SHOW DATABASES" | while read f
do mysqldump -uroot -password --opt $f > /var/backups/MySql/$f_$FECHA.sql done maybe you also should add: mysql -B -N $@ -e "SELECT DISTINCT CONCAT( 'SHOW GRANTS FOR ''', user, '''@''', host, ''';' ) AS query FROM mysql.user" | \ mysql $@ | \ sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}' This dumps the GRANTS so it can be imported againg when the server need rebuilding after a crash.... |
All times are GMT -5. The time now is 04:48 PM. |