Automatically backs up MySQL database every day under CentOS

Source: Internet
Author: User

Automatically backs up the MySQL database scripts every day and automatically sends them to the mailbox you specify so that Vpser no longer worries about losing data.

Mysqldump-uuser-ppassword–databases db1 DB2 db3 >/home/website/backups/databackup.sql

Tar zcf/home/website/backups/databackup.sql.tar.gz/home/website/backups/

echo "topic: Database Backup" |mutt-s "Content: Database backup" [email protected] -a/home/website/backups/databackup.sql.tar.gz

Rm-r/home/website/backups/*

Save the above code as automysqlbackup.sh

Then use crontab to implement automatic backup, run 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

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.sql

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

Mysqldump-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

Automatically backs up MySQL database every day under CentOS

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.