MySQL restores with Xtrabackup and Binlog backups based on point-in-time

Source: Internet
Author: User

#!/bin/bash

#定义变量
mysql_host=192.168.56.21
Mysql_username=root
mysql_port=3306
Mysql_passpwd=oracle
Mysql_sock=/data/mysql/3306/tmp/3306.sock
Mysql_cnf=/data/mysql/3306/my3306.cnf
Mysql_datadir= ' cat ${mysql_cnf}|grep datadir|awk-f ' = ' {print $} '
#MYSQL_BACKUPDIR =$1
#MYSQL_DATATIME =$2

mysql_backupdir=/data/backup/2017-04-26_01-03-49
Mysql_datatime= "2017-04-26 01:05:22"
Mysql_posdir=${mysql_backupdir}/xtrabackup_info

#获取binlog position
Mysql_pos= ' cat ${mysql_posdir} |grep position |awk-f "," ' {print $} ' | Awk-f "" ' {print $} '

#恢复全备
Innobackupex--defaults-file=${mysql_cnf}--user=${mysql_username}--password=${mysql_passpwd}--copy-back ${MYSQL_ Backupdir}

Modify Data Directory DataDir permissions
Chown-r Mysql:mysql ${mysql_datadir}

#启动MySQL
Mysqld--DEFAULTS-FILE=${MYSQL_CNF} &

#利用mysqlbinlog基因时间点恢复


Mysqlbinlog--start-position=${mysql_pos}--stop-datetime= "${mysql_datatime}" |mysql-s ${MYSQL_SOCK}-u${MYSQL_ USERNAME}-p${mysql_passpwd}



######################## the following content please ignore
#全备
# Innobackupex--DEFAULTS-FILE=/DATA/MYSQL/3306/MY3306.CNF--user=root--password=oracle/data/backup


Mysqlbinlog--start-position=120--stop-datetime= ' 2017-04-26 1:05:22 '/data/mysql/3306/logs/mysql-bin.000043/data/ mysql/3306/logs/mysql-bin.000044/data/mysql/3306/logs/mysql-bin.000045/data/mysql/3306/logs/mysql-bin.000046 | Mysql-s/data/mysql/3306/tmp/3306.sock-uroot-poracle

Mysqlbinlog--start-position=${mysql_pos}--stop-datetime= "${mysql_datatime}"/data/mysql/3306/logs/ mysql-bin.000043/data/mysql/3306/logs/mysql-bin.000044/data/mysql/3306/logs/mysql-bin.000045/data/mysql/3306/ logs/mysql-bin.000046 |mysql-s ${mysql_sock}-u${mysql_username}-p${mysql_passpwd}




rm-rf/data/mysql/3306/data/*
Pkill MySQL

MySQL restores with Xtrabackup and Binlog backups based on point-in-time

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.