Mysqldump back up the database and delete the backup file script 7 days ago

Source: Internet
Author: User
Tags mysql backup

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.