In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "mysql backup script sharing". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
#! / bin/bash# Purpose: MySQL backups # # This script does a full or incremental backup # # The full is done via mysqldump## The incremental is done via flush-logs option # # with mysqladmin## The script is also setup to email if a # # failure occurs # Assumptions: # # 1. Database is in Binary Update Log mode # # 2. The variables are set correctly # # # # Usage:mysql_backup [full | incremental] # # INITILIAZE VARIABLES # # # # Set the mode Full | incremental# parameter is passed inMODE=$1# set the username to connect to mysql for the backupMYSQLUSER=backup# set the password to connect to mysql for the backupMYSQLUSERPW=password# set the Binary Update Logs PathBINLOGPATH=/mysql/logs/emds01/mysql# Set the binary Update Logs nameBINLOGNAME=viper2-bin# set the backup pathBACKUPPATH=/export/home/mysql/backups# set the email address for errors to be emailed toEMAIL_ADDR=shenandoah.speers@cicadacorp.com# set the log fileLOGFILE=$BACKUPPATH/logs/$HOSTNAME_$RUNDATE.log# set the error log fileLOGERR=$BACKUPPATH/logs/ERRORS_$HOSTNAME_$RUNDATE.log# set the number of days to Keep the backupsDAYSTOKEEP=5# set Run dateRUNDATE= `date +% Y% m% d% s` # set hostnameHOSTNAME= `uname-n` # GLOBAL FUNCTIONS # # copyBinlogs () {# copy binlogs to backup direcho "Copying binlogs" for FILE in `cat $BINLOGPATH/$ BINLOGNAME.index`doSFILE = (${FILE/*//}) echo "- binlog $SFILE" cp $FILE $BACKUPPATH/$SFILE_$RUNDATEgzip $BACKUPPATH/$SFILE_$RUNDATEdone} removeOldBackups () {# remove old backupsecho "Removing old backups greater then $DAYSTOKEEP days" find $BACKUPPATH-type f-mtime + $DAYSTOKEEP-name * .gz-print-exec rm {} Find $BACKUPPATH/logs-type f-mtime + $DAYSTOKEEP-name * .log-print-exec rm {} } startlog () {# IO redirection for loggingtouch $LOGFILEexec 6 > & 1 # Link file descriptor # 6 with stdout.# Saves stdout.exec > $LOGFILE # stdout replaced with file $LOGFILE.touch $LOGERRexec 7 > & 2 # Link file descriptor # 7 with stderr.# Saves stderr.exec 2 > $LOGERR # stderr replaced with file $LOGERR.} stoplog () {# Clean up IO redirectionexec 1 > & 6 > & # Restore stdout and close file descriptor # 6.exec 1 > & 7 > &- # Restore stdout and close file descriptor # 7.} # START OF MAIN # # case "$MODE" in'full') # Daily backup#-copy all bin logs to backup directory#-remove old backups and logsstartlog Echo "Start Mysql Daily backup `date +% c`" mysqldump-u $MYSQLUSER-p$MYSQLUSERPW-- single-transaction-- flush-logs-- master-data=2--all-databases-- delete-master-logs | gzip > $BACKUPPATH/$HOSTNAME_full_$RUNDATE.sql.gzcopyBinlogs;removeOldBackups;echo "Finish Mysql Daily backup `date +% c`" stoplog;email;;;'incremental') # hourly backup#-flush logs#-copy all bin logs to backup directory if not already doneecho "Start Mysql hourly backup `date +% c`" startlog;mysqladmin-u $MYSQLUSER-p$MYSQLUSERPW flush-logscopyBinlogs Echo "Finish Mysql hourly backup `date +% c`" stoplog;;;*) echo "Usage: mysql_backup [full | incremental]" Esac# email any errors encounteredif [- s "$LOGERR"] thencat "$LOGERR" | mail-s "ERRORS REPORTED: MySQL Backup error Log for $HOSTNAME-$RUNDATE" $EMAIL_ADDRcat "$LOGFILE" | mail-s "MySQL Backup Log for $HOSTNAME-$RUNDATE" $EMAIL_ADDRSTATUS=1elseSTATUS=0fiexit $STATUS### # END OF MAIN # so much for "backup script sharing for mysql" Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.