千家信息网

记录mysql 备份脚本

发表于:2025-01-20 作者:千家信息网编辑
千家信息网最后更新 2025年01月20日,下文内容主要给大家带来记录mysql 备份脚本,这里所讲到的知识,与书籍略有不同,都是专业技术人员在与用户接触过程中,总结出来的,具有一定的经验分享价值,希望给广大读者带来帮助。mysql备份脚本,记
千家信息网最后更新 2025年01月20日记录mysql 备份脚本

下文内容主要给大家带来记录mysql 备份脚本,这里所讲到的知识,与书籍略有不同,都是专业技术人员在与用户接触过程中,总结出来的,具有一定的经验分享价值,希望给广大读者带来帮助。

mysql备份脚本,记录一下:

全备:

#!/bin/sh set -x                                                            USER=root PASSWORD=123456time=`date +"%y-%m-%d-%H-%M"`  date >> /data/mysqlbackup/logs/$time'_allbackup.log'  #1 begin Full Backups echo "begin backup--------------------------------" >> /data/mysqlbackup/logs/$time'_allbackup.log'    /usr/bin/innobackupex --defaults-file=/etc/my.cnf  --user=$USER --password=$PASSWORD --use-memory=2GB  --parallel=4  --no-timestamp /data/mysqlbackup/full-$time 2>>/data/mysqlbackup/logs/$time'_allbackup.log' cp /etc/my.cnf /data/mysqlbackup/full-$time/my.cnf.bkecho "end backup----------------------------------" >> /data/mysqlbackup/logs/$time'_allbackup.log' #2 begin compress echo "Begin compress------------------------------" >> /data/mysqlbackup/logs/$time'_allbackup.log'     archivename=full-$timeecho "The archive time is  $time" >> /data/mysqlbackup/logs/$time'_allbackup.log'    tarname=$archivename.tar.gz echo "The tar name is $tarname" >> /data/mysqlbackup/logs/$time'_allbackup.log'cd /data/mysqlbackup/bin/tar -zcvf ./$tarname ./$archivename >> /data/mysqlbackup/logs/$time'_allbackup.log' 2>&1rm -rf /data/mysqlbackup/full/xtrabackup_checkpoints cp /data/mysqlbackup/full-$time/xtrabackup_checkpoints /data/mysqlbackup/full/xtrabackup_checkpoints


#3 Delete Documentfile=/data/mysqlbackup/$tarnameif [[ -e $file ]] then echo "The $tarname file exists.begin to perform delete action" >> /data/mysqlbackup/logs/$time'_allbackup.log' /bin/rm -rf /data/mysqlbackup/$archivename else echo "The file is not exists." >> /data/mysqlbackup/logs/$time'_allbackup.log' fidate >> /data/mysqlbackup/logs/$time'_allbackup.log'find /data/mysqlbackup/*tar.gz -ctime +1|xargs -I '{}' mv {} /data/ftpcd /data/ftpfunction logftp (){ftp -v -n xxx.xxx.xxx.xxx << EOFuser username passwordbinaryhashcd ftp_mysqlpromptput /data/mysqlbackup/*tar.gzls -labyeEOF}logftp >>/data/mysqlbackup/logs/to_ftp.logcd /data/ftpfind /data/ftp/*tar.gz |xargs rm -rf

增量备份:

#!/bin/shset -xUSER=rootPASSWORD=123456time=`date +"%y-%m-%d-%H-%M"`date >>/data/mysqlbackup/logs/$time'_incre.log'#1 begin Incre Backupsecho "begin backup--------------------------------" >> /data/mysqlbackup/logs/$time'_incre.log'   /usr/bin/innobackupex --defaults-file=/etc/my.cnf  --user=$USER --password=$PASSWORD  --incremental --incremental-basedir=/data/mysqlbackup/full --use-memory=2GB --safe-slave-backup --parallel=4 --slave-info   --no-timestamp /data/mysqlbackup/incre-$time  2>>/data/mysqlbackup/logs/$time'_incre.log'cp /etc/my.cnf /data/mysqlbackup/incre-$time/my.cnf.bkecho "end backup----------------------------------" >> /data/mysqlbackup/logs/$time'_incre.log'#2 begin compressecho "Begin compress------------------------------" >> /data/mysqlbackup/logs/$time'_incre.log'    archivename=incre-$timeecho "The archive time is  $time" >> /data/mysqlbackup/logs/$time'_incre.log'    tarname=$archivename.tar.gzecho "The tar name is $tarname" >> /data/mysqlbackup/logs/$time'_incre.log'cd /data/mysqlbackup//bin/tar -zcvf ./$tarname ./$archivename >> /data/mysqlbackup/logs/$time'_incre.log' 2>&1#3 Delete Documentfile=/data/mysqlbackup/$tarnameif [[ -e $file ]]    then        echo "The $tarname file exists.begin to perform delete action"   >> /data/mysqlbackup/logs/$time'_incre.log'        /bin/rm -rf /data/mysqlbackup/$archivename    else        echo "The file is not exists." >> /data/mysqlbackup/logs/$time'_incre.log'    fidate >> /data/mysqlbackup/logs/$time'_incre.log'find /data/mysqlbackup/*tar.gz -ctime +1|xargs -I '{}'  mv  {}  /data/ftpcd /data/ftpfunction logftp (){ftp -v -n xxx.xxx.xxx.xxx << EOFuser username passwordbinaryhashcd ftp_mysqlpromptput /data/mysqlbackup/*tar.gzls -labyeEOF}logftp >>/data/mysqlbackup/logs/to_ftp.logcd /data/ftpfind /data/ftp/*tar.gz |xargs rm -rf

对于以上关于记录mysql 备份脚本,如果大家还有更多需要了解的可以持续关注我们的行业推新,如需获取专业解答,可在官网联系售前售后的,希望该文章可给大家带来一定的知识更新。

0