MySQL backup script

Source: Internet
Author: User

#!/bin/bash# backs up all MySQL databases to full-Library full-scale backup?use mysqldump# defines the username and password for backing up the database user=rootuserpwd=s2# Define Backup database name # Get all database list Firstdbnames="$ (mysql-uroot-p$userpwd-hlocalhost-bse ' show databases ')"# define backup directory Databackupdir=/media/2a76a963-92b1-4f74-a2c8-b7dc7a898331/mysqlbackup# define the message body file Emailfile= $dataBackupDir/log/email.txt# Define email address Email=[email protected]# define BACKUP log file logfile= $dataBackupDir/log/mysqlbackup.log# DATE=`Date-I ' DATE=`Date-D" Now"+%y%m%d 'Echo`Date-D" Now" "+%y-%m-%d%h:%m:%s"'; $eMailFile forDbNameinch${dbnames[*]} Do# define backup file name DumpFile= $dataBackupDir/db/$dbName-$DATE. sql.gzEcho$dumpFile >>$eMailFile # To back up the database using mysqldump, set the parameters as appropriate mysqldump-u$user-p$userpwd $dbName--skip-lock-tables |gzip>$dumpFile Doneif[[ $? ==0]]; ThenEcho "DataBase Backup success!">>$eMailFileElseEcho "DataBase Backup fail!">>$emailFilefi# Write log fileEcho "================================">>$logFileCat$eMailFile >>$logFileEcho$dumpFile >>$logFile # Send email Notifications #Cat$eMailFile | Mail-s"MySQL Backup"$eMail

MySQL backup script

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.