Automatically back up MySQL database and send to email method

Source: Internet
Author: User
Tags db2

A blog, a site is the most important is the database, so it is necessary to back up the data frequently. Although WordPress has regular backup of the data plug-in, but only back up the current blog, not flexible. Suitable for personal small blog, for some websites, It's not going to fit. Many people now have multiple websites, andshowfom have several websites. Each site has a plug-in to be more troublesome. And not every site is WordPress .

So wrote an automatic backup MySQL database script, plus gmail this G-level mailbox, backup how much data can be ... Here's the code:

Mysqldump-uuser-ppassword--databases db1 DB2 db3 >/home/website/backups/databackup.sqltar zcf/home/website/ Backups/databackup.sql.tar.gz/home/website/backups/echo "topic: Database Backup" | Mutt-a/home/website/backups/databackup.sql.tar.gz-s "Content: Database Backup" [Email protected]rm-r/home/website/backups/*

Save the above code as automysqlbackup.sh
Then use Crontab to implement the backup, under SSH,

Crontab-e

Enter the following:

XX * * * */home/website/automysqlbackup.sh

This makes it possible to automatically back up the MySQL database and send it to email every 00:00

Just a simple explanation.
The first sentence is a one-time backup of multiple databases, which you need to use root privileges of the user can be. -U is followed by the database user name-p followed by the database password without spaces DB1 DB2 DB3 for the database name you need to back up.
If your database user name does not have root permission, you can change this

Mysqldump-uuser-ppassword db1 >/home/website/backups/db1.sqlmysqldump-uuser-ppassword DB2 >/home/website/ Backups/db1.sqlmysqldump-uuser-ppassword db3 >/home/website/backups/db1.sql

The second sentence is to compress the data file inside the backups folder to the file name: databackup.sql.tar.gz

The third sentence is to send the compressed database file to the specified mailbox .....

The topic: Database backup, is the subject of the message, Content: Database backup, is the use of mail,

/home/website/backups/databackup.sql.tar.gz as an accessory

[email protected] for email to be sent

Automatically back up MySQL database and send to email method

Related Article

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.