Create a backup script in the/server/scripts/directory mysql_backup.sh
#!/bin/bash# ---------------------------# filename: mysql_backup.sh# revision: 1.4# date: 2016/05/09# Author: ywliyq# Email: [email protected]# 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 that executes this script 2 o'clock in the morning every day
# CRONTAB-E
###### MySQL backup at 2016/05/09 by Ywliyq ######
0 2 * * */bin/sh/server/scripts/mysql_backup.sh >/dev/null
This article is from the "Linux operations self-cultivation" blog, please be sure to keep this source http://ywliyq.blog.51cto.com/11433965/1771371
Mysqldump back up the database and delete the backup file script 7 days ago