1、全量备份

[root@localhost lib]##innobackupex --defaults-file=$defaults_file --user=$mysql_username --password=$mysql_password --stream=tar $mysql_backup_dir | gzip - > $timeStart.bz.tar.gz 2> "$logfile"

备份目录/var/lib/mysqlsource,
如果下面要恢复,解压bz文件至该目录下面。

2、恢复准备

[root@localhost lib]#mkdir mysql
[root@localhost lib]# innobackupex --apply-log /var/lib/mysqlsource/
180712 15:22:51 innobackupex: Starting the apply-log operation IMPORTANT: Please check that the apply-log run completes successfully.
At the end of a successful apply-log run innobackupex
prints "completed OK!". innobackupex version 2.4.5 based on MySQL server 5.7.13 Linux (x86_64) (revision id: e41c0be)
xtrabackup: cd to /var/lib/mysqlsource/
xtrabackup: This target seems to be not prepared yet.
InnoDB: Number of pools: 1
xtrabackup: xtrabackup_logfile detected: size=8388608, start_lsn=(117069890525)
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:12M:autoextend
xtrabackup: innodb_log_group_home_dir = .
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 8388608
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:12M:autoextend
xtrabackup: innodb_log_group_home_dir = .
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 8388608
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: PUNCH HOLE support available
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Uses event mutexes
InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
InnoDB: Compressed tables use zlib 1.2.7
InnoDB: Number of pools: 1
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, total size = 100M, instances = 1, chunk size = 100M
InnoDB: Completed initialization of buffer pool
InnoDB: page_cleaner coordinator priority: -20
InnoDB: Highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 117069890525
InnoDB: Doing recovery: scanned up to log sequence number 117070116070 (3%)
InnoDB: Database was not shutdown normally!
InnoDB: Starting crash recovery.
InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percent: 0 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
InnoDB: Apply batch completed
InnoDB: xtrabackup: Last MySQL binlog file position 466896958, file name mysql-bin.000360
InnoDB: Creating shared tablespace for temporary tables
InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
InnoDB: File './ibtmp1' size is now 12 MB.
InnoDB: 96 redo rollback segment(s) found. 1 redo rollback segment(s) are active.
InnoDB: 32 non-redo rollback segment(s) are active.
InnoDB: page_cleaner: 1000ms intended loop took 9422ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.)
InnoDB: 5.7.13 started; log sequence number 117070116070
InnoDB: xtrabackup: Last MySQL binlog file position 466896958, file name mysql-bin.000360 xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 117070116783
InnoDB: Number of pools: 1
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:12M:autoextend
xtrabackup: innodb_log_group_home_dir = .
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 268435456
InnoDB: PUNCH HOLE support available
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Uses event mutexes
InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
InnoDB: Compressed tables use zlib 1.2.7
InnoDB: Number of pools: 1
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, total size = 100M, instances = 1, chunk size = 100M
InnoDB: Completed initialization of buffer pool
InnoDB: page_cleaner coordinator priority: -20
InnoDB: Setting log file ./ib_logfile101 size to 256 MB
InnoDB: Progress in MB:
100 200
InnoDB: Setting log file ./ib_logfile1 size to 256 MB
InnoDB: Progress in MB:
100 200
InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
InnoDB: New log files created, LSN=117070116783
InnoDB: Highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 117070116876
InnoDB: Doing recovery: scanned up to log sequence number 117070116885 (0%)
InnoDB: Doing recovery: scanned up to log sequence number 117070116885 (0%)
InnoDB: Database was not shutdown normally!
InnoDB: Starting crash recovery.
InnoDB: xtrabackup: Last MySQL binlog file position 466896958, file name mysql-bin.000360
InnoDB: Removed temporary tablespace data file: "ibtmp1"
InnoDB: Creating shared tablespace for temporary tables
InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
InnoDB: File './ibtmp1' size is now 12 MB.
InnoDB: 96 redo rollback segment(s) found. 1 redo rollback segment(s) are active.
InnoDB: 32 non-redo rollback segment(s) are active.
InnoDB: page_cleaner: 1000ms intended loop took 6645ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.)
InnoDB: 5.7.13 started; log sequence number 117070116885
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 117070117601
180712 15:23:12 completed OK!

