Backuping Full Database



Dump doesn’t work. If you have huge tables with billions of rows your backup process could become a nightmare, mainly if you need to restore it.

This method aims to perform a full backup of a large MySQL database, as Zabbix (any version), focusing on a fast recovery from disaster. So I chose XtraBackup for this task, a backup tool from Percona, which works using the hotcopy mode.

First, you need to download and install XtraBackup:
http://www.percona.com/downloads/XtraBackup/LATEST/

XtraBackup offers a lot of parameters, so this script is intented to be the simplest possible.

Make sure that you’re using InnoDB for history tables at least. In my case, I have a Zabbix Database with 300GB data that takes about 3 hours to do all backup.

Create script /var/lib/xtrabackup/mysql-fullbackup.sh:

https://github.com/xsbr/zabbixzone/blob/master/mysql-fullbackup.sh


#!/bin/bash
#
# mysql-fullbackup.sh
# v0.1 - 20120921
#
# Full Backup for Zabbix w/MySQL
#
# Author: Ricardo Santos (rsantos at gmail.com)
# http://zabbixzone.com
#
MYSQLUSER="YOURUSER"
MYSQLPASS="YOURPASSWORD"


MYSQLCNF="/etc/my.cnf"
MYSQLDIR="/var/lib/mysql"


BASEDIR="/var/lib/xtrabackup"
BKPDIR="${BASEDIR}/lastbackup"
BKPTEMPDIR="${BASEDIR}/tempbackup"


# Memory used in stage 2
USEMEMORY="1GB"


# create basedir
mkdir -p ${BASEDIR}


# remove temporary dir
if [ -d "${BKPTEMPDIR}" ]; then
        rm -rf ${BKPTEMPDIR}
fi


# do backup - stage 1
innobackupex --defaults-file=${MYSQLCNF} --user=${MYSQLUSER} --no-timestamp --password=${MYSQLPASS} ${BKPTEMPDIR}


# do backup - stage 2 (prepare backup for restore)
innobackupex --apply-log --use-memory=${USEMEMORY} ${BKPTEMPDIR}


# backup my.cnf
cp -pf ${MYSQLCNF} ${BKPTEMPDIR}/my.cnf


# keep only the lastbackup
if [ -d "${BKPDIR}" ]; then
      if [ -d "${BKPDIR}.old" ]; then
              rm -rf ${BKPDIR}.old
      fi
      rm -rf ${BKPDIR}
fi
chown -R mysql: ${BKPTEMPDIR}
mv ${BKPTEMPDIR} ${BKPDIR}

Adjust the permissions:

Configure your crontab to backup every day at 04:15am:

So if you need a restore, it’s very simple:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值