-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathmysql-fullbackup.sh
49 lines (40 loc) · 1.03 KB
/
mysql-fullbackup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/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}