MySQL数据库统一备份平台管理

MySQL集中备份平台实现过程:


  #1、将文件db_back存放在/home目录下

#2、将dbreport存放在在/home/www目录下

1、修改/home/db_backup/config.ini配置文件,设置连接数据库设定的4个表基础信息

[baseconf]
host=192.168.15.57 #根据实际修改
name=dbinfo        #根据实际修改库信息
port=5700          #端口
user=dlan   #用户名
password=root123   #密码
Charset=utf8
[concurrent]

processor=20

2、添加数据库及表

1#create database dbconfig;

CREATE TABLE `mysql_backup_list` (
  `c_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '数据库ID',
  `idc` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '所属IDC',
  `c_ip` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'ip',
  `db_version` enum('5.1','5.5','5.6') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '5.1',
  `back_type` enum('mysqldump','xtrabackup','mydumper') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'mysqldump',
  `c_port` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT '数据库端口',
  `app_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '应用名称',
  `mysql_dir` varchar(120) COLLATE utf8mb4_unicode_ci DEFAULT '/usr/local/mysql/bin' COMMENT 'mysql安装路径',
  `defaults_file` varchar(60) COLLATE utf8mb4_unicode_ci DEFAULT '/etc/my3306.cnf',
  `c_socket` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '/tmp/mysql3306.sock' COMMENT 'sock 名称,带路径',
  `back_dbs` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT '--all-databases' COMMENT '备份的数据库',
  `c_user` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'root' COMMENT '账号',
  `c_passwd` varchar(30) CHARACTER SET latin1 NOT NULL DEFAULT '' COMMENT '密码',
  `bin_log` tinyint(4) DEFAULT '0' COMMENT '0开bin-log,1,未开启',
  `is_backup` tinyint(4) DEFAULT '0' COMMENT '0备份,1不备份',
  `is_ftp` smallint(6) NOT NULL DEFAULT '0' COMMENT '是否上传到ftp,0上传,1不上传',
  `back_dir` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT '/home/backup' COMMENT '备份目录',
  `expire_days` int(11) NOT NULL DEFAULT '15' COMMENT '保留天数',
  `c_comment` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '备注',
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '插入记录时间',
  PRIMARY KEY (`c_id`),
  UNIQUE KEY `NewIndex1` (`c_ip`,`c_port`)

) ENGINE=InnoDB AUTO_INCREMENT=124 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

CREATE TABLE `mysql_backup_log` (
  `c_id` int(11) NOT NULL AUTO_INCREMENT,
  `db_id` int(11) DEFAULT '0' COMMENT 'mysql_backup_list表的c_id',
  `c_date` datetime DEFAULT '0000-00-00 00:00:00' COMMENT '备份日期',
  `file_name` varchar(80) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '文件名',
  `file_md5` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT 'md5值',
  `file_size` bigint(20) NOT NULL DEFAULT '0' COMMENT '备份文件大小',
  `step` enum('backup','ftp') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'backup' COMMENT '步骤,是ftp还是backup',
  `is_backok` tinyint(4) DEFAULT '0' COMMENT '备份情况,0 成功,1失败',
  `is_ftpok` tinyint(4) DEFAULT '0' COMMENT 'FTP上传情况,0 成功,1失败',
  `message` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '备份时的错误信息',
  PRIMARY KEY (`c_id`)

) ENGINE=InnoDB AUTO_INCREMENT=3303 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

2#添加数据库:create database dbinfo

