MySQL backup script

Source: Internet
Author: User
Tags mysql backup

#!/bin/bash
BACKUPPATH=/DATA/BACKUP/TESTBK #备份路径
mysql_bk_dir= $BackupPath/mysql_bk_dir
logfile= $BackupPath/backuplog
Passwd=admin #mysql密码
######################################
# define MySQL Variables
######################################
newfile= "$Mysql _bk_dir"/test$ (date +%y%m%d). tar.gz
dumpfile= "$Mysql _bk_dir"/test$ (date +%y%m%d). sql
oldfile= "$Mysql _bk_dir"/test$ (date +%y%m%d--date= ' 5 days ago '). tar.gz
######################################
#mysql Backup proccess
######################################
echo "------------------------------------" >> $LogFile
echo $ (date + "%y-%m-%d%h:%m:%s") >> $LogFile
echo "------------------------------------" >> $LogFile
#Dlete Old File
If [-F $OldFile]
Then
Rm-f $OldFile >> $LogFile 2>&1
echo "[$OldFile] Delete old File Success" >> $LogFile
Else
echo "[$OldFile] Delete old Backup File" >> $LogFile
Fi
If [-F $NewFile]
Then
echo "[$NewFile] The backup File is Exists,can ' t backup >> $LogFile
Else
CD $Mysql _bk_dir
/USR/LOCAL/MYSQL/BIN/MYSQLDUMP-UROOT-P$PASSWD--opt--database Test > $DumpFile
Tar czf $NewFile ccv$ (date +%y%m%d). SQL >> $LogFile 2>&1
echo "[$NewFile] Backup success >> $LogFile
/BIN/RM-RF $DumpFile
Fi

This article is from the "Target: India" blog, please be sure to keep this source http://shunzi115.blog.51cto.com/5184443/1826164

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.