Home  >  Article  >  Database  >  How to write a script for mysql scheduled backup in Linux

How to write a script for mysql scheduled backup in Linux

WBOY
WBOYforward
2023-06-02 22:52:491350browse

How to write a script for mysql scheduled backup in Linux

1. Create a backup script

Backup script:

#!/bin/bashdate_str=$(date +%Y%m%d-%T)cd /bf/mysql_back
mysqldump -h localhost -u root --password=PASSWORD -R -E -e \databaseName \
 | gzip > /bf/mysql_back/database_$date_str.sql.gz

2. Execute scheduled tasks

Use crontab to execute the above script regularly

crontab -e

Perform backup every Monday morning

05 02 * * 1 /home/mysqls_backup/mysqlbackup.sh

View crontab list

crontab -l

Effective immediately

/etc/init.d/cron restart

The above is the detailed content of How to write a script for mysql scheduled backup in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete