Linux automatically backs up MySQL database

Source: Internet
Author: User
Tags mysql login

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.