<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
mysql版本:8.0.28
xtrabackup版本:8.0.28
下載地址:Download Percona XtraBackup 8.0
[root@myoracle ~]# tar -zxvf percona-xtrabackup-8.0.28-20-Linux-x86_64.glibc2.17.tar.gz [root@myoracle ~]# mv percona-xtrabackup-8.0.28-20-Linux-x86_64.glibc2.17 /usr/local/xtrabackup
xtrabackup備份時報錯: [Xtrabackup] failed to execute query ‘LOCK INSTANCE FOR BACKUP' : 1227 (42000) Access denied; you need (at least one of) the BACKUP_ADMIN privilege(s) for this operation 解決方案: 進入mysql 賦予許可權 grant BACKUP_ADMIN on *.* to ‘root'@‘%'; flush privileges;
[root@myoracle bin]# ./xtrabackup -u root -p -S /home/mysql/mysql.sock --backup --target-dir=/data/backup/full 2022-11-02T09:53:02.321003+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized server arguments: --datadir=/home/mysql/data --innodb_buffer_pool_size=512M 2022-11-02T09:53:02.321193+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized client arguments: --port=3306 --socket=/home/mysql/mysql.sock --user=root --password --socket=/home/mysql/mysql.sock --backup=1 --target-dir=/data/backup/full Enter password: ... ... 2022-11-02T09:53:09.742194+08:00 0 [Note] [MY-011825] [Xtrabackup] Transaction log of lsn (18182291) to (18182301) was copied. 2022-11-02T09:53:09.962188+08:00 0 [Note] [MY-011825] [Xtrabackup] completed OK! [root@myoracle bin]# ll /data/backup/ total 4 drwxr-x---. 5 root root 4096 Nov 2 09:53 full
[root@myoracle bin]# cd /home/mysql/mysql8/bin/ [root@myoracle bin]# ./mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 13 Server version: 8.0.28 MySQL Community Server - GPL Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql> create database dey; Query OK, 1 row affected (0.07 sec) mysql> use dey; Database changed mysql> create table tb(id int); Query OK, 0 rows affected (0.07 sec) mysql> insert into tb values(1),(2); Query OK, 2 rows affected (0.00 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> exit Bye
[root@myoracle bin]# cd /usr/local/xtrabackup/bin/ [root@myoracle bin]# ./xtrabackup -u root -p -S /home/mysql/mysql.sock --backup --target-dir=/data/backup/inc1 --incremental-basedir=/data/backup/full/ 2022-11-02T09:58:37.492129+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized server arguments: --datadir=/home/mysql/data --innodb_buffer_pool_size=512M 2022-11-02T09:58:37.492345+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized client arguments: --port=3306 --socket=/home/mysql/mysql.sock --user=root --password --socket=/home/mysql/mysql.sock --backup=1 --target-dir=/data/backup/inc1 --incremental-basedir=/data/backup/full/ Enter password: ... ... 2022-11-02T09:58:44.745723+08:00 0 [Note] [MY-011825] [Xtrabackup] Transaction log of lsn (18201617) to (18201627) was copied. 2022-11-02T09:58:44.954584+08:00 0 [Note] [MY-011825] [Xtrabackup] completed OK! [root@myoracle bin]# ll /data/backup/ total 8 drwxr-x---. 5 root root 4096 Nov 2 09:53 full drwxr-x---. 6 root root 4096 Nov 2 09:58 inc1
[root@myoracle bin]# cd - /home/mysql/mysql8/bin [root@myoracle bin]# ./mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 16 Server version: 8.0.28 MySQL Community Server - GPL Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | dey | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.01 sec) mysql> drop database dey; Query OK, 1 row affected (0.12 sec) mysql> exit Bye
[root@myoracle bin]# ./xtrabackup --prepare --apply-log-only --target-dir=/data/backup/full/ 2022-11-02T10:03:16.369911+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized server arguments: --innodb_checksum_algorithm=crc32 --innodb_log_checksums=1 --innodb_data_file_path=ibdata1:12M:autoextend --innodb_log_files_in_group=2 --innodb_log_file_size=50331648 --innodb_page_size=16384 --innodb_undo_directory=./ --innodb_undo_tablespaces=2 --server-id=0 --innodb_log_checksums=ON --innodb_redo_log_encrypt=0 --innodb_undo_log_encrypt=0 2022-11-02T10:03:16.370082+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized client arguments: --prepare=1 --apply-log-only=1 --target-dir=/data/backup/full/ ./xtrabackup version 8.0.28-20 based on MySQL server 8.0.28 Linux (x86_64) (revision id: 4cc3081873d) ... ... 2022-11-02T10:03:18.052072+08:00 0 [Note] [MY-013251] [InnoDB] Number of pools: 1 2022-11-02T10:03:18.054302+08:00 0 [Note] [MY-011825] [Xtrabackup] completed OK! [root@myoracle bin]# ./xtrabackup --prepare --apply-log-only --target-dir=/data/backup/full/ --incremental-dir=/data/backup/inc1/ 2022-11-02T10:04:02.786618+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized server arguments: --innodb_checksum_algorithm=crc32 --innodb_log_checksums=1 --innodb_data_file_path=ibdata1:12M:autoextend --innodb_log_files_in_group=2 --innodb_log_file_size=50331648 --innodb_page_size=16384 --innodb_undo_directory=./ --innodb_undo_tablespaces=2 --server-id=0 --innodb_log_checksums=ON --innodb_redo_log_encrypt=0 --innodb_undo_log_encrypt=0 2022-11-02T10:04:02.786786+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized client arguments: --prepare=1 --apply-log-only=1 --target-dir=/data/backup/full/ --incremental-dir=/data/backup/inc1/ ./xtrabackup version 8.0.28-20 based on MySQL server 8.0.28 Linux (x86_64) (revision id: 4cc3081873d) ... ... 2022-11-02T10:04:05.260675+08:00 0 [Note] [MY-011825] [Xtrabackup] Done: Copying /data/backup/inc1/binlog.index to ./binlog.index 2022-11-02T10:04:05.262194+08:00 0 [Note] [MY-011825] [Xtrabackup] completed OK! [root@myoracle bin]# ./xtrabackup --prepare --target-dir=/data/backup/full/ //最後一次執行不需要--apply-log-only 2022-11-02T10:05:08.225156+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized server arguments: --innodb_checksum_algorithm=crc32 --innodb_log_checksums=1 --innodb_data_file_path=ibdata1:12M:autoextend --innodb_log_files_in_group=2 --innodb_log_file_size=50331648 --innodb_page_size=16384 --innodb_undo_directory=./ --innodb_undo_tablespaces=2 --server-id=0 --innodb_log_checksums=ON --innodb_redo_log_encrypt=0 --innodb_undo_log_encrypt=0 2022-11-02T10:05:08.225323+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized client arguments: --prepare=1 --target-dir=/data/backup/full/ ./xtrabackup version 8.0.28-20 based on MySQL server 8.0.28 Linux (x86_64) (revision id: 4cc3081873d) ... ... 2022-11-02T10:05:10.760137+08:00 0 [Note] [MY-012980] [InnoDB] Shutdown completed; log sequence number 18202144 2022-11-02T10:05:10.760601+08:00 0 [Note] [MY-011825] [Xtrabackup] completed OK!
[root@myoracle bin]# mv /home/mysql/data/ /home/mysql/data.BAK [root@myoracle bin]# service mysql stop Shutting down MySQL.. SUCCESS!
[root@myoracle bin]# ./xtrabackup --copy-back --target-dir=/data/backup/full/ 2022-11-02T10:05:44.060196+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized server arguments: --datadir=/home/mysql/data --innodb_buffer_pool_size=512M 2022-11-02T10:05:44.060373+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized client arguments: --port=3306 --socket=/home/mysql/mysql.sock --copy-back=1 --target-dir=/data/backup/full/ ./xtrabackup version 8.0.28-20 based on MySQL server 8.0.28 Linux (x86_64) (revision id: 4cc3081873d) 2022-11-02T10:05:44.060416+08:00 0 [Note] [MY-011825] [Xtrabackup] cd to /data/backup/full/ 2022-11-02T10:05:44.060680+08:00 0 [Note] [MY-011825] [Xtrabackup] Original data directory /home/mysql/data is not empty! [root@myoracle bin]# cp -a /data/backup/full/ /home/mysql/ [root@myoracle bin]# cd /home/mysql [root@myoracle mysql]# ll total 12 drwxr-xr-x. 6 mysql mysql 4096 Nov 2 10:00 data.BAK drwxr-x---. 7 root root 4096 Nov 2 10:05 full drwxrwxr-x. 9 mysql mysql 129 Nov 1 11:25 mysql8 srwxrwxrwx. 1 mysql mysql 0 Nov 2 09:19 mysql.sock -rw-------. 1 mysql mysql 5 Nov 2 09:19 mysql.sock.lock [root@myoracle mysql]# chown -R mysql.mysql full/ [root@myoracle mysql]# mv full/ data [root@myoracle mysql]# ll total 12 drwxr-x---. 7 mysql mysql 4096 Nov 2 10:05 data drwxr-xr-x. 6 mysql mysql 4096 Nov 2 10:00 data.BAK drwxrwxr-x. 9 mysql mysql 129 Nov 1 11:25 mysql8 srwxrwxrwx. 1 mysql mysql 0 Nov 2 09:19 mysql.sock -rw-------. 1 mysql mysql 5 Nov 2 09:19 mysql.sock.lock
[root@myoracle bin]# service mysql start Starting MySQL. SUCCESS! [root@myoracle bin]# ./mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 8 Server version: 8.0.28 MySQL Community Server - GPL Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | dey | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.01 sec) mysql> 資料恢復成功
#!/bin/bash date=`date +%F` backupDir=/data/backup/ target_dir=/data/backup/$date xtrDir=/usr/local/xtrabackup/bin/xtrabackup mysqlDir=/home/mysql/mysql8/bin/mysql backupLog=$backupDir/backuplog mysql_host=192.168.x.x mysql_port=3306 mysql_root=root mysql_password=xxx mysql_socket=/home/mysql/mysql.sock mysql_cnf=/etc/my.cnf $xtrDir --defaults-file=$mysql_cnf --user=$mysql_user --password=$mysql_password --socket=$mysql_socket --compress --compress-threads=2 --backup --target-dir=$target_dir >>$backupLog/backup_full_success.log 2>&1 ##備份時--compress將備份出來的檔案壓縮成.qp結尾的檔案,需要先解壓--decompress,不然在prepare時報錯找不到xtrabackup_logfile,或者在備份時去掉--compress和--compress-threads,我這裡是去掉了。 $xtrDir --prepare --apply-log-only --target-dir=$target_dir >>$backupLog/prepare_full_success.log 2>&1 #find $backupDir -maxdepth 1 -type d -mtime +14 -exec rm -Rf {} ; >>$backupLog/deleted_record.log 2>&1 ##刪除14天前的備份檔案
#!/bin/bash date=`date +%F` datenum=`date -d "1 days ago" +%F` cur_dateTime=$(date "+%Y-%m-%d %H:%M:%S") backupDir=/data/backup target_dir=/data/backup/$date xtrDir=/usr/local/xtrabackup/bin/xtrabackup mysqlDir=/home/mysql/mysql8/bin/mysql backupLog=$backupDir/backuplog mysql_host=192.168.x.x mysql_port=3306 mysql_root=root mysql_password=xxx mysql_socket=/home/mysql/mysql.sock mysql_cnf=/etc/my.cnf $xtrDir --defaults-file=$mysql_cnf --port=$mysql_port --user=$mysql_user --password=$mysql_password --socket=$mysql_socket --compress --compress-threads=2 --backup --target-dir=$target_dir --incremental-basedir=$backupDir/$datenum >> $backupLog/backup_incr_success.log 2>&1 ##這裡和全備指令碼一樣,需要先解壓或者去掉--compress和--compress-threads $xtrDir --prepare --apply-log-only --target-dir=$backupDir/$datenum --incremental-dir=$target_dir >> $backupLog/prepare_incr_success.log 2>&1 #find $backupDir -maxdepth 1 -type d -mtime +14 -exec rm -Rf {} ; >>$backupLog/deleted_record.log 2>&1 ##刪除14天前的備份檔案
[root@myoracle data]# crontab -l 0 10 * * 7 sh /data/mysql_full_backup.sh ##週日10點做一次全備 0 10 * * 1-6 sh /data/mysql_incr_backup.sh ##週一到週六10點做一次增備
到此這篇關於MySQL之xtrabackup備份恢復的實現的文章就介紹到這了,更多相關MySQL xtrabackup備份恢復內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45