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-p980405 >/mysqldata/mysql$rq.tar.gz
/var/lib/mysql is the directory of your database files, some users are/usr/local/mysql/data, everyone may be different
This column more highlights: http://www.bianceng.cn/database/MySQL/
/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.
Stop the database service process or lock the database before the TAR command executes.
Otherwise restore the data, there will be a database damage situation, good luck can be repaired, bad luck will not be.