(一) 通過dbexport實現單表數據還原
1. 測試前的信息查看
[gbasedbt@iZ2ze5s78e4tanwe5q2znxZ ~]$ dbaccess test -
Your evaluation license will expire on 2025-05-26 00:00:00Database selected.> select * from test21;id name1 a2 b3 c3 row(s) retrieved.Elapsed time: 0.001 sec
2. 通過dbexport備份數據
--創建文件夾
mkdir backup
--執行命令
dbexport test -ss -o backup/ -l
3. 還原數據
- 備份過后將會在backup/文件夾下出現庫名+.exp的格式的文件夾,本次出現的是test.exp文件夾
- 文件夾內容里.sql的是表結構文件,其余的是數據文件
[gbasedbt@iZ2ze5s78e4tanwe5q2znxZ ~]$ cd backup/test.exp/
[gbasedbt@iZ2ze5s78e4tanwe5q2znxZ test.exp]$ ls -l *sql
--ora.sql是oracle模式下的表結構,如果沒有使用oracle模式,則表結構在test下
-rw-rw-r-- 1 gbasedbt gbasedbt 9557 Jul 3 17:45 test_ora.sql
-rw-rw-r-- 1 gbasedbt gbasedbt 13244 Jul 3 17:45 test.sql
[gbasedbt@iZ2ze5s78e4tanwe5q2znxZ test.exp]$
[gbasedbt@iZ2ze5s78e4tanwe5q2znxZ test.exp]$ cat test.sql|grep -i -A 5 -B 5 'create table "gbasedbt".test21'commcol = id,name }
--說明表test21對應的數據文件為test200118.unl
{ unload file name = test200118.unl number of rows = 3 }create table "gbasedbt".test21(id integer,name varchar(10)) extent size 16 next size 64 lock mode page;
[gbasedbt@iZ2ze5s78e4tanwe5q2znxZ test.exp]$ dbaccess test -
Your evaluation license will expire on 2025-05-26 00:00:00Database selected.> truncate table test21;Table truncated.Elapsed time: 0.003 sec> load from /home/gbasedbt/backup/test.exp/test200118.unl insert into test21;3 row(s) loaded.Elapsed time: 0.002 sec> select * from test21;id name1 a2 b3 c3 row(s) retrieved.Elapsed time: 0.001 sec>
(二) 復制數據庫(適合小數據庫的場景,否則時間過長)
1. 統計數據庫大小
select dbsname,sum(pe_size)*4
from
sysmaster:sysptnext a,
outer sysmaster:systabnames b
where a.pe_partnum=b.partnum group by 1;
2. 復制數據庫的步驟
- 準備備份文件夾
- 備份數據庫
- 更改信息
- 粘貼(還原)數據庫
3. 信息收集
- 保存的文件夾:/home/gbasedbt/backup
- 需要復制的數據庫:test
- 復制粘貼成的數據庫:test_cp
4. 備份數據庫
[gbasedbt@node01 ~]$ mkdir backup
[gbasedbt@node01 ~]$ dbexport test -ss -o backup/ -l
Your evaluation license will expire on 2025-04-22 00:00:00
{ DATABASE test delimiter | }
grant dba to "gbasedbt";
set environment sqlmode 'oracle';
set environment sqlmode 'gbase';
revoke usage on language SPL from public ;
grant usage on language SPL to public ;
dbexport completed
[gbasedbt@node01 ~]$
5. 更改信息(四處)
--備份的文件夾名稱更改
mv backup/test.exp backup/test_cp.exp--更新gbase模式sql文件的名稱mv backup/test_cp.exp/test.sql backup/test_cp.exp/test_cp.sql--更新oracle模式下sql文件的名稱mv backup/test_cp.exp/test_ora.sql backup/test_cp.exp/test_cp_ora.sql--更新文件內的數據庫名稱sed -i 's/{ DATABASE test delimiter | }/{ DATABASE test_cp delimiter | }/g' backup/test_cp.exp/test_cp.sql
6. 還原數據庫
[gbasedbt@node01 ~]$ dbimport test_cp -i backup/ -l
Your evaluation license will expire on 2025-04-22 00:00:00
{ DATABASE test_cp delimiter | }
grant dba to "gbasedbt";
revoke usage on language SPL from public ;
grant usage on language SPL to public ;
dbimport completed
set environment sqlmode 'oracle';
set environment sqlmode 'gbase';