1.安装obdumper
(1)下载软件
OceanBase分布式数据库-海量数据 笔笔算数https://www.oceanbase.com/softwarecenter
(2)安装软件
参考:https://www.oceanbase.com/docs/common-oceanbase-dumper-loader-1000000000628759https://www.oceanbase.com/docs/common-oceanbase-dumper-loader-1000000000628759
上传导数工具软件包到服务器并解压:
unzip ob-loader-dumper-4.2.x-RELEASE.zip
cd ob-loader-dumper-4.2.x-RELEASE
(3)配置运行环境
注意
用户的本地环境中必须安装 Java 8+ 并配置 JAVA_HOME
环境变量。强烈建议安装 JDK 1.8.0_3xx 及之后的版本。环境配置详情请参考 准备环境。
本步骤旨在修改 JVM 参数。
JVM 内存太小可能会影响导入导出的性能,甚至影响导入导出功能的稳定性。例如:Full GC 或者 GC Crash。
-
编辑
JAVA_OPTS
选项所在的文件。-
Linux 操作系统下,编辑
{ob-loader-dumper}/bin/
目录下的obloader
和obdumper
脚本。 -
Windows 操作系统下,编辑
{ob-loader-dumper}/bin/windows/
目录下的obloader.bat
和obdumper.bat
脚本。
-
-
修改 JVM 参数。
说明
建议您根据运行机器的实际规格,调整 JVM 内存为适当的值。
示例:运行机器可用内存为 16G,将 JVM 堆内存设置为 8G。
JAVA_OPTS="$JAVA_OPTS -server -Xms8G -Xmx8G -XX:MetaspaceSize=128M -XX:MaxMetaspaceSize=128M -Xss352K" JAVA_OPTS="$JAVA_OPTS -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -Xnoclassgc -XX:+DisableExplicitGC
2.查询用户是否有备份权限
参考:OceanBase分布式数据库-海量数据 笔笔算数https://www.oceanbase.com/docs/common-oceanbase-dumper-loader-1000000000628761
运行权限
OBLOADER 运行权限
使用 OBLOADER 连接 OceanBase 数据库导入数据时,连接数据库的账号需要拥有 CREATE
, SELECT
, INSERT
, UPDATE
等命令的执行权限。可通过 SHOW GRANTS
语句查看用户被授予的权限。示例语句:
obclient> SHOW GRANTS FOR user1;
+------------------------------------------+
| Grants for user1@% |
+------------------------------------------+
| GRANT CREATE ON *.* TO 'user1' |
| GRANT SELECT ON `db1`.* TO 'user1' |
| GRANT INSERT ON `db1`.* TO 'user1' |
| GRANT UPDATE ON `db1`.* TO 'user1' |
| GRANT SELECT ON `oceanbase`.* TO 'user1' |
+------------------------------------------+
2 rows in set
说明
-
如果是 OceanBase 数据库 MySQL 租户,导入数据前,用户需要具备
oceanbase
数据库的查询权限。授权语句示例:GRANT SELECT ON `oceanbase`.* TO 'user1'
。如果是 OceanBase 数据库 Oracle 租户,导入数据前,用户需要具备
SYS
的查询权限。授权语句示例:GRANT SELECT ON "SYS".* TO 'user1'
。 - 使用 OBLOADER 连接 OceanBase 数据库 Oracle 租户导入数据库对象定义和数据时,建议使用数据库管理员(DBA)角色的账号连接数据库。
OBDUMPER 运行权限
使用 OBDUMPER 连接 OceanBase 数据库导出数据时,连接数据库的账号需要拥有 CREATE
, SELECT
等命令的执行权限。可通过 SHOW GRANTS
语句查看用户被授予的权限。示例语句:
obclient> SHOW GRANTS FOR user1;
+------------------------------------------+
| Grants for user1@% |
+------------------------------------------+
| GRANT CREATE ON *.* TO 'user1' |
| GRANT SELECT ON `db1`.* TO 'user1' |
| GRANT SELECT ON `oceanbase`.* TO 'user1' |
+------------------------------------------+
2 rows in set
本次实验环境为:
CREATE USER test1 IDENTIFIED BY "test1234";
create database db1;
create table t1 (id int);
GRANT CREATE ON *.* TO 'test1';
GRANT SELECT ON `db1`.* TO 'test1';
GRANT SELECT ON `oceanbase`.* TO 'test1';
3.使用obdumper进行备份
mkdir -p /tmp/ob --创建备份目录
cd /data/ob-loader-dumper-4.2.1-RELEASE/bin --切换到obdumper的bin目录
[root@oceanbase bin]# ./obdumper -h127.0.0.1 -P 2881 -u test1@sys -p test1234 -D db1 --csv --table '*' -f /tmp/obbk
2024-06-23 14:37:06 [INFO] Parsed args:
[--csv] true
[--file-path] /tmp/obbk
[--host] 127.0.0.1
[--port] 2881
[--user] test1@sys
[--password] ******
[--database] db1
[--sys-user] root
[--table] [*]
2024-06-23 14:37:06 [INFO] Load jdbc driver class: "com.oceanbase.jdbc.Driver" finished
2024-06-23 14:37:06 [INFO] Manifest: "/tmp/obbk/data/MANIFEST.bin" has been saved
2024-06-23 14:37:06 [WARN] Query table entry for table: "t1" is null. Consider the table as non-partitioned table.
2024-06-23 14:37:06 [INFO] Try to query unique keys for table: "t1".... (But no-primary constraints).
2024-06-23 14:37:06 [INFO] Query unique keys for table: "t1" success. (No-unique constraints). Elapsed: 2.815 ms
2024-06-23 14:37:06 [INFO] Query table entry for table: "t1" success. Remain: 0. Elapsed: 1.711 ms
2024-06-23 14:37:06 [INFO] Query all table entries success. Total: 1. Elapsed: 42.23 ms
2024-06-23 14:37:06 [INFO] Split rows for non-partitioned table(without primary key): "t1" success. Ranges: 1
2024-06-23 14:37:06 [INFO] Generate 1 dump tasks finished. Total Elapsed: 11.68 ms
2024-06-23 14:37:06 [INFO] Start 8 record dump threads for 1 dump tasks finished
2024-06-23 14:37:07 [INFO] Dump 2 rows db1.t1 to "/tmp/obbk/data/db1/TABLE/t1.1.*.csv" finished
2024-06-23 14:37:08 [INFO] Close connection count: 7 of the DataSource. Key: BIZ
2024-06-23 14:37:08 [INFO] Shutdown task context finished
2024-06-23 14:37:08 [INFO] ---------- Finished Tasks: 1 Running Tasks: 0 Progress: 100.00% ----------
2024-06-23 14:37:08 [INFO]
All Dump Tasks Finished:
----------------------------------------------------------------------------------------------------------------------------
No.# | Type | Name | Count | Status
----------------------------------------------------------------------------------------------------------------------------
1 | TABLE | t1 | 2 | SUCCESS
----------------------------------------------------------------------------------------------------------------------------
Total Count: 2 End Time: 2024-06-23 14:37:08
2024-06-23 14:37:08 [INFO] Dump record finished. Total Elapsed: 1.141 s
2024-06-23 14:37:08 [INFO] System exit 0
[root@oceanbase bin]#