Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysqldump backs up the database and deletes the backup file script from 7 days ago

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Create the backup script mysql_backup.sh in/server/scripts/directory

#!/ bin/bash# ---------------------------# Filename: mysql_backup.sh# Revision: 1.4# Date: 2016/05/09# Author: ywliyq# Email: ywliyq@163.com# Website: http://ywliyq.blog.51cto.com/# Description: mysql backup every day delete before 7days.# Notes: This plugin uses the "" command# ----------------------------# Copyright: 2016 (c) ywliyq# License: GPL# ----------------------------# Backup file is saved in the directory, if it does not exist Createbasepath='/data/mysql/backup/'if [ ! -d "$basepath" ]; then mkdir -p "$basepath"fi# mysql bakcup to /data/mysql/backup//application/mysql/bin/mysqldump -uroot -p'12345677' --events --ignore-table=mysql.events -F -B -A|gzip >$basepath/mysqlbak_$(date +%F).sql.gz# Delete the backup data to 7 days beforefind $basepath -mtime +7 -name "*.sql.gz" -exec rm -rf {} \;

===============================================================

Create a timed task and execute this script every day at 2 a.m.

# crontab -e

###### mysql backup at 2016/05/09 by ywliyq ######

0 2 * * * /bin/sh /server/scripts/mysql_backup.sh >/dev/null

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report