mysql5.7_xtraBackup_备份脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql5.7_xtraBackup_备份脚本相关的知识,希望对你有一定的参考价值。
# 备份脚本XtraBackup.sh:#!/bin/bash
# filename : XtraBackup.sh
# Author : 00000
day=date +%w
dt=date +%Y%m%d
lastday=date -d ‘1 days ago‘ +%Y%m%d
user=backupuser
log=backuplog.date +%Y%m%d
case $day in
0)
# Monday Relatively Sunday‘s incremental backup
sudo innobackupex --defaults-file=/etc/my.cnf --login-path=$user --no-timestamp --incremental --backup --incremental-basedir=/data/backup/xtrainc$lastday /data/backup/xtrainc$dt > /tmp/$log 2>&1
;;
1)
# Sunday Full backup
sudo find /data/backup/ -name "xtra_" -mtime +6 -exec rm -rf {} ;
sudo innobackupex --defaults-file=/etc/my.cnf --login-path=$user --no-timestamp --backup /data/backup/xtrabase$dt > /tmp/$log 2>&1
;;
2)
# Saturday Compared with Friday‘s incremental backup
sudo innobackupex --defaults-file=/etc/my.cnf --login-path=$user --no-timestamp --incremental --backup --incremental-basedir=/data/backup/xtrabase$lastday /data/backup/xtrainc$dt > /tmp/$log 2>&1
;;
3)
# Tuesday Compared with Monday‘s incremental backup
sudo innobackupex --defaults-file=/etc/my.cnf --login-path=$user --no-timestamp --incremental --backup --incremental-basedir=/data/backup/xtrainc$lastday /data/backup/xtrainc$dt > /tmp/$log 2>&1
;;
4)
# Friday Compared with Thursday‘s incremental backup
sudo innobackupex --defaults-file=/etc/my.cnf --login-path=$user --no-timestamp --incremental --backup --incremental-basedir=/data/backup/xtrainc$lastday /data/backup/xtrainc$dt > /tmp/$log 2>&1
;;
5)
# Wednesday Full backup
sudo find /data/backup/ -name "xtra_" -mtime +6 -exec rm -rf {} ;
sudo innobackupex --defaults-file=/etc/my.cnf --login-path=$user --no-timestamp --backup /data/backup/xtrabase$dt > /tmp/$log 2>&1
;;
6)
# Thursday Relatively Wednesday‘s incremental backup
sudo innobackupex --defaults-file=/etc/my.cnf --login-path=$user --no-timestamp --incremental --backup --incremental-basedir=/data/backup/xtrabase$lastday /data/backup/xtrainc$dt > /tmp/$log 2>&1
;;
esac
sudo find /tmp -mtime +6 -type f -name ‘backuplog.*‘ -exec rm -rf {} ;
以上是关于mysql5.7_xtraBackup_备份脚本的主要内容,如果未能解决你的问题,请参考以下文章
MySQL5.6下使用xtrabackup部分备份恢复到MySQL5.7
Mysql/Mariadb备份(xtrabackup)还原实战
Xtrabackup2.4.8备份还原恢复Mysql5.7.19实操
MySQL5.7.18 备份Mysqldump,mysqlpump,xtrabackup,innobackupex 全量,增量备份,数据导入导出