博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
percona-xtrabackup-8.0.7简单快捷使用
阅读量:5279 次
发布时间:2019-06-14

本文共 5231 字,大约阅读时间需要 17 分钟。

percona-xtrabackup-8.0.7简单快捷使用

# 参考资料:

https://blog.csdn.net/vkingnew/article/details/83012316

# 环境:centos6.x

yum -y install perl-DBIyum -y install perl-DBD-MySQL yum -y install perl-IO-Socket-SSL.noarchyum -y install perl-Time-HiRes  yum -y install perl-TermReadKeyyum -y install perl-ExtUtils-MakeMaker[root@dbhost ~]# rpm -qa|grep libgcryptlibgcrypt-1.4.5-12.el6_8.x86_64

# 下载对应的版本

cd /opt/wget https://www.percona.com/downloads/Percona-XtraBackup-LATEST/Percona-XtraBackup-8.0-7/binary/tarball/percona-xtrabackup-8.0.7-Linux-x86_64.libgcrypt145.tar.gztar -zxf percona-xtrabackup-8.0.7-Linux-x86_64.libgcrypt145.tar.gz cd /usr/local/ln -s /opt/percona-xtrabackup-8.0.7-Linux-x86_64 xtrabackupln -fs  /opt/percona-xtrabackup-8.0.7-Linux-x86_64/bin/* /usr/bin/ xtrabackup -v

# 在主库中创建专用备份账号

create user 'bk_user'@'10.192.30.%' identified WITH mysql_native_password by 'v9SimLKsIHpwzyOgVwlM' PASSWORD EXPIRE NEVER ; GRANT BACKUP_ADMIN,SELECT, RELOAD, PROCESS, SUPER, LOCK TABLES, REPLICATION SLAVE, REPLICATION CLIENT, SHOW VIEW ON *.* TO 'bk_user'@'10.192.30.%';

# 全量备份(在本地从库上备份)

xtrabackup --defaults-file=/data/mysql/mysql_3306/my_3306.cnf --host=10.192.30.60 --user='bk_user' --password='v9SimLKsIHpwzyOgVwlM' --port=3306  --backup --compress --compress-threads=8 --use-memory=4G --slave-info --parallel=8 --target-dir=/data/backup/

# 全量恢复

# 需要先清空数据目录下的文件及其目录

-- rm -rf tmp/* undolog/* data/* logs/mysql-bin*

# 先解压,需要单独安装

/*wget http://www.quicklz.com/qpress-11-linux-x64.tartar xvf qpress-11-linux-x64.tarcp qpress /usr/bin # 如果无法下载,登录其官网,单独下载,再上传 */xtrabackup --defaults-file=/data/mysql/mysql_3306/my_3306.cnf  --use-memory=4G --decompress --parallel=8 --remove-original --target-dir=/data/backup/  # 压缩备份xtrabackup --defaults-file=/data/mysql/mysql_3306/my_3306.cnf --prepare --use-memory=4G --parallel=8 --target-dir=/data/backup/  # 恢复数据xtrabackup --defaults-file=/data/mysql/mysql_3306/my_3306.cnf --copy-back --use-memory=4G --parallel=8 --target-dir=/data/backup/  # 拷贝会目录所在,这里推荐使用--copy-back方式,因为我的my.cnf中的配置路径是分散的chown -R mysql.mysql *

# 附录:简单的全备shell脚本

#!/bin/bash# file_name: /usr/local/scripts/full_xtrabackup.sh##################################################################################################################################################################### create user 'bk_user'@'10.192.30.%' identified WITH mysql_native_password by 'v9SimLKsIHpwzyOgVwlM' PASSWORD EXPIRE NEVER ; # GRANT BACKUP_ADMIN,SELECT, RELOAD, PROCESS, SUPER, LOCK TABLES, REPLICATION SLAVE, REPLICATION CLIENT, SHOW VIEW ON *.* TO 'bk_user'@'10.192.30.%';# mkdir -p /data/backup/logs/ ; mkdir -p /data/backup/full_bak/# 33 18 13 08 * /bin/bash  /usr/local/scripts/full_xtrabackup.sh &>/dev/null. /etc/init.d/functionsDate_Time=`date +%Y%m%d%H%M%S`Date_Day=`date +%Y%m%d%H%M`Target_Dir="/data/backup/full_bak/"User_Name="bk_user"Pass_Word="v9SimLKsIHpwzyOgVwlM"Host_Ip="10.192.30.60"Port_MySQL="3306"Xtrabackup_Cmd="/usr/bin/xtrabackup"Compress_Threads="8"Parallel_Num='8'Use_Memory="4G"My_Conf="/data/mysql/mysql_3306/my_3306.cnf"Log_File_Dir="/data/backup/logs/"Log_File="/data/backup/logs/full_bak_"${Date_Day}""Count_Day="30"Scp_Target_Host="root@10.192.30.53:/data/backup/full_backup/"# 全备份function Full_Backup(){    "${Xtrabackup_Cmd}" --defaults-file="${My_Conf}" --host="${Host_Ip}" --user="${User_Name}" --password="${Pass_Word}" --port="${Port_MySQL}" --backup --compress --compress-threads="${Parallel_Num}" --use-memory="${Use_Memory}" --slave-info --parallel="${Parallel_Num}" --target-dir="${Target_Dir}"full_bak_"${Date_Day}"/ &>>"${Log_File}".log    Results=`tail -1  "${Log_File}".log | awk '{print $3}'`    if [ "${Results}"x == "completed"x ]; then        echo "############################################################################" &>>"${Log_File}".log        action "full_backup files are successful" /bin/true &>>"${Log_File}".log    else        echo "############################################################################" &>>"${Log_File}".log        action "full_backup files are error" /bin/false &>>"${Log_File}".log    fi}# 给远端传输一份,需要实现配置rsync或者ssh互信    function Scp_BackupFiles(){    Results=`tail -3  "${Log_File}".log |head -1| awk '{print $3}'`    if [ "${Results}"x == "completed"x ]; then        scp -rp -l 52428800 "${Target_Dir}"full_bak_"${Date_Day}" "${Scp_Target_Host}"        if [ "$?" -eq 0 ]; then             action " "${Target_Dir}"full_bak_"${Date_Day}" are successfully transformed. " /bin/true &>>"${Log_File}".log        fi    else        echo "############################################################################" &>>"${Log_File}".log        action " "${Target_Dir}"full_bak_"${Date_Day}" are failed transformed.  " /bin/false &>>"${Log_File}".log    fi}# 删除旧文件,保留最近n天的文件function Delete_Files(){    find "${Target_Dir}" -type d -mtime  +"${Count_Day}" -name "full_bak*" -exec rm -rf  {} \;    find "${Log_File_Dir}" -type f -mtime  +"${Count_Day}" -name "full_bak_*.log" -exec rm -rf  {} \;}Full_Backupsleep 10Scp_BackupFilesDelete_Files#################################################################################################################################################################

 

转载于:https://www.cnblogs.com/bjx2020/p/11350281.html

你可能感兴趣的文章
SetCapture() & ReleaseCapture() 捕获窗口外的【松开左键事件】: WM_LBUTTONUP
查看>>
Android 设置界面的圆角选项
查看>>
百度地图api服务端根据经纬度得到地址
查看>>
CSS中隐藏内容的3种方法及属性值
查看>>
每天一个linux命令(1):ls命令
查看>>
根据xml生成相应的对象类
查看>>
查看ASP.NET : ViewState
查看>>
Android StageFrightMediaScanner源码解析
查看>>
vue项目中开启Eslint碰到的一些问题及其规范
查看>>
循环队列实现
查看>>
CSS层模型
查看>>
springBoot 项目 jar/war打包 并运行
查看>>
HDU 1501 Zipper
查看>>
打包java程序生成exe
查看>>
八叉树
查看>>
poj 1129 搜索
查看>>
Git 远程仓库
查看>>
HttpClient的巨坑
查看>>
关于静态文本框透明度的问题
查看>>
海量数据、高并发的优化方案
查看>>