Use the system crontab to execute the backup file regularly, save the backup result by date, and achieve the purpose of backup.
1, create the path to save the backup file/mysqldata
#mkdir/mysqldata
2. Create/usr/sbin/bakmysql files
#vi/usr/sbin/bakmysql
Input
rq= ' Date +%y%m%d '
Tar Zcvf/mysqldata/mysql$rq.tar.gz/var/lib/mysql
or write
rq= ' Date +%y%m%d '
mysqldump--all-databases-u root-p Password >/mysqldata/mysql$rq.sql
/var/lib/mysql is the directory of your database files, some users are/usr/local/mysql/data, everyone may be different
/mysqldata/represents the directory where the backup files are saved, and everyone can do it according to their own requirements.
3, modify the file properties to make it executable
# chmod +x/usr/sbin/bakmysql
4. Modify/etc/crontab
#vi/etc/crontab
Add the following
3 * * * root/usr/sbin/bakmysql
Indicates a backup is performed 3 o'clock daily
5. Reboot Crond
#/etc/rc.d/init.d/crond Restart
Complete.
So every day you can see a file like this in/mysqldata.
Mysql20040619.tar.gz
You can download it directly.