xtrabackup一键自动化备份脚本V2版【原创】
备份文件路径 backdir=/ASSET.innobackupex MySQL用来备份用户 user=用户名 mysql用户的密码 pass=密码 输出的信息保存路径 logfile=/var/www/html/index.html
创新互联建站认为,企业网站是要赋予品质、思维、人性,深入到用户内心的细腻情感,才能真正称得上企业网站。创新互联建站根据每位用户内心最深的需求网站建设服务,坚实的设计执行是品牌长期视觉塑造的重要支持。
[root@localhost /home]# cat /home/innobackupex.v2.sh #!/bin/bash backdir=/ASSET.innobackupex user=username pass=yourpassword logfile=/var/www/html/files/index.html week=`date +%u` mkdir $backdir >> /dev/null 2>&1 if [ ! -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 exit fi if [ $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 "
" >> $logfile else 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 "
" >> $logfile fi
.
文章名称:xtrabackup一键自动化备份脚本V2版【原创】
网页链接:http://scyingshan.cn/article/jggijh.html