一、全量備份指令碼
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
Xtrabackup 全量備份指令碼
bin bash 備份檔案的名字為當前主機的ip位址 tar.gz,例如172.16.103.1.tar.gz,且每次備份成功之後都會清空本地的備份目錄。相關目錄 mkdir p xtrabackup mysql back dir xtrabackup mysql backfilename ip a...
xtrabackup備份(全備,增備)
xtrabackup的介紹 mysql冷備 mysqldump mysql熱拷貝都無法實現對資料庫進行增量備份。在實際生產環境中增量備份是非常實用的,如果資料大於50g或100g,儲存空間足夠的情況下,可以每天進行完整備份,如果每天產生的資料量較大,需要定製資料備份策略。例如每週實用完整備份,周一到...
xtrabackup全備 增備 恢復
全備 innobackupex no timestamp defaults file path my.cnf data backup 20141106 增量1 innobackupex no timestamp defaults file path my.cnf incremental increm...