MySQL regular backup is an important work, but manual operation is too cumbersome, also difficult to avoid omissions, use the following methods to allow the system to back up data on a regular basis.
1. Create a backup folder
#cd/www
#makedir Backup
2. Write Run script
#vi Autobackup
Write the following:
Filename= ' Date +%y%m%d '
Mysql_bin_dir/mysqldump–opt Dataname-u User-ppassword | gzip >/www/mysqlbackup/name$filename.gz
Save exit
Description
(1) The bin path of the Mysql_bin_dir:mysql;
(2) Dataname: database name;
(3) User: Database username;
(4) Password: User password;
(5) Name: Custom backup file prefix identification.
As in the previous example, the MySQL database is automatically backed up and stored in gzip compression, in the form of a file named name20080101.gz.
3. Add execution permissions to the script
#chmod +x Autobackup
4, let crontab to complete the task of regular execution
In this step, the Redhat method will be different, specifically given in the following.
Edit crontab:
#vi/etc/crontab
In the last line, add:
5 * * * root/www/autobackup
Run the script at 5 o ' Day, or you can modify 5 for another specified time.
Redhat Method:
Redhat crontab 4 directories per hour (/etc/cron.hourly: hourly;/etc/cron.daily: per day;/etc/cron.weekly: Weekly;/etc/cron.monthly: Monthly) The way the script comes out to run.
In Redhat, just copy the script you just edited to the appropriate directory.
5, restart Crontab
#/etc/rc.d/init.d/crond restart
Complete.