Use the system crontab to execute backup files regularly and save the backup results by date to achieve the purpose of backup.
1. Create the path to save the backup file /MySQLdata
#mkdir /mysqldata
2. Create the /usr/sbin/bakmysql file
#vi /usr/sbin /bakmysql
Enter
Note: The ` symbol is the symbol above the TAB key, not the
to the left of ENTER. There must also be a space after the date. Drq = `date +%y%m%d's `Tar ZCVF/Mysqldata/Mysql $rq.tar.gz/var/lib/mysql
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. For some users, it is /usr/local/mysql/data. It may be different for everyone. /mysqldata/ represents the directory where backup files are saved. Everyone can also choose this according to their own requirements. Do.
3. Modify the file attributes to make it executable
# chmod +x /usr/sbin/bakmysql
4. Modify /etc/crontab
#vi / etc/crontab
Add
01 3 * * * root /usr/sbin/bakmysql
means to perform backup at 3 o'clock every day
02 * * * * root /usr/sbin/bakmysql
So you can see such a file in /mysqldata every day
mysql20070929.tar.gz
Just download it directly.