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.
扩展阅读: