Home  >  Article  >  Database  >  Practical method for automatic backup of MySQL database under Linux

Practical method for automatic backup of MySQL database under Linux

巴扎黑
巴扎黑Original
2017-03-19 10:46:14977browse

[Introduction] Regular backup of MySQL is an important task, but manual operation is too cumbersome and it is difficult to avoid omissions. Use the following method to make the system regularly back up data. ◆1. Create a backup folder cd www  makedir backup ◆2. Write a running script

Regular backup of MySQL is an important task, but manual operation is too cumbersome and it is difficult to avoid omissions. Use the following method This allows the system to back up data regularly.
 ◆1. Create a backup folder

 #cd /www

 #makedir backup

 ◆2. Write a running script

 #vi autobackup

Write the following content:

filename=`date +%Y%m%d`

mysql_bin_dir/mysqldump –opt dataname -u user -ppassword | gzip > /www/mysqlbackup/name$filename.gz

Save and exit

Description:

(1) mysql_bin_dir: mysql bin path;

(2 )dataname: database name;

 (3)user: database username;

 (4)password: user password;

 (5)name: custom backup file Prefix identifier.

As in the above example, the mysql database will be automatically backed up and stored in gzip compression, with the file name in the form of name20080101.gz.

 ◆3. Add execution permissions to the script

 #chmod +x autobackup

 ◆4. Let crontab complete regularly executed tasks

 This step , Redhat’s method will be different, which will be given later.

Edit crontab:

#vi /etc/crontab

Add in the last line:

01 5 * * * root /www/autobackup

Run the script at 5 o'clock every day. You can also modify 5 to other specified times.

Redhat method:

Redhat's crontab uses four directories to be called by time (/etc/cron.hourly: every hour; /etc/cron.daily: every day; /etc/cron. weekly: every week; /etc/cron.monthly: every month) is how the script is run.

In Redhat, you only need to copy the script you just edited to the corresponding directory.

 ◆5. Restart crontab

 #/etc/rc.d/init.d/crond restart

 Complete.

The above is the detailed content of Practical method for automatic backup of MySQL database under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn