Linux Mysql automatic backup database and automatic deletion of temporary files _mysql

Source: Internet
Author: User

Automatic deletion of temporary files 23:00 daily

First look at the crontab task list:
Crontab-l
And then NEW:
Crontab-e
Add a line:
* * * rm-rf/www/cmstest/my120/public/scripts/jpgraph/*
Save exit.
Restart Service:/etc/rc.d/init.d/crond restart

Second, daily 24:00 automatically back up the database

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
To find the path to a database library file:
Are generally:/var/lib/mysql, or,/usr/local/mysql/var
Find Method:

1,/usr/local/mysql/bin/mysql-u root-p into the database
2, input: show databases;
3, this is to be able to view all the databases, and then
4, Find/-name db (You want to look up the name of the database)

After: #vi/usr/sbin/bakmysql
Input

Copy Code code as follows:

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 the crontab task list:
Crontab-l
And then NEW:
Crontab-e
Add a row
* * * */usr/sbin/bakmysql
Indicates a backup is performed 24 o'clock daily

4. Reboot Crond
#/etc/rc.d/init.d/crond Restart
Every day after that, you can see a similar file in/mysqldata: mysql20040619.tar.gz.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.