重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

记录mysql备份脚本

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

创新互联从2013年成立,是专业互联网技术服务公司,拥有项目网站设计制作、成都网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元子洲做网站,已为上家服务,为子洲各地企业和个人服务,联系电话:13518219792

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 备份脚本,如果大家还有更多需要了解的可以持续关注我们创新互联的行业推新,如需获取专业解答,可在官网联系售前售后的,希望该文章可给大家带来一定的知识更新。


网页题目:记录mysql备份脚本
本文来源:http://cqcxhl.cn/article/jjjjoe.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP