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

Regular backup of MySQL database under Linux platform

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

Share

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

Write MySQL backup script according to requirement, requirement is as follows: Make daily backup to specified database and save backup files for one week, delete files after one week automatically.

1. Create shell scripts

[root@server18 mysql]$ mkdir -p /home/mysql/DB_BAK/day_bak/

[root@server18 mysql]$ vim day_bak.sh

DB_NAME='tdc_ntt_debug'

USER='mysql'

PWD='mysql'

TIME=$(date +%Y%m%d)

DEL_TIME=$(date --date="7 days ago" +%Y%m%d)

DB_BAK_NAME=tdc_debug${TIME}.sql

DB_DEL_NAME=tdc_debug${DEL_TIME}.sql

BACKUP_PATH='/home/mysql/DB_BAK/day_bak/'

echo $BACKUP_PATH$DB_BAK_NAME

if test -f $BACKUP_PATH$DB_DEL_NAME

then

echo "Delete history dump file"

rm -f $BACKUP_PATH$DB_DEL_NAME

fi

mysqldump -u $USER -p$PWD $DB_NAME > $BACKUP_PATH$DB_BAK_NAME

2./etc/crontab

[root@server18 ~]# crontab -e

30 21 * * * root /home/mysql/DB_BAK/day_bak/day_bak.sh

MySQL backups are made every night at 21:30 and the backup files are retained for 7 days.

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

Database

Wechat

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

12
Report