3、开始恢复

[root@localhost lib]# innobackupex  --defaults-file=/etc/my.cnf --copy-back --rsync /var/lib/mysqlsource
180712 15:23:50 innobackupex: Starting the copy-back operation IMPORTANT: Please check that the copy-back run completes successfully.
At the end of a successful copy-back run innobackupex
prints "completed OK!". innobackupex version 2.4.5 based on MySQL server 5.7.13 Linux (x86_64) (revision id: e41c0be)
180712 15:23:50 [01] Copying ib_logfile0 to /var/lib/mysql/ib_logfile0
180712 15:23:52 [01] ...done
180712 15:23:53 [01] Copying ib_logfile1 to /var/lib/mysql/ib_logfile1
180712 15:23:55 [01] ...done
180712 15:23:55 [01] Copying ibdata1 to /var/lib/mysql/ibdata1
180712 15:23:59 [01] ...done
180712 15:23:59 [01] Copying ./2018712013001.bz.tar.gz to /var/lib/mysql/2018712013001.bz.tar.gz
180712 15:25:02 [01] ...done
180712 15:25:03 [01] Copying ./vehicle_gps/tb_bas_gps_vendor.ibd to /var/lib/mysql/vehicle_gps/tb_bas_gps_vendor.ibd
180712 15:25:03 [01] ...done
180712 15:25:03 [01] Copying ./vehicle_gps/tb_gps_info.ibd to /var/lib/mysql/vehicle_gps/tb_gps_info.ibd
180712 15:25:03 [01] ...done
180712 15:25:03 [01] Copying ./vehicle_gps/tb_gps_alarm_info.ibd to /var/lib/mysql/vehicle_gps/tb_gps_alarm_info.ibd
180712 15:25:03 [01] ...done
180712 15:40:55 [01] ...done
180712 15:40:55 [01] Copying ./ib_buffer_pool to /var/lib/mysql/ib_buffer_pool
180712 15:40:55 [01] ...done
180712 15:40:55 [01] Copying ./xtrabackup_info to /var/lib/mysql/xtrabackup_info
180712 15:40:55 [01] ...done
180712 15:40:55 [01] Copying ./xtrabackup_binlog_pos_innodb to /var/lib/mysql/xtrabackup_binlog_pos_innodb
180712 15:40:55 [01] ...done
180712 15:40:55 [01] Copying ./ibtmp1 to /var/lib/mysql/ibtmp1
180712 15:40:55 [01] ...done
180712 15:40:55 completed OK!

4、更改mysql目录属性

[root@localhost lib]# chown -R mysql.mysql mysql

5、启动mysql

[root@localhost mysql]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@localhost mysql]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2018-07-12 15:42:17 CST; 10s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 127987 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 127908 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 127995 (mysqld)
CGroup: /system.slice/mysqld.service
└─127995 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid Jul 12 15:41:40 localhost.localdomain systemd[1]: Starting MySQL Server...
Jul 12 15:42:17 localhost.localdomain systemd[1]: Started MySQL Server.

扩展阅读:

