LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-07-2011, 02:09 AM   #1
montblanc
LQ Newbie
 
Registered: Feb 2008
Posts: 7

Rep: Reputation: 0
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/
 
Old 10-07-2011, 05:08 AM   #2
JSkywalker
Member
 
Registered: Aug 2007
Distribution: openSUSE
Posts: 102

Rep: Reputation: 24
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....
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Optimizing a Bash Script zokken Programming 3 04-13-2011 12:29 AM
Can MySQL log on via SSH/bash? mysql:x:27:101:MySQL Server:/var/lib/mysql:/bin/bash Ujjain Linux - Newbie 2 04-24-2009 02:21 PM
optimizing this bash script yah0m Programming 6 04-17-2009 07:42 PM
how to create backup MYSQL Script to backup my database for every 1hour RMLinux Linux - Newbie 3 11-20-2008 10:13 AM
bash backup script kristof_v Programming 4 07-24-2007 07:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration