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

How to write a script for mysql scheduled backup in Linux

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-06-02 22:52:49
forward
1461 people have browsed it

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
Copy after login

2. Execute scheduled tasks

Use crontab to execute the above script regularly

crontab -e
Copy after login

Perform backup every Monday morning

05 02 * * 1 /home/mysqls_backup/mysqlbackup.sh
Copy after login

View crontab list

crontab -l
Copy after login

Effective immediately

/etc/init.d/cron restart
Copy after login

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!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template