mysqldump implementing a MySQL Backup small script

Source: Internet
Author: User
Tags mysql backup

Collect and test and organize online

#!/bin/bash  #This  is a ShellScript For Auto DB Backup  #Powered  by aspbiz Changed by Jeen#2004-09 Changed 2014-12#Setting  #设置数据库名, Database login name, password, backup path, log path, data file location dbname= "test" dbuser= "root" dbpasswd= "root" backuppath=/root/backup/mysqllogfile=/root/ backup/mysql/bak_$dbname.log#setting end newfile= $BackupPath/"$DBName" _$ (date +%y%m%d). tar.gz  dumpfile= "$DBName" _$ (date +%y%m%d). sqloldfile= $BackupPath/"$DBName" _$ (date +%y%m%d --date = ' 7 days ago ') .tar.gz echo  "-------------------------------------------"  >>   $LogFile  echo $ (date + "%y-%m-%d %h:%m:%s")  >>  $LogFile  echo   "--------------------------"  >>  $LogFile   #Delete  old file if [  -f  $OldFile  ] ; then    rm -f  $OldFile  >>   $LogFile  2>&1    echo  "[$OldFile]delete old file success!"  >>  $LogFile  else    echo  "[$OldFile]no old backup  file! "  >>  $LogFile  fi echo -------------------------- >>  $LogFile  if [ -f  $NewFile  ] ; then     echo  "[$ Newfile]the backup file is exists,can ' t backup! '  >>  $LogFile  else     cd  $BackupPath      if [ -z  $DBPasswd  ] ;then          mysqldump -u  $DBUser  --opt  $DBName  >  $DumpFile     else          mysqldump -u  $DBUser  -p$dbpasswd -- opt  $DBName  >  $DumpFile      fi     tar czvf  $NewFile   $DumpFile  >>  $LogFile  2>& 1     echo  "[$NewFile]backup success!"  >>  $LogFile      rm -rf  $DumpFile  fiecho ------- ------------------------------------" >>  $LogFile



This article is from the "micro-desire for-micro-life" blog, please be sure to keep this source http://vsfor.blog.51cto.com/4165449/1586531

mysqldump implementing a MySQL Backup small script

Related Article

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.