千家信息网

xtrabackup一键自动化备份脚本 V2 版【原创】

发表于:2025-01-21 作者:千家信息网编辑
千家信息网最后更新 2025年01月21日,备份文件路径 backdir=/ASSET.innobackupexmysql用来备份用户 user=用户名mysql用户的密码 pass=密码输出的信息保存路径 log
千家信息网最后更新 2025年01月21日xtrabackup一键自动化备份脚本 V2 版【原创】
备份文件路径        backdir=/ASSET.innobackupexmysql用来备份用户   user=用户名mysql用户的密码     pass=密码输出的信息保存路径   logfile=/var/www/html/index.html


[root@localhost /home]# cat /home/innobackupex.v2.sh #!/bin/bashbackdir=/ASSET.innobackupexuser=usernamepass=yourpasswordlogfile=/var/www/html/files/index.htmlweek=`date +%u`mkdir $backdir >> /dev/null 2>&1if [ ! -f  /globalback ]then    cat /dev/null > $logfile    innobackupex --user=$user -password=$pass $backdir    stat=`echo $?`    ls $backdir | tail -n 1 > /globalback    basedir=`cat /globalback`    last=`ls $backdir  | tail -n 1`    echo "

" date >> $logfile if [ $stat -ne 0 ] then echo "备份失败!" >> $logfile exit fi echo "
检测到之前没有做过全局备份,完全备份一次!
" >> $logfile echo -n "本次全局备份使用的二进制日志文件,截止位置信息:" >> $logfile cat $backdir/$basedir/xtrabackup_binlog_info >> $logfile echo -n "
二进制日志文件路径" >> $logfile grep "^log-bin" /etc/my.cnf >> $logfile echo "
本次数据库备份文件份的lsn信息如下:
开始位置:" >> $logfile grep from_lsn $backdir/$last/xtrabackup_checkpoints >> $logfile echo "
结束位置: " >> $logfile grep to_lsn $backdir/$last/xtrabackup_checkpoints >> $logfile echo "
备份文件的大小、路径" >> $logfile du -sh $backdir/$last/ >> $logfile echo "
" >> $logfile exitfiif [ $week -eq 5 ]then innobackupex --user=$user -password=$pass $backdir stat=`echo $?` incre=`ls $backdir | tail -n 1` if [ $stat -ne 0 ] then echo "

" >> $logfile date >> $logfile echo "
备份失败!" >> $logfile exit fi ls $backdir | tail -n 1 > /globalback basedir=`cat /globalback` echo "

↓↓↓↓↓↓↓↓↓↓↓ 全局备份分割线 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

" >> $logfile date >> $logfile echo "
全局备份
" >> $logfile echo "数据备份的位置 $backdir/$basedir
" >> $logfile echo -n "本次全局备份使用的二进制日志文件,截止位置信息:" >> $logfile cat $backdir/$basedir/xtrabackup_binlog_info >> $logfile echo -n "
二进制日志文件路径" >> $logfile grep "^log-bin" /etc/my.cnf >> $logfile echo "
本次数据库备份文件份的lsn信息如下:
开始位置:" >> $logfile grep from_lsn $backdir/$basedir/xtrabackup_checkpoints >> $logfile echo "
结束位置: " >> $logfile grep to_lsn $backdir/$basedir/xtrabackup_checkpoints >> $logfile echo "
备份文件的大小、路径" >> $logfile du -sh $backdir/$basedir >> $logfile echo "
" >> $logfileelse basedir=`cat /globalback` last=`ls $backdir | tail -n 1` innobackupex --user=$user -password=$pass --incremental $backdir --incremental-basedir=$backdir/$last stat=`echo $?` incre=`ls $backdir | tail -n 1` echo "

" >> $logfile date >> $logfile if [ $stat -ne 0 ] then echo "备份失败!" >> $logfile exit fi echo "
增量备份
" >> $logfile echo "基 本库是 $backdir/$basedir
" >> $logfile echo "上次备份是 $backdir/$last
" >> $logfile echo "本次备份是 $backdir/$incre
" >> $logfile echo -n "上次全局备份使用的二进制日志文件,截止位置信息:" >> $logfile cat $backdir/$basedir/xtrabackup_binlog_info >> $logfile echo -n "
本次增量备份使用的二进制日志文件,截止位置信息:" >> $logfile cat $backdir/$incre/xtrabackup_binlog_info >> $logfile echo -n "
二进制日志文件路径" >> $logfile grep "^log-bin" /etc/my.cnf >> $logfile echo "
本次增量数据库备份文件份的lsn信息如下:
开始位置:" >> $logfile grep from_lsn $backdir/$incre/xtrabackup_checkpoints >> $logfile echo "
结束位置: " >> $logfile grep to_lsn $backdir/$incre/xtrabackup_checkpoints >> $logfile echo "
增量备份文件的大小、路径" >> $logfile du -sh $backdir/$incre >> $logfile echo "
" >> $logfilefi







.

0