monicazhang 发表于 2017-9-3 10:09:49

Zabbix数据库的完全备份方案

背景介绍:Dump doesn’t work. If you have huge tableswith billions of rows your backup process could become a nightmare, mainly ifyou need to restore it.This method aims to perform a full backupof a large MySQL database, as Zabbix (any version), focusing on a fast recoveryfrom 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 installXtraBackup:downloads/XtraBackup/LATEST/XtraBackup offers a lot of parameters, sothis script is intented to be the simplest possible.Make sure that you’re using InnoDB forhistory tables at least. In my case, I have a Zabbix Database with 300GB datathat takes about 3 hours to do all backup.Create script /var/lib/xtrabackup/mysql-fullbackup.sh:xsbr/zabbixzone/blob/master/mysql-fullbackup.sh备份脚本:#!/bin/bash## mysql-fullbackup.sh# v0.1 - 20120921## Full Backup for Zabbix w/MySQL## Author: Ricardo Santos ( )# h #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 2USEMEMORY="1GB"
# create basedirmkdir -p ${BASEDIR}
# remove temporary dirif [ -d "${BKPTEMPDIR}" ]; thenrm -rf ${BKPTEMPDIR}fi
# do backup - stage 1innobackupex --defaults-file=${MYSQLCNF}--user=${MYSQLUSER} --no-timestamp --password=${MYSQLPASS} ${BKPTEMPDIR}
# do backup - stage 2 (prepare backup forrestore)innobackupex --apply-log--use-memory=${USEMEMORY} ${BKPTEMPDIR}
# backup my.cnfcp -pf ${MYSQLCNF} ${BKPTEMPDIR}/my.cnf
# keep only the lastbackupif [ -d "${BKPDIR}" ]; thenif [ -d "${BKPDIR}.old" ]; thenrm -rf ${BKPDIR}.oldfirm -rf ${BKPDIR}fichown -R mysql: ${BKPTEMPDIR}mv ${BKPTEMPDIR} ${BKPDIR}赋予权限:Adjust the permissions:chmod +x/var/lib/xtrabackup/mysql-fullbackup.sh配置定时任务:Configure your crontab to backup every dayat 04:15am:15 04 * * * root/var/lib/xtrabackup/mysql-fullbackup.sh >/var/lib/xtrabackup/lastrun.log2>&1如何进行恢复:So if you need a restore, it’s very simple:# stop MySQLservice mysql stop
# move backuped filescd /var/libmv mysql mysqlcrashedmv xtrabackup/lastbackup mysql
# start MySQLservice mysql start原创: Ricardo Santos
页: [1]
查看完整版本: Zabbix数据库的完全备份方案