xtrabackup 全量备份、恢复数据的更多相关文章

  1. xtrabackup全量备份和增(差)量备份

    xtrabackup全量备份和增(差)量备份 1.xtrabackup全量备份和恢复 1)备份: innobackupex --default-file=/PATH/TO/DEFAULT --host ...

  2. MySQL innobackupex全量备份恢复

    转自 http://blog.itpub.net/27099995/viewspace-1295099/ 先简单介绍一下这个工具:innobackupexinnobackupex比xtarbackup ...

  3. 阿里RDS数据库 全量备份恢复到本地MYSQL

    阿里RDS数据库 全量备份恢复到本地MYSQL   1.首先下载RDS的全量备份 下载完成后上传到服务器备用   2.安装MySQL 5.6 首先删除机上其他的MySQL版本 检查系统是否安装其他版本 ...

  4. 15、xtrabackup 全量备份

    xtrabackup 全量备份与恢复 安装 yum install https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2. ...

  5. xtrabakcup基本用法 安装、全量备份恢复、增量备份恢复

    xtrabackup备份原理以及工作流程 备份流程日志分析:1.##读取mysql配置文件2.## 扫描innodb日志lsn并复制inndodb系统表空间3.## 缓冲写出到数据文件并锁表4.## ...

  6. xtrabackup全量备份+binlog基于时间点恢复

    1.通过xtrabackup的备份恢复数据库. 2.找到start-position和binlog名称 cat xtrabackup_info 3.导出mysqlbinlog为sql文件,并确定恢复的 ...

  7. Xtrabackup 全量备份脚本

    #!/bin/bash #备份文件的名字为当前主机的IP地址+tar.gz,例如172.16.103.1.tar.gz,且每次备份成功之后都会清空本地的备份目录. #相关目录 mkdir -p /xt ...

  8. Xtrabackup全量备份与恢复mysql数据库

    一.Xtrabackup简单概述: Percona  Xtrabackup是开源免费的MySQL数据库热备份软件,它能对InnoDB和XtraDB存储引擎的数据库非阻塞地备份(对于MyISAM的备份同 ...

  9. 【运维实战】利用tar -g 实现简单全量备份和增量备份(带演示)

    备份产生 全量备份指完全备份,增量备份指针对上次至今的修改进行备份.linux提供tar -g可实现备份功能. 第一次运行 tar -g 备份存放目录/snapshot -czvf  备份存放目录/备 ...

随机推荐

  1. WPF MvvmLight简单实例(1) 页面导航

    原文:WPF MvvmLight简单实例(1) 页面导航 实现了那些功能,先看看截图: 操作描述: 在程序运行后,点击“Load”按钮,页面会加载PageOne,点击PageOne页面中的“Next” ...

  2. c#通过datatable导出excel和word

    /// <summary> /// 导出datatable到word /// </summary> /// <param name="dg">需 ...

  3. Fabric-Crashlytics-Android 注意点

    Fabric-Crashlytics-Android 注意点 非发布版本关闭Fabirc 官方文档中有这方面的介绍,有助于在开发过程中,提高编译速度和避免上报不必要的Crash 链接 一共两步 第一步 ...

  4. Win8Metro(C#)数字图像处理--2.3图像反色

    原文:Win8Metro(C#)数字图像处理--2.3图像反色 [函数名称] 图像反色函数ContraryProcess(WriteableBitmap src) [算法说明]     反色公式如下: ...

  5. 微信小程序把玩(十九)radio组件

    原文:微信小程序把玩(十九)radio组件 radio组件为单选组件与radio-group组合使用,使用方式和checkbox没啥区别 主要属性: wxml <!--设置监听器,当点击radi ...

  6. 零元学Expression Blend 4 - Chapter 42 五分钟快速完成扇形变圆形动画

    原文:零元学Expression Blend 4 - Chapter 42 五分钟快速完成扇形变圆形动画 零元学Expression Blend 4 - Chapter 42 五分钟快速完成扇形变圆形 ...

  7. 使用内核对象Mutex可以防止同一个进程运行两次

    用互斥法实现防止程序重复运行,使用内核对象Mutex可以防止同一个进程运行两次.注意:是名称相同的进程,而不是exe,因为exe程序可以改名. using System.Threading; publ ...

  8. Delphi在系统菜单中添加菜单项

    unit dy219; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  9. ssh超时时间设置(设置ClientAliveInterval),附SSH超详细参数

    作者: daodaoliang 版本: V 0.0.1 日期: 2016年12月29日 0x00 OpenSSH 简介 OpenSSH是采用SSH协议实现的重要的远程连接工具,它对所有的数据进行加密以 ...

  10. Codility---Nesting

    Task description A string S consisting of N characters is called properly nested if: S is empty; S h ...