Improved version mysqldump in Linux to back up Mysql database _mysql

Source: Internet
Author: User
Because mysqldump will add a global lock to the entire library.
A full-library backup with Mysqldump will have the following three effects.
1, the server CPU seriously blocked.
2, disk I/O line increase.
3, all the queries have become a slow query.
My current website database is about 5 g or so, and it increases every day.
The table structure is a mixture of three myisam,innodb,memory.
So it's a little difficult to use hotcopy tools alone. So today I've simply changed my last written script about using outfile to back up MySQL.
Can solve the above three shortcomings.

1, Backup script content

[David_yeung@localhost ~]$ Cat Fast_backup
#!/bin/sh
#
# Created by David Yeung.
#
# 20080707.
#
# Backup MySQL ' s full data.
#
Dbname=$1
Backupdir=/home/david_yeung/backup_new
Username=backup_user
passwd=123456
Tarname= "$BACKUPDIR"/backup "$" ' Date ' +%y%m%d '
# ADD your own database name here.
Case "$" in
My_site);;
*) exit;;
Esac
# Get all the tables ' name.
num= '/usr/local/mysql/bin/mysql-u$username-p$passwd-s-vv-e "show tables"-D $DBNAME |wc-l '
headnum= ' Expr ${num}-3 '
tailnum= ' Expr ${num}-7 '
arr1= '/usr/local/mysql/bin/mysql-u$username-p$passwd-s-vv-e "show tables"-D $DBNAME | Head-n "$HEADNUM" | Tail-n "$TAILNUM"
Arr2= ($ARR 1)
I=0
While ["$i"-lt "${#ARR2 [@]}"]
Todo
tmpfilename=${arr2[$i]}
# The real dump process.
/usr/local/mysql/bin/mysqldump-u$username-p "$PASSWD" "$DBNAME" "$tmpFileName" >> "$TARNAME"
Let "i++"
Done

2, because we have been using stored procedures, so we have to back up separately.

[David_yeung@localhost ~]$ Cat fast_sp
#!/bin/sh
# Created by David Yeung 20080122.
#
# Backup site ' s routine.
Tarname=/home/david_yeung/backup_new/spbackup "$" ' Date ' +%y%m%d '
/usr/local/mysql/bin/mysqldump-ubackup_user-p123456-n-t-d-R my_site > "$TARNAME"

3, throw into the plan task inside go, no matter.

[Root@localhost backup_new]# Crontab-l
0 * * * */home/david_yeung/fast_backup My_site
0 0 * * 5/home/david_yeung/fast_sp

Back up the data every 1 o'clock in the morning in the morning and back up the stored procedure every Friday.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.