研发服:
yum install -y /data/mysql/backup/percona-xtrabackup-24-2.4.21-1.el7.x86_64.rpm
rpm -qa | grep percona-xtrabackup
rpm -e percona-xtrabackup-80-8.0.22-15.1.el7.x86_64
xtrabackup --defaults-file=/etc/my.cnf --backup --databases=‘db_name’ --user=‘root’ --password=‘db_pwd’ --host=‘127.0.0.1’ --target-dir=/data/mysql/backup/
============================================
生产服务器:
yum install -y /data/backup/percona-xtrabackup-24-2.4.21-1.el7.x86_64.rpm
/data/backup
##############
#单库备份
##############
#第一种方法指定备份文件夹
innobackupex --defaults-file=/etc/my.cnf --backup --databases=‘testdb’ --no-timestamp --user=root --host=127.0.0.1 --password=‘db_pwd’ /data/backup/
#第二种方法
innobackupex --defaults-file=/etc/my.cnf --backup --databases=‘testdb’ --user=root --host=127.0.0.1 --password=‘db_pwd’ /data/backup/
##############
#恢复
##############
innobackupex --defaults-file=/etc/my.cnf --databases=‘testdb’ --user=root --host=127.0.0.1 --passsword=‘db_pwd’ --apply-log /data/backup/2021-03-03_17-08-34
mysqladmin -u root -h 127.0.0.1 -p shutdown
#备份原始文件
mkdir /data/backup/old_fullbackup_ ( d a t e + (date +%Y-%m-%d_%H-%M) && cp -Rf /data/mysql/* /data/backup/old_fullbackup_ (date+(date +%Y-%m-%d_%H-%M)
mv /data/backup/2021-03-03_16-01-36 /data/mysql/
mv /data/mysql/2021-03-03_16-01-36 /data/mysql/testdb
chown mysql:mysql -R /data/mysql/testdb
##############
#全部备份
##############
mkdir /data/backup/old_fullbackup_ ( d a t e + (date +%Y-%m-%d_%H-%M) && cp -Rf /data/mysql/* /data/backup/old_fullbackup_ (date+(date +%Y-%m-%d_%H-%M)
innobackupex --default-file=/etc/my.cnf --no-timestamp --user root --password ‘db_pwd’ --host 127.0.0.1 /data/backup/all-20210304bak
–删除数据
#开始还原
innobackupex --default-file=/etc/my.cnf --user root --password ‘db_pwd’ --host 127.0.0.1 --apply-log /data/backup/all-20210304bak
mysqladmin -uroot -p’db_pwd’ shutdown
mv /data/mysql /data/mysql_bak
mv /data/backup/all-20210304bak /data/mysql
chown mysql:mysql -R /data/mysql
#增备
innobackupex --default-file=/etc/my.cnf --no-timestamp --user root --password ‘db_pwd’ --host 127.0.0.1 /data/backup/all-20210304bak
innobackupex --defaults-file=/etc/my.cnf --no-timestamp --user root --password ‘db_pwd’ --host 127.0.0.1 --incremental /data/backup/all-2021030401incr --incremental-basedir=/data/backup/all-20210304bak
innobackupex --defaults-file=/etc/my.cnf --no-timestamp --user root --password ‘db_pwd’ --host 127.0.0.1 --incremental /data/backup/all-2021030402incr --incremental-basedir=/data/backup/all-2021030401incr
innobackupex --default-file=/etc/my.cnf --user root --password ‘db_pwd’ --host 127.0.0.1 --apply-log --redo-only /data/backup/all-20210304bak
innobackupex --default-file=/etc/my.cnf --user root --password ‘db_pwd’ --host 127.0.0.1 --apply-log --redo-only /data/backup/all-20210304bak --incremental-dir=/data/backup/all-2021030401incr
innobackupex --default-file=/etc/my.cnf --user root --password ‘db_pwd’ --host 127.0.0.1 --apply-log --redo-only /data/backup/all-20210304bak --incremental-dir=/data/backup/all-2021030402incr
innobackupex --default-file=/etc/my.cnf --user root --password ‘db_pwd’ --host 127.0.0.1 --apply-log /data/backup/all-20210304bak
参考资料:
Percona XtraBackup打包备份使用注意
https://www.cnblogs.com/gaoyuechen/p/8808100.html
利用Xtrabackup进行单库备份、单表恢复实例
https://blog.csdn.net/zhwxl_zyx/article/details/105795355