centos7-daily backup MySQL database The first step: Write a database backup script database_mysql_shell.sh
#!/bin/bashdate=`Date+%y%m%d%h%M ' #every minutedatabase=springboot-Admin #database namedb_username=Root #database Usernamedb_password="MySQL"#database Passwordbackup_path=/backup/mysqldata #backup path#backup command/usr/bin/mysqldump-u$db_username-p$db_password-h127.0.0.1-R--opt $DATABASE |gzip> ${backup_path}\/${database}_${date}.sql.gz#just Backup the latest5 DaysFind${backup_path}-mtime +5-name"${database}_*.sql.gz"-execRM-f {} \;
Step two: Give the script permission
chmod +x Database_backup_shell. SH
Step three: Write a scheduled backup task
Enter the following command:
Crontab-e
Write the following in the page:
xx 3 * * */root/database_backup_shell. SH
You can automate the first-step script every three o'clock in the morning, back up the MySQL database to/backup/mysqldata, and keep only the database backups for the last 5 days.
centos7-daily backup of MySQL database regularly