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