linux under mysql automatic backup database with automatic deletion of temporary files

  • 2020-05-15 02:18:02
  • OfStack

1. Automatically delete temporary files at 23:00 every day

First take a look at crontab's task list:
crontab -l
Then new:
crontab -e
Add 1 line:
00 03 * * * rm -rf /www/cmstest/my120/public/scripts/jpgraph/*
Save to exit.
Restart services: / etc rc d/init d/crond restart

2. Automatically backup the database at 24:00 every day

The system crontab is used to regularly execute backup files, and the backup results are saved by date to achieve the purpose of backup.

1. Create a path /mysqldata to save the backup files
#mkdir /mysqldata

2. Create /usr/sbin/bakmysql files
Find the path to the database files:
As is: 1 / var lib/mysql, or, / usr local/mysql/var
Search method:

1, / usr/local/mysql/bin/mysql - u root - p into database
2. Input: show databases;
3, it is possible to view all the databases, and then
4. find / -name db(database name you are looking for)

After: #vi /usr/sbin/bakmysql
The input


rq=` date +%Y%m%d `
tar zcvf /mysqldata/mysql$rq.tar.gz /var/lib/mysql

3, modify the file properties to make it executable

# chmod +x /usr/sbin/bakmysql
New task:
First look at crontab's task list:
crontab -l
Then new:
crontab -e
Add 1 line
00 04 * * * /usr/sbin/bakmysql
Means that backups are performed at 24 o 'clock every day

4. Restart crond
# /etc/rc.d/init.d/crond restart
Then you can see in/mysqldata a day under the similar file: mysql20040619. tar. gz.


Related articles: