Linux shell realizes regular backup of MySQL database every day


Regularly back up MySQL database tasks every day, delete the data before the specified days, and retain the data of the specified days;

1. Back up MySQL data at 4:00 every day;
2. In order to save space, delete all backup data for more than 3 months;
3. Delete the backup data for more than 7 days, and keep the backup data for the 10th, 20th and 30th in 3 months;

#Create SHELL file
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 {} \;
#Create scheduled task
crontab –e
0 4 * * * /data/dbdata/

The above is the whole content of this article. I hope it will be helpful for you to master shell scripts.

Recommended Today

Markup language – List

Standardized design solution – markup language and style manualWeb Standards Solutions The Markup and Style Handbook Part 1: get down with markup Chapter 1 List The list can be found on almost every page on the Internet Hyperlink list; Shopping cart item list; Your favorite movie list Even the navigation list of the whole website […]