Automatic backup mysql database and automatically delete temporary files


Automatic backup mysql database and automatically delete temporary files, a friend in need can refer to.

First, the daily 23:00 automatically delete temporary files
first look at the task list the crontab:
crontab the -l
and New:
crontab -e
to add a line:
00 03 * * * RM -rf / the WWW / cmstest / my120 / public / scripts / jpgraph / *
save and exit.
Restart the service: /etc/rc.d/init.d/crond restart

Second, the automatic backup database 24:00 daily
use of the timing system crontab to perform the backup file, backup by date save the results, the purpose of backup.

1, create a path to save the backup file / mysqldata
#mkdir / mysqldata

2, create / usr / sbin / bakmysql file
search path database library files:
are generally: / var / lib / mysql, or, / usr / local / mysql / var
discovery methods:
1, / usr / local / MySQL / bin / mysql -u root -p enter the database
2, type: Show databases;
3, it is possible to see all of the database, then
4, find / -name db (database name you want to find)

After: #vi / usr / sbin / bakmysql
input
 

Code is as follows: rq = `date +% Y% m% d`


takes zcvf /mysqldata/mysql$rq.tar.gz / var / lib / mysql

3, modify the file attributes, make it executable
# chmod + x / usr / sbin / bakmysql
New Task:
First look at the task list the crontab:
crontab the -l
and New:
crontab -e
to add a line
00 04 * * * / usr / sbin / bakmysql
represent 24 o'clock every day to perform backups

5, restart crond
# /etc/rc.d/init.d/crond restart
after which you can see under similar files in / mysqldata in every day: mysql20040619.tar.gz.

Guess you like

Origin www.cnblogs.com/SyncNavigator-V8-4-1/p/11014183.html