Automatically back up the mysql database and send it to the e-mail method, mysqlemail
A blog, the most important thing for a website is a database, so it is necessary to back up data frequently.WordPressThere is a plug-in for regular data backup, but it can only be used to back up the current blog. It is not flexible enough. It is suitable for personal blogs and not suitable for some websites. Many people now have multiple websites,ShowfomThere are several websites for students. It is troublesome to install a plug-in for each website. Besides, not every websiteWordPress.
So I wrote a script to automatically back up the mysql database, and added the G-level mailbox gmail to back up the data as much as possible. The following code is as follows:
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 "www@gmail.comrm-r/home/website/backups /*
Save the above Code as automysqlbackup. sh
Then, use crontab to implement dynamic backup. Under ssh,
Crontab-e
Enter the following content:
00 00 ***/home/website/automysqlbackup. sh
In this way, the mysql database is automatically backed up at every day and sent to the Email
Let's briefly describe it.
The first sentence is to back up multiple databases at a time. This requires you to use the root permission .. -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 the root permission, you can change it to this way.
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 in the backups folder into the file name: databackup. SQL .tar.gz
The third sentence is to send the compressed database file to the specified mailbox .....
The topic is database backup, which is the subject of the email. The content is database backup, which is used in the email,
/Home/website/backups/databackup. SQL .tar.gz is the attachment
The www@gmail.com is the Email you want to send