Linux Shell implements a daily scheduled backup of the MySQL database _linux shell

Source: Internet
Author: User

Daily backup MySQL database tasks, delete the specified number of days before the data, keep the date of the specified day;

Demand:

1, backup MySQL data 4 points per day;

2, to save space, delete more than 3 months of all backup data;

3, delete more than 7 days of backup data, keep 3 months of 10th number 20th number of backup data;

#创建shell文件
vim backup_mysql.sh
 
mysqldump-uroot-p123456--all-databases >/data/dbdata/mysqlbak/' Date +%Y %m%d '. SQL
find/data/dbdata/mysqlbak/-mtime +7-name ' *[1-9].sql '-exec rm-rf {} \;
find/data/dbdata/mysqlbak/-mtime +92-name ' *.sql '-exec rm-rf {} \;
 
#创建定时任务
crontab–e
0 4 * * */data/dbdata/backup_mysql.sh

The above is the entire content of this article, I hope that you can be proficient in the shell script to help.

Related Article

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.