一、全量备份脚本
1.全量备份脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#!/bin/bash
#Description:xtrabackup complete
#Author:created by michael
#2017-08-07 v0.1
#
USER=root
PASSWD=123456
BACKUP_DIR=
/backup/mysql/complete
DATE=$(
date
+
"%F_%T"
)
[[ -d $BACKUP_DIR ]] ||
mkdir
$DATE_DIR
innobackupex --user=$USER --password=$PASSWD $BACKUP_DIR &>
/tmp/mysql/
"$DATE"
.txt
egrep
".* Backup created in directory.*"
/tmp/mysql/
"$DATE"
.txt >> $BACKUP_DIR
/complete
.info
rm
-rf
/tmp/mysql/
"$DATE"
.txt
|
2.启动crond以及开机自启动crond
1
2
|
systemctl start crond
systemctl
enable
crond
|
3.授予执行权限
1
|
chmod
755
/root/script/backup_complete
.sh
|
4.每周六的凌晨4点整定时执行全量备份
1
2
3
4
|
[root@michaelos complete]
# crontab -e
crontab
: installing new
crontab
[root@michaelos complete]
# crontab -l
0 4 * * 6
/root/script/backup_complete
.sh
|
二、增量备份脚本
1.增量备份脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@michaelos script]
# cat backup_increment.sh
#!/bin/bash
#Description: mysql backup incremention
#Author:michael
#2017-08-07 v0.1
#
USER=root
PASSWORD=123456
BACKUP_DIR=
/backup/mysql/increment
DATE=$(
date
+
"%F_$T"
)
BASE_DIR=$(
tail
-1
/backup/mysql/complete/complete
.info |
cut
-d\' -f2)
[[ -d $BACKUP_DIR ]] ||
mkdir
$BACKUP_DIR
innobackupex --user=$USER --password=$PASSWORD --incremental $BACKUP_DIR --incremental-basedir=$BASE_DIR &>
/tmp/mysql/
"$DATE"
.txt
egrep
".*Backup created in directory.*"
/tmp/mysql/
"$DATE"
.txt >> $BACKUP_DIR
/backup
.info
rm
-rf
/tmp/mysql/
"$DATE"
.txt
|
2.授予执行权限
1
|
chmod
755 backup_increment.sh
|
3.每周二、四、日的凌晨2点执行增量备份
1
2
3
|
[root@michaelos script]
# crontab -l
0 4 * * 6
/root/script/backup_complete
.sh
0 2 * * 2,4,7
/root/script/backup_increment
.sh
|
本文转自 PowerMichael 51CTO博客,原文链接:http://blog.51cto.com/huwho/1954307,如需转载请自行联系原作者