达梦数据库学习笔记之 — 物理备份与恢复
本站文章除注明转载外,均为本站原创: 转载自love wife love life —Roger的Oracle/MySQL/PostgreSQL数据恢复博客
本文链接地址: 达梦数据库学习笔记之 — 物理备份与恢复
针对达梦数据库的物理备份,可以通过disql和dmrman来进行操作,首先配置归档。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
++ mount 实例 [dmdba@mogdb enmotech]$ dmserver mount /opt/dm/dmdbms/data/enmotech/dm.ini file dm.key not found, use default license! version info: develop Use normal os_malloc instead of HugeTLB Use normal os_malloc instead of HugeTLB DM Database Server x64 V8 1-1-126-20.09.04-126608-ENT startup... Database mode = 0, oguid = 0 License will expire on 2021-09-09 file lsn: 85619148 ndct db load finished ndct fill fast pool finished nsvr_startup end. aud sys init success. aud rt sys init success. systables desc init success. ndct_db_load_info success. SYSTEM IS READY. |
数据库归档模式必须在实例mount的情况下打开:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
--配置归档 SQL> alter database archivelog; executed successfully used time: 7.019(ms). Execute id is 0. SQL> ALTER DATABASE ADD ARCHIVELOG 'DEST=/opt/dm/dmarch,TYPE = local,FILE_SIZE=200,SPACE_LIMIT=2048'; executed successfully used time: 4.581(ms). Execute id is 0. SQL> alter database open; executed successfully used time: 00:00:01.789. Execute id is 0. SQL> select version(); select version(); [-2207]:Error in line: 1 Member access [VERSION] unresolved. used time: 1.037(ms). Execute id is 0. SQL> select * from v$version; LINEID BANNER ---------- ------------------------- 1 DM Database Server 64 V8 2 DB Version: 0x7000b used time: 1.129(ms). Execute id is 4. SQL> |
++++ 通过disql 进行数据库全备份
1 2 3 4 |
SQL> backup database full backupset '/opt/dm/dmbak/db_full_20210826_bak_01' parallel 2; executed successfully used time: 00:00:36.553. Execute id is 4. SQL> |
log中会有如下类似记录(实际上disql备份记录会进行log记录,dmrman备份并不会记录在后台日志中):
1 2 3 4 |
2021-08-26 05:03:02.883 [INFO] database P0000017453 T0000000000000017541 backup database full backupset '/opt/dm/dmbak/db_full_20210826_bak_01' parallel 2; 2021-08-26 05:03:02.883 [INFO] database P0000017453 T0000000000000017541 BACKUP DATABASE [enmottch] 2021-08-26 05:03:02.883 [INFO] database P0000017453 T0000000000000017541 CMD START...... 2021-08-26 05:03:39.428 [INFO] database P0000017453 T0000000000000017541 CMD END.CODE:[0] |
接下来我们进行一次增量备份:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
SQL> create table test_incr as select * from dba_objects; executed successfully used time: 71.209(ms). Execute id is 5. SQL> insert into test_incr select * from test_incr; affect rows 1705 used time: 11.900(ms). Execute id is 6. SQL> / affect rows 3410 used time: 15.428(ms). Execute id is 7. SQL> / affect rows 6820 used time: 35.236(ms). Execute id is 8. SQL> / affect rows 13640 used time: 51.031(ms). Execute id is 9. SQL> / affect rows 27280 used time: 96.810(ms). Execute id is 10. SQL> commit; executed successfully used time: 2.096(ms). Execute id is 11. SQL> backup database increment with backupdir '/opt/dm/dmbak/db_increment_bak'; backup database increment with backupdir '/opt/dm/dmbak/db_increment_bak'; [-8036]:No base backup or no base backup matched. used time: 00:00:01.844. Execute id is 0. SQL> backup database increment with backupdir '/opt/dm/dmbak/db_full_20210826_bak_01' backupset '/opt/dm/dmbak/db_increment20210826_bak_01'; executed successfully used time: 00:00:22.118. Execute id is 13. SQL> |
可以看到如果要进行增量备份,必须指定基础全备,否则会报错No base backup的Error。 同样针对增量备份的信息也会在日志中进行简单记录:
1 2 3 4 5 6 |
2021-08-26 05:05:55.948 [ERROR] database P0000017453 T0000000000000017541 CMD END.CODE:[-8036],DESC:[No base backup or no base backup matched] 2021-08-26 05:07:50.845 [INFO] database P0000017453 T0000000000000017541 backup database increment with backupdir '/opt/dm/dmbak/db_full_20210826_bak_01' backupset '/opt/dm/dmbak/db_increment20210826_bak_01'; 2021-08-26 05:07:50.846 [INFO] database P0000017453 T0000000000000017541 BACKUP DATABASE [enmottch] 2021-08-26 05:07:50.846 [INFO] database P0000017453 T0000000000000017541 CMD START...... 2021-08-26 05:08:12.149 [INFO] database P0000017453 T0000000000000017467 ckpt2_log_adjust: ckpt_lsn(85675335), ckpt_fil(0), ckpt_off(2350671360), cur_lsn(85675335), l_next_seq(738460), g_next_seq(738460), cur_free(2350671872), total_space(9437171712), free_space(9437171200), n_ep(1) 2021-08-26 05:08:12.961 [INFO] database P0000017453 T0000000000000017541 CMD END.CODE:[0] |
此外还可以进行基于表空间的备份;当然也支持增量;同时也支持加密,压缩等:
1 2 3 4 |
SQL> backup tablespace enmotech full backupset '/opt/dm/dmbak/ts_enmotech_full20210826_bak_01'; executed successfully used time: 00:00:01.810. Execute id is 14. SQL> |
除此之外还有一一点让我感觉非常有趣的地方是,还可以对表进行备份:
1 2 3 4 |
SQL> backup table benchmarksql.test0826 backupset '/opt/dm/dmbak/tab_test0826_bak'; executed successfully used time: 924.811(ms). Execute id is 15. SQL> |
既然这样的话,那么肯定也支持restore table了。 我们来看看备份文件长什么样。
1 2 3 4 5 6 7 8 9 10 11 12 |
[dmdba@mogdb dm]$ cd dmbak/ [dmdba@mogdb dmbak]$ ls -ltr total 0 drwxr-xr-x. 4 dmdba dinstall 143 Aug 26 05:03 db_full_20210826_bak_01 drwxr-xr-x. 2 dmdba dinstall 126 Aug 26 05:08 db_increment20210826_bak_01 drwxr-xr-x. 2 dmdba dinstall 93 Aug 26 05:12 ts_enmotech_full20210826_bak_01 drwxr-xr-x. 2 dmdba dinstall 63 Aug 26 05:15 tab_test0826_bak [dmdba@mogdb dmbak]$ cd tab_test0826_bak [dmdba@mogdb tab_test0826_bak]$ ls -ltr total 96 -rw-r--r--. 1 dmdba dinstall 29184 Aug 26 05:15 tab_test0826_bak.bak -rw-r--r--. 1 dmdba dinstall 62976 Aug 26 05:15 tab_test0826_bak.meta |
可以看到这里实际上产生了2个备份文件。通过strings meta文件发现里面是元数据信息:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
[dmdba@mogdb tab_test0826_bak]$ strings tab_test0826_bak.meta ]"]6 V7.1.7.126-Build(2020.09.04-126608)ENT /opt/dm/dmdbms/data/enmotech TAB_BTREE_20210826_051522_323393 tab_test0826_bak enmottch #<L=W #DaMeng Database Server Configuration file #this is comments #file location of dm.ctl CTL_PATH = /opt/dm/dmdbms/data/enmotech/dm.ctl #ctl file path CTL_BAK_PATH = /opt/dm/dmdbms/data/enmotech/ctl_bak #dm.ctl backup path CTL_BAK_NUM = 10 #backup number of dm.ctl, allowed to keep one more backup file besides specified number. SYSTEM_PATH = /opt/dm/dmdbms/data/enmotech #system path ...... tab_test0826_bak.bak (D~K `0L%~ `0L%~ ts_enmotech_full20210826_bak_01.meta ENABLE_ADJUST_NLI_COST = 1 #Whether adjust TEST0826 BENCHMARKSQL MAIN BENCHMARKSQL' CREATE SCHEMA "%s" AUTHORIZATION "%s" ;V CREATE TABLE "TEST0826" "A" INT, "B" VARCHAR2(20)) STORAGE(ON "MAIN", NOBRANCH) |
另外一个bak文件应该就是存放实际数据了。
1 2 3 4 5 6 7 |
[dmdba@mogdb tab_test0826_bak]$ strings tab_test0826_bak.bak ]"]6 V7.1.7.126-Build(2020.09.04-126608)ENT Parameter[%s] has setup, repeat setting is not allowed Parameter [%s]'s value[%s] Inval www.enmotech.com [dmdba@mogdb tab_test0826_bak]$ |
接下来我们来验证一下表的备份恢复(通过disql来进行):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
SQL> select * from benchmarksql.test0826; LINEID A B ---------- ----------- ---------------- 1 10 www.enmotech.com used time: 1.044(ms). Execute id is 16. SQL> drop table benchmarksql.test0826; executed successfully used time: 62.535(ms). Execute id is 17. SQL> backup table benchmarksql.test0826 backupset '/opt/dm/dmbak/tab_test0826_bak'; executed successfully used time: 924.811(ms). Execute id is 15. SQL> select * from benchmarksql.test0826; LINEID A B ---------- ----------- ---------------- 1 10 www.enmotech.com used time: 1.044(ms). Execute id is 16. SQL> drop table benchmarksql.test0826; executed successfully used time: 62.535(ms). Execute id is 17. SQL> restore table benchmarksql.test0826 from backupset '/opt/dm/dmbak/tab_test0826_bak'; restore table benchmarksql.test0826 from backupset '/opt/dm/dmbak/tab_test0826_bak'; [-2106]:Error in line: 1 Invalid table or view name [TEST0826]. used time: 0.750(ms). Execute id is 0. SQL> SQL> CREATE TABLE benchmarksql.test0826("A" INT, "B" VARCHAR2(20)) STORAGE(ON "MAIN", NOBRANCH) ; executed successfully used time: 8.810(ms). Execute id is 18. SQL> restore table benchmarksql.test0826 from backupset '/opt/dm/dmbak/tab_test0826_bak'; executed successfully used time: 53.326(ms). Execute id is 19. SQL> SQL> SQL> truncate table benchmarksql.test0826; executed successfully used time: 6.999(ms). Execute id is 20. SQL> restore table benchmarksql.test0826 from backupset '/opt/dm/dmbak/tab_test0826_bak'; executed successfully used time: 46.922(ms). Execute id is 21. SQL> select * from benchmarksql.test0826; LINEID A B ---------- ----------- ---------------- 1 10 www.enmotech.com used time: 1.592(ms). Execute id is 22. |
从测试来看,对于drop table的情况,是无法直接恢复的,需要先创建表空间,通过strings 备份文件即可获得表结构;对于truncate table的情况,可以直接restore恢复。从这个操作来看,更像是一个逻辑层的insert into或者类似oracle sqlldr 数据加载的恢复操作方式。
对于数据备份的restore 还原操作;disql 工具只能支持对于表的操作,不支持数据库级别/表空间级别或者schema级别。
如果要进行数据库级别,tablespace等级别的还原和恢复操作,那么需要使用dmrman 工具。接下里玩一玩!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
[dmdba@mogdb ~]$ dmrman dmrman V8 RMAN> CONFIGURE help [-8301]:line [1],col [10] and nearby [help] exists error[-2007]:Syntax error RMAN> CONFIGURE; THE DMRMAN DEFAULT SETTING: DEFAULT DEVICE: MEDIA : DISK DEFAULT TRACE : FILE : LEVEL : 1 DEFAULT BACKUP DIRECTORY: TOTAL COUNT :0 DEFAULT ARCHIVE DIRECTORY: TOTAL COUNT :0 time used: 1.433(ms) RMAN> CONFIGURE TRACE 2 [-8301]:line [1],col [10] and nearby [TRACE] exists error[-2007]:Syntax error RMAN> CONFIGURE DEFAULT TRACE LEVEL 2; configure default trace successfully! time used: 0.091(ms) RMAN> CONFIGURE DEFAULT TRACE FILE '/opt/dm/dmbak/trace'; configure default trace successfully! time used: 0.507(ms) RMAN> CONFIGURE DEFAULT BACKUPDIR '/opt/dm/dmbak/'; configure default backupdir update successfully! DEFAULT BACKUP DIRECTORY: TOTAL COUNT :1 /opt/dm/dmbak time used: 0.627(ms) RMAN> CONFIGURE DEFAULT ARCHIVEDIR '/opt/dm/dmarch'; configure default archivedir update successfully! DEFAULT ARCHIVE DIRECTORY: TOTAL COUNT :1 /opt/dm/dmarch time used: 1.116(ms) RMAN> RMAN> backup database '/opt/dm/dmdbms/data/enmotech/dm.ini' ; backup database '/opt/dm/dmdbms/data/enmotech/dm.ini'; file dm.key not found, use default license! [-137]:DM server is running or exist other process which is operating the same database RMAN> |
dmrman类似Oracle rman一样,可以进行一些配置,如上所示,比如目录,备份存储形式(tape,disk),包括trace等。
由于dmrman是脱机备份工具,因此数据库必须是关闭状态,否则会报错;这里我先把库停掉。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
[dmdba@mogdb log]$ DmServicedmdb stop Stopping DmServicedmdb: [ OK ] [dmdba@mogdb log]$ [dmdba@mogdb ~]$ dmrman dmrman V8 RMAN> backup database '/opt/dm/dmdbms/data/enmotech/dm.ini' ; backup database '/opt/dm/dmdbms/data/enmotech/dm.ini'; file dm.key not found, use default license! Database mode = 0, oguid = 0 EP[0]'s cur_lsn[85675643] BACKUP DATABASE [enmottch],execute...... CMD CHECK LSN...... BACKUP DATABASE [enmottch],collect dbf...... CMD CHECK ...... DBF BACKUP SUBS...... total 1 packages processed... total 16 packages processed... total 148 packages processed... total 276 packages processed... total 282 packages processed... DBF BACKUP MAIN...... BACKUPSET [/opt/dm/dmdbms/data/enmotech/bak/DB_enmottch_FULL_20210826_054644_098866] END, CODE [0]...... META GENERATING...... total 284 packages processed... total 284 packages processed... total 284 packages processed! CMD END.CODE:[0] backup successfully! time used: 00:00:21.388 RMAN> RMAN> backup database '/opt/dm/dmdbms/data/enmotech/dm.ini' increment with backupdir '/opt/dm/dmbak' BACKUPSET '/opt/dm/dmbak/db_increment_bak_02'; backup database '/opt/dm/dmdbms/data/enmotech/dm.ini' increment with backupdir '/opt/dm/dmbak' BACKUPSET '/opt/dm/dmbak/db_increment_bak_02'; Database mode = 0, oguid = 0 EP[0]'s cur_lsn[85675643] BACKUP DATABASE [enmottch],execute...... CMD CHECK LSN...... BACKUP DATABASE [enmottch],collect dbf...... CMD CHECK ...... DBF BACKUP SUBS...... total 1 packages processed... total 16 packages processed... total 90 packages processed... total 148 packages processed... total 276 packages processed... total 282 packages processed... DBF BACKUP MAIN...... BACKUPSET [/opt/dm/dmbak/db_increment_bak_02] END, CODE [0]...... META GENERATING...... total 284 packages processed... total 284 packages processed... total 284 packages processed! CMD END.CODE:[0] backup successfully! time used: 00:00:13.537 |
在脱机情况下才能通过dmrman进行备份,如果做全备份,数据库还必须是正常停机,如果是异常情况下,那么还需要先进行修复到一致状态才能进行备份。 这让人难以理解?
如果只能在脱机情况下进行备份,那么要这个有何用?查询了一下dm的官方文档,发现确实是这样说的:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
创建完全备份 执行数据库备份要求数据库处于脱机状态。若是正常退出的数据库,则脱机备份前不需要配置归档;若是故障退出的数据库,则备份前,需先进行归档修复。以正常退出的数据库为例,一个完整的创建脱机数据库备份的步骤如下: 保证数据库处于脱机状态; 启动DMRMAN命令行工具; DMRMAN中输入以下命令: RMAN>BACKUP DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' FULL BACKUPSET '/home/dm_bak/db_full_bak_01'; 命令中的FULL参数表示执行的备份为完全备份,也可以不指定该参数,DMRMAN默认执行的备份类型为完全备份。 创建增量备份 增量备份指基于指定的库的某个备份(完全备份或者增量备份),备份自该备份以来所有发生修改了的数据页。脱机增量备份要求两次备份之间数据库必须有操作,否则备份会报错。 创建归档备份 执行归档备份要求数据库处于脱机状态。与联机归档备份一样,脱机归档备份需要配置归档。 |
达梦官方文档链接:https://eco.dameng.com/docs/zh-cn/pm/backup-restore-combat.html
查看文档发现dmrman还支持一些show和check,repair等命令,在恢复时可以用到:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
RMAN> check backupset '/opt/dm/dmdbms/data/enmotech/bak/DB_enmottch_FULL_20210826_054644_098866'; check backupset '/opt/dm/dmdbms/data/enmotech/bak/DB_enmottch_FULL_20210826_054644_098866'; CMD END.CODE:[0] check backupset successfully. time used: 89.174(ms) RMAN> check backupset '/opt/dm/dmbak/db_increment_bak_02'; check backupset '/opt/dm/dmbak/db_increment_bak_02'; CMD END.CODE:[0] check backupset successfully. time used: 25.830(ms) RMAN> show backupset '/opt/dm/dmdbms/data/enmotech/bak/DB_enmottch_FULL_20210826_054644_098866'; show backupset '/opt/dm/dmdbms/data/enmotech/bak/DB_enmottch_FULL_20210826_054644_098866'; <backupset [DEVICE TYPE:DISK, BACKUP_PATH: /opt/dm/dmdbms/data/enmotech/bak/DB_enmottch_FULL_20210826_054644_098866] info start ..........> <DB INFO> system path: /opt/dm/dmdbms/data/enmotech pmnt_magic: 272050232 src_db_magic: 148545590 db_magic: 148545590 dsc node: 1 sys mode: 0 page check: 0 rlog encrypt: 0 external cipher[id/name]: 0/ external hash[id/name]: 0/ length in char: 0 use new hash: 1 page size: 8KB extent size: 16 case sensitive: 1 log page size: 512B unicode_flag/charset: 0 data version: 0x7000B sys version: V8 enable policy: 0 archive flag: 1 blank_pad_mode: 0 crc_check: TRUE page_enc_slice_size: 0 <META INFO> backupset sig: BA backupset version: 0x400A database name: enmottch backup name: DB_FULL_20210826_054644_098866 backupset description: n_magic: 0x392E7BA0 parent n_magic: 0xFFFFFFFF meta file size : 82432 compressed level: 0 encrypt type: 0 parallel num: 1 backup range: database mpp_timestamp: 1629982003 with_huge: FALSE backupset_type: NORMAL mpp_flag: FALSE backup level: offline backup type: full without log: FALSE end_lsn: 85675643 max_trxid: 85675402 base begin_lsn: -1 base end_lsn: -1 base n_magic: 0xFFFFFFFF base name: base backupset: backup time: 2021-08-26 05:47:05 min exec ver: 0x08010101 min dct ver: 4 pkg size: 0x02000000 <EP INFO> EP[0]: begin_pkg_seq: 738489 begin_lsn: 85675643 end_pkg_seq: 738489 end_lsn: 85675643 <FILE INFO> backupset directory: /opt/dm/dmdbms/data/enmotech/bak/DB_enmottch_FULL_20210826_054644_098866 backupset name: DB_enmottch_FULL_20210826_054644_098866 backup data file num: 5 backup piece num: 1 backup huge file num: 0 <backup_piece_list> $file_seq |$size(KB) |$pos_desc |$content_type 0 |4456417 |DB_enmottch_FULL_20210826_054644_098866.bak |DATA <data_file_list> $file_seq |$group_id |$group_name |$file_id |$file_path |$mirror_path |$file_len |$copy_num |$size_flag 1 |0 |SYSTEM |0 |/opt/dm/dmdbms/data/enmotech/SYSTEM.DBF| |25165824 |0 |0 2 |1 |ROLL |0 |/opt/dm/dmdbms/data/enmotech/ROLL.DBF| |485490688 |0 |0 3 |4 |MAIN |0 |/opt/dm/dmdbms/data/enmotech/MAIN.DBF| |4426039296 |0 |0 4 |5 |ENMOTECH |0 |/opt/dm/dmdbms/data/enmotech/enmotech01.dbf| |4273995776 |0 |0 5 |5 |ENMOTECH |1 |/opt/dm/dmdbms/data/enmotech/enmotech02.dbf| |202375168 |0 |0 <arch_file_list> $file_seq |$dsc_seq |$file_len |$begin_seqno |$begin_lsn |$end_seqno |$end_lsn <huge_file_list> $group_id |$schema_id|$table_id |column_id |$file_id |$file_len |$path <backupset [DEVICE TYPE:DISK, BACKUP_PATH: /opt/dm/dmdbms/data/enmotech/bak/DB_enmottch_FULL_20210826_054644_098866] info end .> show backupsets successfully. time used: 16.419(ms) RMAN> |
这里我创建一个测试表空间来进行备份恢复验证一下该工具的具体使用。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
SQL> create tablespace test_recover datafile '/opt/dm/dmdbms/data/enmotech/test_recover.dbf' size 128; executed successfully used time: 27.254(ms). Execute id is 6. SQL> create table test_rec tablespace test_recover as select * from dba_objects where rownum=1; executed successfully used time: 30.473(ms). Execute id is 7. SQL> select * from test_rec; LINEID OWNER OBJECT_NAME SUBOBJECT_NAME OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE CREATED ---------- ------------ ------------ -------------- --------- -------------- ----------- ---------------------------------------------------------------------------------------------------- LAST_DDL_TIME ---------------------------------------------------------------------------------------------------- TIMESTAMP STATUS TEMPORARY GENERATED SECONDARY NAMESPACE EDITION_NAME ---------------------------------------------------------------------------------------------------- ------ --------- --------- --------- --------- ------------ 1 BENCHMARKSQL BENCHMARKSQL NULL 150995945 NULL SCH 2021-08-26 17:45:42.091959 NULL NULL VALID N NULL NULL NULL NULL used time: 1.075(ms). Execute id is 8. SQL> backup tablespace test_recover full backupset '/opt/dm/dmbak/ts_test_recover_20210826_bak_01'; executed successfully used time: 820.217(ms). Execute id is 9. SQL> drop tablespace test_recover; drop tablespace test_recover; [-3412]:Try to drop used tablespace. used time: 5.893(ms). Execute id is 0. SQL> alter tablespace TEST_RECOVER offline; executed successfully used time: 101.733(ms). Execute id is 13. SQL> select name,STATUS$,TOTAL_SIZE from v$tablespace; LINEID NAME STATUS$ TOTAL_SIZE ---------- ------------ ----------- -------------------- 1 SYSTEM 0 3072 2 ROLL 0 59264 3 TEMP 0 131072 4 MAIN 0 540288 5 ENMOTECH 0 546432 6 TEST_RECOVER 1 16384 6 rows got used time: 1.737(ms). Execute id is 15. SQL> host [dmdba@mogdb log]$ rm -rf /opt/dm/dmdbms/data/enmotech/test_recover.dbf [dmdba@mogdb log]$ exit exit SQL> shutdown immediate 2 ; executed successfully used time: 0.415(ms). Execute id is 0. SQL> |
停掉数据库之后,我们开始用dmrman来进行恢复被删除的表空间文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
[dmdba@mogdb ~]$ dmrman dmrman V8 RMAN> restore database '/opt/dm/dmdbms/data/enmotech/dm.ini' tablespace test_recover from backupset '/opt/dm/dmbak/ts_test_recover_20210826_bak_01'; restore database '/opt/dm/dmdbms/data/enmotech/dm.ini' tablespace test_recover from backupset '/opt/dm/dmbak/ts_test_recover_20210826_bak_01'; RESTORE TABLESPACE[test_recover] IN DB[/opt/dm/dmdbms/data/enmotech/dm.ini] CHECK...... Database mode = 0, oguid = 0 EP[0]'s cur_lsn[85676271] RESTORE TABLESPACE[test_recover] IN DB[/opt/dm/dmdbms/data/enmotech/dm.ini],dbf collect...... RESTORE TABLESPACE[test_recover] IN DB[/opt/dm/dmdbms/data/enmotech/dm.ini],ts status and dbf refresh ...... RESTORE BACKUPSET [/opt/dm/dmbak/ts_test_recover_20210826_bak_01] START...... total 1 packages processed... total 3 packages processed... RESTORE TABLESPACE[test_recover] IN DB[/opt/dm/dmdbms/data/enmotech/dm.ini],UPDATE ctl file...... total 3 packages processed... total 3 packages processed! CMD END.CODE:[0] restore successfully. time used: 332.263(ms) RMAN> recover database '/opt/dm/dmdbms/data/enmotech/dm.ini' tablespace test_recover; recover database '/opt/dm/dmdbms/data/enmotech/dm.ini' tablespace test_recover; Database mode = 0, oguid = 0 [WARN]tablespace TEST_RECOVER is corrupted(state: 2), restore or drop please. EP[0]'s cur_lsn[85676271] RECOVER TABLESPACE[test_recover] IN DB[/opt/dm/dmdbms/data/enmotech/dm.ini] CHECK...... EP[0]'s cur_lsn[85676271] EP:0 total 4 pkgs applied, percent: 11% EP:0 total 8 pkgs applied, percent: 23% EP:0 total 12 pkgs applied, percent: 35% EP:0 total 16 pkgs applied, percent: 47% EP:0 total 20 pkgs applied, percent: 58% EP:0 total 24 pkgs applied, percent: 70% EP:0 total 28 pkgs applied, percent: 82% EP:0 total 32 pkgs applied, percent: 94% EP:0 total 34 pkgs applied, percent: 100% Recover from archive log finished, time used:0.020s. CMD END.CODE:[0] recover successfully. time used: 526.667(ms) RMAN> |
接下来我们启动数据库验证一下恢复数据恢复结果如何。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
[dmdba@mogdb log]$ DmServicedmdb start Starting DmServicedmdb: [ OK ] [dmdba@mogdb log]$ ls -ltr /opt/dm/dmdbms/data/enmotech/test_recover* -rw-r--r--. 1 dmdba dinstall 134217728 Aug 26 06:15 /opt/dm/dmdbms/data/enmotech/test_recover.dbf [dmdba@mogdb log]$ disql disql V8 username: password: Server[LOCALHOST:5236]:mode is normal, state is open login used time : 5.687(ms) SQL> select name,STATUS$,TOTAL_SIZE from v$tablespace; LINEID NAME STATUS$ TOTAL_SIZE ---------- ------------ ----------- -------------------- 1 SYSTEM 0 3072 2 ROLL 0 59264 3 TEMP 0 131072 4 MAIN 0 540288 5 ENMOTECH 0 546432 6 TEST_RECOVER 0 16384 6 rows got used time: 6.705(ms). Execute id is 4. SQL> select OWNER,object_name,object_id from test_rec; LINEID OWNER OBJECT_NAME OBJECT_ID ---------- ------------ ------------ --------- 1 BENCHMARKSQL BENCHMARKSQL 150995945 used time: 2.602(ms). Execute id is 5. SQL> |
表空间被自动online了。
最开始翻了一个文档,说是要启动dmap服务;我这里确实没启动;先启动服务。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
[dmdba@mogdb root]$ DmServicedmdb stop Stopping DmServicedmdb: [ OK ] [dmdba@mogdb root]$ DmServicedmdb start Starting DmServicedmdb: [ OK ] [dmdba@mogdb root]$ DmAPService start Starting DmAPService: [ OK ] [dmdba@mogdb root]$ [dmdba@mogdb log]$ ps -ef|grep amap dmdba 19626 16924 0 06:49 pts/1 00:00:00 grep --color=auto amap [dmdba@mogdb log]$ ps -ef|grep dmap dmdba 19552 1 0 06:44 pts/1 00:00:00 /opt/dmdbms/bin/dmap dmdba 19628 16924 0 06:49 pts/1 00:00:00 grep --color=auto dmap [dmdba@mogdb log]$ 再次测试dmrman能否进行联机恢复: SQL> backup tablespace test_recover full backupset '/opt/dm/dmbak/ts_test_recover_20210826_bak_02'; executed successfully used time: 818.856(ms). Execute id is 106. SQL> alter tablespace TEST_RECOVER offline; executed successfully used time: 98.804(ms). Execute id is 107. SQL> host [dmdba@mogdb log]$ rm -rf /opt/dm/dmdbms/data/enmotech/test_recover.dbf [dmdba@mogdb log]$ [dmdba@mogdb ~]$ dmrman use_ap=1 dmrman V8 RMAN> restore database '/opt/dm/dmdbms/data/enmotech/dm.ini' tablespace test_recover from backupset '/opt/dm/dmbak/ts_test_recover_20210826_bak_02'; restore database '/opt/dm/dmdbms/data/enmotech/dm.ini' tablespace test_recover from backupset '/opt/dm/dmbak/ts_test_recover_20210826_bak_02'; file dm.key not found, use default license! [-137]:DM server is running or exist other process which is operating the same database RMAN> |
尽管启动了dmap服务,可以看到,仍然是不行的。可以通过disql来进行全备份。但是就恢复而言,通过dmrman进行,只能脱机操作。
最后简单总结一下物理备份恢复:
1、通过参数bak_use_ap来控制是否需要通过dmap进行来进行辅助,便于进行联机热备;联机备份只能通过disql进行。
2、disql 备份支持数据库级别,表空间级别,用户级别以及 table级别;
3、disql的恢复操作,只能支持表级别;不支持全库或者表空间级别;
4、dmrman备份恢复工具是脱机备份恢复工具;这跟Oracle RMAN差距较大;
5、达梦数据库仅支持表的联机还原,数据库、表空间和归档日志的还原必须通过脱机工具DMRMAN执行。
如果数据库运行中,其中一个文件或者表空间有问题,需要进行备份恢复,那么达梦似乎就无法应对这情况了,只能把实例停掉。。。
Leave a Reply
You must be logged in to post a comment.