搭建MySQL备库
CBackup的主备功能是在CBackup的机器上搭建一个备库,然后通过从全备路径中读取数据进行恢复,恢复成功后,与主库建立主从链接从而进行主备的同步。
提示
1.本系统实现了对 MySQL 的5.6、5.7、8.0 3个版本的备份和恢复到指定时间点的功能;
2.每个版本都要GTID和非GTID模式,系统会自动识别,无需人工干预。
操作步骤如下:
1.要定义好 MySQL 主库的信息
点击 数据备份-定义主库-创建主库定义,填写相应信息,保存即可,MySQL,如下图所示:
提示
用户名和密码为流复制的用户名和密码。
2.点击备库管理-点击创建备库
选择数据库类型,主库名称,备库的名称,IP,端口等具体信息。 点击创建后,会自动创建一个 MySQL 备库实例,创建 MySQL 备库界面如下图所示:
提示
上图是
5.6、5.7版本的创建备库页面
提示
上图是
8.0版本的创建备库页面,在选择版本时,会特别提示;
创建流复制用户时,需用图中红色字体采用的方式。
全量热备份MySQL数据
首先确认配置文件、sock文件和备份文件innobackupex存在
注意
上图是
5.6,5.7版本的全量备份注意事项;
请仔细核对参数是否正确,并根据实际情况,调整参数。
注意
上图是
8.0版本的全量备份注意事项;
执行步骤1的备份命令(MySQL 5.6、5.7版本)
innobackupex --defaults-file=/etc/my.cnf --user=root --password=root --no-timestamp -S /usr/local/mysql/data/mysql.sock --backup /root/fulldatas
下面是执行过程中的信息
[root@mysql56_master ~]# innobackupex --defaults-file=/etc/my.cnf --user=root --password=root --no-timestamp -S /usr/local/mysql/data/mysql.sock --backup /root/fulldatasxtrabackup: recognized server arguments: --datadir=/usr/local/mysql/data --server-id=40 --log_bin=/var/log/mysql/mysql-bin.logxtrabackup: recognized client arguments: --backup=1250731 09:39:07 innobackupex: Starting the backup operationIMPORTANT: Please check that the backup run completes successfully.At the end of a successful backup run innobackupexprints "completed OK!".250731 09:39:07 version_check Connecting to MySQL server with DSN 'dbi:mysql::mysql_read_default_group=xtrabackup;mysql_socket=/usr/local/mysql/data/mysql.sock' as 'root' (using password: YES).250731 09:39:07 version_check Connected to MySQL server250731 09:39:07 version_check Executing a version check against the server...250731 09:39:07 version_check Done.250731 09:39:07 Connecting to MySQL server host: localhost, user: root, password: set, port: not set, socket: /usr/local/mysql/data/mysql.sockUsing server version 5.6.51-loginnobackupex version 2.4.29 based on MySQL server 5.7.44 Linux (x86_64) (revision id: 2e6c0951)xtrabackup: uses posix_fadvise().xtrabackup: cd to /usr/local/mysql/dataxtrabackup: open files limit requested 0, set to 1024xtrabackup: using the following InnoDB configuration:xtrabackup: innodb_data_home_dir = .xtrabackup: innodb_data_file_path = ibdata1:12M:autoextendxtrabackup: innodb_log_group_home_dir = ./xtrabackup: innodb_log_files_in_group = 2xtrabackup: innodb_log_file_size = 50331648InnoDB: Number of pools: 1250731 09:39:07 >> log scanned up to (1953100)xtrabackup: Generating a list of tablespacesInnoDB: Allocated tablespace ID 6 for test_db/t, old maximum was 0250731 09:39:07 [01] Copying ./ibdata1 to /root/fulldatas/ibdata1250731 09:39:07 [01] ...done250731 09:39:07 [01] Copying ./test_db/t.ibd to /root/fulldatas/test_db/t.ibd250731 09:39:07 [01] ...done250731 09:39:07 [01] Copying ./mysql/innodb_table_stats.ibd to /root/fulldatas/mysql/innodb_table_stats.ibd250731 09:39:07 [01] ...done250731 09:39:07 [01] Copying ./mysql/innodb_index_stats.ibd to /root/fulldatas/mysql/innodb_index_stats.ibd250731 09:39:07 [01] ...done250731 09:39:07 [01] Copying ./mysql/slave_worker_info.ibd to /root/fulldatas/mysql/slave_worker_info.ibd250731 09:39:07 [01] ...done250731 09:39:07 [01] Copying ./mysql/slave_relay_log_info.ibd to /root/fulldatas/mysql/slave_relay_log_info.ibd250731 09:39:07 [01] ...done250731 09:39:07 [01] Copying ./mysql/slave_master_info.ibd to /root/fulldatas/mysql/slave_master_info.ibd250731 09:39:07 [01] ...done250731 09:39:08 >> log scanned up to (1953100)250731 09:39:08 Executing FLUSH NO_WRITE_TO_BINLOG TABLES...250731 09:39:08 Executing FLUSH TABLES WITH READ LOCK...250731 09:39:08 Starting to backup non-InnoDB tables and files250731 09:39:08 [01] Copying ./test_db/db.opt to /root/fulldatas/test_db/db.opt250731 09:39:08 [01] ...done250731 09:39:08 [01] Copying ./test_db/t.frm to /root/fulldatas/test_db/t.frm250731 09:39:08 [01] ...done250731 09:39:08 [00] Writing /root/fulldatas/test_db/db.opt250731 09:39:08 [00] ...done250731 09:39:08 [01] Copying ./performance_schema/events_waits_history.frm to /root/fulldatas/performance_schema/events_waits_history.frm250731 09:39:08 [01] ...done250731 09:39:08 [01] Copying ./performance_schema/performance_timers.frm to /root/fulldatas/performance_schema/performance_timers.frm250731 09:39:08 [01] ...done250731 09:39:08 [01] Copying ./performance_schema/events_waits_summary_by_user_by_event_name.frm to /root/fulldatas/performance_schema/events_waits_summary_by_user_by_event_name.frm250731 09:39:08 [01] ...done250731 09:39:08 [01] Copying ./performance_schema/socket_summary_by_event_name.frm to /root/fulldatas/performance_schema/socket_summary_by_event_name.frm250731 09:39:08 [01] ...done250731 09:39:08 [01] Copying ./performance_schema/events_stages_summary_by_account_by_event_name.frm to /root/fulldatas/performance_schema/events_stages_summary_by_account_by_event_name.frm250731 09:39:08 [01] ...done250731 09:39:08 [01] Copying ./performance_schema/events_stages_summary_by_user_by_event_name.frm to /root/fulldatas/performance_schema/events_stages_summary_by_user_by_event_name.frm250731 09:39:08 [01] ...done.........250731 09:39:08 [01] Copying ./mysql/user.MYD to /root/fulldatas/mysql/user.MYD250731 09:39:08 [01] ...done250731 09:39:08 [01] Copying ./mysql/db.MYD to /root/fulldatas/mysql/db.MYD250731 09:39:08 [01] ...done250731 09:39:08 [01] Copying ./mysql/user.frm to /root/fulldatas/mysql/user.frm250731 09:39:08 [01] ...done250731 09:39:08 [01] Copying ./mysql/slow_log.CSV to /root/fulldatas/mysql/slow_log.CSV250731 09:39:08 [01] ...done250731 09:39:08 Finished backing up non-InnoDB tables and files250731 09:39:08 [00] Writing /root/fulldatas/xtrabackup_binlog_info250731 09:39:08 [00] ...done250731 09:39:08 Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...xtrabackup: The latest check point (for incremental): '1953100'xtrabackup: Stopping log copying thread..250731 09:39:08 >> log scanned up to (1953100)250731 09:39:09 Executing UNLOCK TABLES250731 09:39:09 All tables unlocked250731 09:39:09 Backup created in directory '/root/fulldatas/'MySQL binlog position: filename 'mysql-bin.000016', position '120'250731 09:39:09 [00] Writing /root/fulldatas/backup-my.cnf250731 09:39:09 [00] ...done250731 09:39:09 [00] Writing /root/fulldatas/xtrabackup_info250731 09:39:09 [00] ...donextrabackup: Transaction log of lsn (1953100) to (1953100) was copied.250731 09:39:09 completed OK![root@mysql56_master ~]#
当看到 completed OK! 时,表示备份成功。
提示
MySQL8.0版本命令
xtrabackup —user=备份用户 —password=密码 —backup —target-dir=/path/fulldatas
例如:
xtrabackup —user=root —password=root —backup —target-dir=/root/fulldatas
执行步骤2的打包命令
tar cvf fulldatas.tar fulldatas`
执行步骤3的上传备份数据的命令
形如:scp fulldatas.tar root@xxx.xxx.xxx.xxx:
直接copy对话框中的内容,执行即刻。
提示
1.要依次执行步骤2和步骤3,不可同时执行;
2.待步骤3命令执行完毕,方可点击页面对话框中右下角的创建按钮。
3.查看创建后备库状态
查看备库状态界面,如下图所示:
提示
1.点击备库列表下相应的备库名,可查看备库实时信息;
2.当Slave_IO_Running显示为Yes,Slave_SQL_Running显示为Yes时,表示全量恢复已经完成;
4.制定备份保留策略
点击更多,点击备份策略,设置备份保留策略界面,如下图所示:
5.选择归档保留天数,定时备份的时间,备份保留的策略
归档保留策略我们一般建议设置为7-14天。定时备份策略可以0,6,12,18点备份 。备份保留策略我们建议一周保留所有备份,2周保留四分之一,一个月保留八分之一。当然也视具体情况而定,设置 MySQL 备份保留策略界面,如下图所示: