运维笔记Mysql

2023年 9月 12日 45.9k 0

#!/bin/bash
backuppath="/home/ccodrunner/mysqlforbak/BinLogBack"
mysqlpath="/var/lib/mysql"
logpath="/home/ccodrunner/mysqlforbak/log"
logfile="/home/ccodrunner/mysqlforbak/log/backup-1.log"
binFile="/var/lib/mysql/mysql-bin.index"
username="ucds"
password="ucds"

if [ ! -d $backuppath ];then
    mkdir -p $backuppath
fi

if [ ! -d $logpath ];then
    mkdir -p $logpath
fi

echo "" >> $logfile
echo "-------------------" >> $logfile
echo "BACKUP DATE:"$(date +"%Y-%m-%d %H:%M:%S") >> $logfile
echo "-------------------" >> $logfile

/usr/bin/mysqladmin -u$username -p$password flush-logs

counter=`wc -l $binFile | awk '{print $1}'`
nextNum=0
for file in `cat $binFile`
do
    base_file=`basename $file`     
    #basename 用于截取mysql-bin.00000*文件名,去掉./mysql-bin.000005前面的./
    nextNum=`expr $nextNum + 1`
    if [ $nextNum -eq $counter ]
    then
        echo "$base_file skip !" >> $logfile
    else
        dest=$backuppath/$base_file
        if (test -e $dest)
        then
            echo "$base_file exist !" >> $logfile
        else
            cp $mysqlpath/$base_file $backuppath
            echo "$base_file copying" >> $logfile
        fi
    fi
done
echo [PartBack] `date +"%Y%m%d %H:%M:%S"` $nextNum Backup successful ! >> $logfile

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论