CREATE TABLE `mysql_ssh_pass` (
  `id` int(32) NOT NULL AUTO_INCREMENT,
  `idc` int(16) DEFAULT NULL COMMENT '所述IDC编号',
  `ip` varchar(15) DEFAULT NULL COMMENT '数据库ip',
  `os` varchar(30) DEFAULT NULL COMMENT '服务器系统版本',
  `username` varchar(20) DEFAULT NULL COMMENT 'ssh用户名',
  `password` varchar(128) DEFAULT NULL COMMENT 'ssh密码',
  `comment` varchar(500) NOT NULL DEFAULT '' COMMENT '备注',
  PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=214 DEFAULT CHARSET=utf8

2、修改/home/db_back/mysql_back_ssh.py管理端管理地址


3、修改/home/db_back下mysql_back_status.py、send_err_mails.py为备份成功或者失败邮件地址

##有需要修改地址的都设置相同即可,不重复截图


5、配置apache服务

#apache根据提供的包,解压到/usr/local目录下,修改文件配置:/usr/local/apache/conf/extra/httpd-vhosts.conf

#修改目录的权限:chown -R daemon.daemon /home/www


6、修改/home/www/dbreport/config.inc.php 配置dbconfig的数据库地址信息


7、给dbinfo.mysql_ssh_pass表添加登陆系统的用户名和密码并设置服务器IDC编号(编号为备份设置定时任务使用)

#用户名和密码采用加密方式存储:在LINUX 终端执行获取加解信息

    ##加密 echo -n "123456"|base64 

    ##解密 echo -n "MTIzNDU2"|base64 -d

如系统登录用户为root 密码为123456

加密:


解密:


INSERT INTO mysql_ssh_pass (idc,ip,os,username,PASSWORD,COMMENT)VALUES(120,'192.168.21.17','centos','加密后root密文','加密后密码秘闻','测试backup');

##若服务器为多实例,SSH列表设置一条信息登陆服务器信息即可。

8、添加备份用户信息dbconfig.mysql_backup_list

INSERT INTO `dbconfig`.`mysql_backup_list`
 (idc,c_ip, db_version, c_port, c_user,defaults_file,c_socket,c_passwd,bin_log,mysql_dir,is_backup,back_type,back_dir,back_dbs,expire_days,is_ftp, app_name)
VALUES ('120','192.168.28.87', '5.5','3306', 'root', '/etc/my3306.cnf','/tmp/mysql3306.sock', ENCODE('数据库登陆密码','tm_dba'), '0', '/usr/local/mysql/bin','0','mysqldump','/home/backup','--all-databases','10','1','测试');

##具体字段描述:


##备份信息列表IP地址必须在ssh表存在,两者idc值可以不一样,最终启动备份使用的idc值为此表(mysql_backup_list)idc

9、在管理服务器设置定时任务,如:


##1\2\3\4\5\6值一定存在mysql_backup_list表里的idc值

10、设置定时任务邮件和微信告警


11、配置微信脚本



微信告警配置具体百度下,需要申请个微信企业号

12、需要把db_backup.sh分发到到备份服务器上,若备份服务器没有xtra需要安装,mysqldump mydumpe在全局变量都可以访问到/usr/bin目录下

13、启动apache服务

##启动成功

文件下载路径:

https://download.csdn.net/download/weixin_36135773/10277785


Legal Notice Copyright © 2017 Veritas Technologies LLC. All rights reserved. Veritas and the Veritas Logo are trademarks or registered trademarks of Veritas Technologies LLC or its affiliates in the U.S. and other countries. Other names may be trademarks of their respective owners. This product may contain third party software for which Veritas is required to provide attribution to the third party (“Third Party Programs”). Some of the Third Party Programs are available under open source or free software licenses. The License Agreement accompanying the Software does not alter any rights or obligations you may have under those open source or free software licenses. Please see the Third Party Legal Notice Appendix to this Documentation or TPIP ReadMe File accompanying this product for more information on the Third Party Programs. The product described in this document is distributed under licenses restricting its use, copying, distribution, and decompilation/reverse engineering. No part of this document may be reproduced in any form by any means without prior written authorization of Veritas Technologies LLC and its licensors, if any. THE DOCUMENTATION IS PROVIDED "AS IS" AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID. VERITAS TECHNOLOGIES LLC SHALL NOT BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH THE FURNISHING, PERFORMANCE, OR USE OF THIS DOCUMENTATION. THE INFORMATION CONTAINED IN THIS DOCUMENTATION IS SUBJECT TO CHANGE WITHOUT NOTICE. The Licensed Software and Documentation are deemed to be commercial computer software as defined in FAR 12.212 and subject to restricted rights as defined in FAR Section 52.227-19 "Commercial Computer Software - Restricted Rights" and DFARS 227.7202, et seq. "Commercial Computer Software and Commercial Computer Software Documentation," as applicable, and any successor regulations, whether delivered by Veritas as on premises or hosted services. Any use, modification, reproduction release, performance, display or disclosure of the Licensed Software and Documentation by the U.S. Government shall be solely in accordance with the terms of this Agreement.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值