Automatic backup mysql database and send mail

Disclaimer: This article switched to: http: //blog.csdn.net/l1028386804/article/details/44240031

A blog, a website is the most important database, I often backup data is needed. Although? WordPress ? There are plug-timed backup data, but can only back up the current blog, is not flexible enough. Suitable for small personal blog, for some sites speaking, are not appropriate. now many people have more than one website, showfom ? students have several websites. each site installing a plug-in more trouble. Moreover, not every site is WordPress ? a

.

So write a script to automatically back up MySQL database, coupled with gmail this G-class mail, how much data can be backed up ... Here is the code:


Save the above code is automysqlbackup.sh

Then use crontab achieve automatic backup, in SSH,

crontab -e

Enter the following:

00 00 * * * /home/website/automysqlbackup.sh

This realization 00:00 every day automatically backup mysql database and sent to Email

Simple instructions under the bar.

The first sentence is a one-time backup multiple databases, which you can use to root user privileges ..- u is behind the back of the database user name -p password database is a database db1 db2 db3 do not need the space you need to back up name.

If your database user name is not the root privileges, you can change this


The second sentence is compressed backups of data files inside a folder for the file name: databackup.sql.tar.gz

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

The topics: database backup, is the subject of the message, content: database backup, is in the use of e-mail,

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

Email to be sent to [email protected]






Guess you like

Origin www.cnblogs.com/SyncNavigator-V8-4-1/p/11015845.html