温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

记录mysql 备份脚本

发布时间:2020-04-23 14:11:58 来源:亿速云 阅读:181 作者:三月 栏目:MySQL数据库

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

mysql备份脚本,记录一下:

全备:

#!/bin/sh 
set -x                                                            
USER=root 
PASSWORD=123456
time=`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.bk
echo "end backup----------------------------------" >> /data/mysqlbackup/logs/$time'_allbackup.log' 

#2 begin compress 
echo "Begin compress------------------------------" >> /data/mysqlbackup/logs/$time'_allbackup.log' 
    archivename=full-$time
echo "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>&1
rm -rf /data/mysqlbackup/full/xtrabackup_checkpoints 
cp /data/mysqlbackup/full-$time/xtrabackup_checkpoints /data/mysqlbackup/full/xtrabackup_checkpoints记录mysql 备份脚本


#3 Delete Document

file=/data/mysqlbackup/$tarname if [[ -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'     fi date >> /data/mysqlbackup/logs/$time'_allbackup.log' find /data/mysqlbackup/*tar.gz -ctime +1|xargs -I '{}'  mv  {}  /data/ftp cd /data/ftp function logftp (){ ftp -v -n xxx.xxx.xxx.xxx << EOF user username password binary hash cd ftp_mysql prompt put /data/mysqlbackup/*tar.gz ls -la bye EOF } logftp >>/data/mysqlbackup/logs/to_ftp.log cd /data/ftp find /data/ftp/*tar.gz |xargs rm -rf

增量备份:

#!/bin/sh
set -x
USER=root
PASSWORD=123456
time=`date +"%y-%m-%d-%H-%M"`
date >>/data/mysqlbackup/logs/$time'_incre.log'

#1 begin Incre Backups
echo "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.bk
echo "end backup----------------------------------" >> /data/mysqlbackup/logs/$time'_incre.log'

#2 begin compress
echo "Begin compress------------------------------" >> /data/mysqlbackup/logs/$time'_incre.log'
    archivename=incre-$time
echo "The archive time is  $time" >> /data/mysqlbackup/logs/$time'_incre.log'
    tarname=$archivename.tar.gz
echo "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 Document
file=/data/mysqlbackup/$tarname
if [[ -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'
    fi

date >> /data/mysqlbackup/logs/$time'_incre.log'

find /data/mysqlbackup/*tar.gz -ctime +1|xargs -I '{}'  mv  {}  /data/ftp

cd /data/ftp

function logftp (){
ftp -v -n xxx.xxx.xxx.xxx << EOF
user username password
binary
hash
cd ftp_mysql
prompt
put /data/mysqlbackup/*tar.gz
ls -la
bye
EOF
}

logftp >>/data/mysqlbackup/logs/to_ftp.log

cd /data/ftp

find /data/ftp/*tar.gz |xargs rm -rf

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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI