Posted in 2016

mysql_backup.sh

#!/bin/bash

file_md5sum=/tmp/mysql_backup.sum
backup_dest=/var/lib/mysql-binlogs/backup

if [ -a $file_md5sum ];
then
        md5sum=`cat $file_md5sum`
fi

index_path=`locate binlog.index`

var=0
while IFS= read -r line;
do
        ((var++))
done < $index_path

current_idx=`sed "${var}q;d" $index_path`
current_md5sum=`md5sum $current_idx | cut -d ' ' -f1`


if [ ! -a $file_md5sum ];
then
        echo $current_md5sum > $file_md5sum
        md5sum=`cat $file_md5sum`
fi

if [[ -a $file_md5sum && ( $md5sum == $current_md5sum ) ]];
then
        echo "Backup is not needed. md5sum of current binlog is the same as in ${file_md5sum}"
else
        backup_file=${backup_dest}/backup_`date +%Y%m%d-%H`.sql
        mysqldump --databases mysqldb > $backup_file
        logger "$backup_file created"
        gzip $backup_file
fi
Advertisements

Author:

Database administrator who loves to work with Oracle software. (Sometimes not)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s