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