Home > Database > Mysql Tutorial > body text

How to incrementally backup MySQL

WBOY
Release: 2023-05-27 10:07:56
forward
1680 people have browsed it

How to incrementally backup MySQL

添加自动任务每小时或者更短时间执行就好了

#!/bin/sh#author RuM#date 2015-07-10BAKDIR=/tmp/mysqlbak
BAKDIR_FULL=$BAKDIR/full
BAKDIR_ADD=$BAKDIR/add
CONF=/etc/my.cnf
passwd=123456
INNOBACKUPEX=/usr/bin/innobackupex
Copy after login

第一次执行会做一次全备跟增备,以后执行都会是增量备份

if [ -f "$INNOBACKUPEX" ]
    then        if  [ -d "$BAKDIR" ]
             then           echo "is ok"             else           mkdir $BAKDIR_FULL -p
           mkdir $BAKDIR_ADD -p
       fi
Copy after login

全备

files=`ls $BAKDIR_FULL`
       if [ -z "$files" ]
           then               $INNOBACKUPEX  --defaults-file=$CONF  --user=root --password=$PASSWD  $BAKDIR_FULL               FULLNAME=$(dir "$BAKDIR_FULL")
               $INNOBACKUPEX  --defaults-file=$CONF  --user=root --password=$PASSWD --incremental-basedir=$BAKDIR_FULL/$FULLNAME/ --incremental $BAKDIR_ADD           else
Copy after login

增量备份

               ADDNAME=$(ls -lt $BAKDIR_ADD |sed -n 2p|awk '{print $9}')
               $INNOBACKUPEX  --defaults-file=$CONF  --user=root --password=$PASSWD --incremental-basedir=$BAKDIR_ADD/$ADDNAME/ --incremental $BAKDIR_ADD       fi   else       echo "is not install innobackupex"fi
Copy after login

The above is the detailed content of How to incrementally backup MySQL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template