Automatic MySQL backup (Linux)

Source: Internet
Author: User
Tags mysql backup

Regular MySQL backup is an important task, but manual operations are too cumbersome and difficult to avoid any omissions. You can use the following method to regularly back up data.

1. Create a backup folder

# Cd/chinamaga
# Makedir backup

2. Write a running script

# Vi mysqldump. Sh

Write the following content:

Filename = 'date + % Y % m % d'
Mysql_bin_dir/mysqldump-u user-ppassword chinmaga>/chinamaga/backup/name1_filename.gz

Save and exit

Note:

(1) mysql_bin_dir: Bin path of MySQL;

(2) dataname: Database Name;

(3) User: Database User Name;

(4) password: User Password;

(5) name: ID of the prefix of the backup file.

3. Add execution permissions for the script

# Chmod 777 mysqldump. Sh

4. Let crontab complete the task of regular execution

In this step, the RedHat method will be different and will be provided later.

Edit crontab:

# Vim/etc/crontab

Add the following to the last line:

01 5 *** root/chinamaga/backup/mysqldump. Sh

Run the script at every day, or change 5 to another specified time.

5. Restart crontab or load the configuration file again.

#/Sbin/service crond reload | #/sbin/service crond restart

In fact, the principle is very simple. Make a script for the Linux system to run automatically. We can also expand to edit a script to automatically back up website files, so that Linux can complete the script and automatically back up the entire website every day ......

Related Article

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.