MYSQL binary log management script _ MySQL

Source: Internet
Author: User
MYSQL binary log management script bitsCN.com
MYSQL binary log management script is used to flush the database every hour to generate new binary logs, back up binary logs to NFS, and compress and store them :#! /Bin/bash # Purpose: manages mysql binary logs, refreshes binary logs every hour, and copies the logs to the nfs server for future recovery and problem analysis! # Author: carl_zhang # Date: # some variables parameters # define database-related information USERNAME = rootPASSWORD = zhang @ 123 HOSTIP = localhostMYSQL =/usr/local/mysql/bin/mysql # set binary log path BIN_LOG_DIR = /data/dbdata # set the binary log backup path BIN_LOG_BACKUP_DIR =/data/binlog_backup # define a constant to skip the last log file COUNT = 0 # define a log file LOGFILE =/data/ binlog_backup/binlog_backup.log # locate the binary log name prefix BINLOG_PREFIX = 'grep "log-bin ="/etc/my. cnf | awk-f' = ''{print $2}'' # compares the list of binary log files with the list of backed up binary log files. If [! -F "$ BIN_LOG_BACKUP_DIR/backup. file "]; thentouch $ BIN_LOG_BACKUP_DIR/backup. filefi # run flush logs $ MYSQL-u $ USERNAME-p $ PASSWORD-h $ HOSTIP-e "flush logs" FILE_LIST = 'comm-23 $ BIN_LOG_DIR/ $ BINLOG_PREFIX.index $ BIN_LOG_BACKUP_DIR/backup. file '# count the number of log files FILE_COUNT = 'comm-23 $ BIN_LOG_DIR/$ BINLOG_PREFIX.index $ BIN_LOG_BACKUP_DIR/backup. file | wc-l '# Program body # start to back up the binary log file for file in $ FILE_LISTdoBINLOG _ NAME = 'basename $ file' let COUNT = $ COUNT + 1if [$ COUNT-eq $ FILE_COUNT]; then # skip the latest binary log file echo "skip the lastest binlog file" >>$ LOGFILEelsecp $ BIN_LOG_DIR/$ BINLOG_NAME $ BIN_LOG_BACKUP_DIR/if [$? -Eq 0]; thenecho "'date-d" today "+ % Y-% m-% d-% H-% M-% s' $ BINLOG_NAME backup success"> $ LOGFILEelseecho "'date -d "today" + % Y-% m-% d-% H-% M-% s' $ BINLOG_NAME backup faild, please check it out ">>$ LOGFILE exit 5fi # compress binary logs and store gzip $ BIN_LOG_BACKUP_DIR/$ BINLOG_NAMEif [$? -Eq 0]; thenecho "'date-d" today "+ % Y-% m-% d-% H-% M-% s' $ BINLOG_NAME gzip success"> $ LOGFILEelseecho "'date -d "today" + % Y-% m-% d-% H-% M-% s' $ BINLOG_NAME gzip faild, please check it out ">>$ LOGFILEexit 5 fiecho. /$ BINLOG_NAME> $ BIN_LOG_BACKUP_DIR/backup. by filefidone, Feihong has no trace bitsCN.com

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.