yum -y install bzip2
xtrabackup8 适用于 mysql8
sudo yum install https://repo.percona.com/yum/percona-release-latest.noarch.rpm
sudo percona-release enable-only tools
sudo yum install percona-xtrabackup-80
# 下载并安装
curl -L http://gosspublic.alicdn.com/ossutil/1.6.9/ossutil64 -o /usr/local/bin/ossutil64
# 添加执行权限
chmod +x /usr/local/bin/ossutil64
#查看版本
ossutil64 -v
在配置文件conf/backup.conf
中添加ossutil信息
### oss-config
# 阿里云OSS Bucket
oss_bucket = test-data-backup
# 自定义一个命名空间
oos_namespaces = test
# 阿里云OSS Endpoint
oss_endpoint = oss-cn-shenzhen-internal.aliyuncs.com
# 阿里云OSS AccessKeyId
oss_accesskeyid = LTAI3Fm7GEQca5BTBK8Bhqea
# 阿里云OSS AccessKeySecret
oss_accesskeysecret = jCPQ2cgJz3ZfBoc3btdCn2uHgPDdcl
# 阿里云ossutil命令路径
ossutil_bin = /usr/local/bin/ossutil64
ossutil具体使用方法可查看官方文档
git clone https://github.com/jayknoxqu/database-backup.git /usr/local/database-backup
chmod +x $(find /usr/local/database-backup -name '*.sh')
# 每天凌晨3点15分执行备份mongodb
15 3 * * * /usr/local/database-backup/mongo/bin/backup.sh >/dev/null 2>&1
# 每天凌晨4点15分执行备份mysql
15 4 * * * /usr/local/database-backup/mysql/bin/backup.sh >/dev/null 2>&1
systemctl stop mysqld
mv /var/lib/mysql /var/lib/mysql-bak
mkdir -p /var/lib/mysql
xtrabackup --prepare --apply-log-only --target-dir=/mnt/backups/mysql/full_2021-08-23_04-15-01_1
Tip:参数--defaults-file=/etc/my.cnf
可指定mysql的配置文件,它会读取mysql数据的目录和binlog目录
xtrabackup --prepare --apply-log-only --target-dir=/mnt/backups/mysql/full_2021-08-23_04-15-01_1 --incremental-dir=/mnt/backups/mysql/incr_2021-08-24_04-15-01_2
Tip:多份增量备份的数据重复执行合并操作即可
xtrabackup --prepare --target-dir=/mnt/backups/mysql/full_2021-08-23_04-15-01_1
xtrabackup --copy-back --target-dir=/mnt/backups/mysql/full_2021-08-23_04-15-01_1
chown -R mysql:mysql /var/lib/mysql
systemctl start mysqld 或者 /usr/sbin/mysqld --user=mysql &