Open the server this morning. 13W a Trojan horse. was successfully exploded 2 times, 3 holes. The database was deleted. It was a sad experience.
Fortunately before there was a backup, the server also upgraded the security mechanism, but the backup was last month's backup. So want to write a script, try to automatically back up the database.
1. Take a look at the big plate first.
Forgot. I have only one plate.
2. Create a directory first. Used to store scripts and backup databases.
3. Writing scripts
# !/bin/bashMysqldump-uusername-ppassword DatabaseName >/home/sqlbackup/databasename_$ (date +% y%m%d_%h%m%s). sql
Copy the above to the script
Where username is the MySQL account name password is the mysql login password databasename database name
4. Then give a EXECUTE permission
# chmod U+x yn_db.sh
5. Try it and see if the script can run
#./yn_db.sh
The red box will report a warning. But the file is still generated. So the warning ignores
6. Then set the scheduled task. (indicates that the scheduled task Crontab has been fully installed.) Not installed by self-Baidu)
# CRONTAB-E (Enter configuration timer Task)
The red line is my job. Represents a yn_db.sh that is performed once every week in Sunday of 0:0.
You can also set it to every minute first, and then check to see if the file is generated. You can do it.
Above
Linux automatically backs up MySQL database