Physical backup and recovery of Dameng database_ Part6

Posted by hurricane on Tue, 08 Feb 2022 22:30:28 +0100

Refer to DM8 backup and recovery manual (version 1-1-190)

Scenario in which the active and standby clusters are restored to a single machine

Restore the archived log files of the primary database and the standby database to the stand-alone database.

Environmental description

OS: Linux

DB_VERSION: DM8 1-1-190-21.04.16-137954-ENT Pack4

The primary and standby clusters use the backup database archive to restore and recover

The first step is to back up in the main library

[dmdba@localhost bin]$ ./disql
disql V8
 user name:
password:

The server[LOCALHOST:5236]:The main library is open
 Login usage time : 5.839(ms)
SQL>
SQL> create table t as select * from dba_objects;
Operation executed
 Elapsed time: 742.287(millisecond). Execution number:400.
SQL> select count(*) from t;

Line number     COUNT(*)            
---------- --------------------
1          1365

Elapsed time: 4.000(millisecond). Execution number:402.

---Perform backup
SQL> backup database full backupset '/home/dmdba/DB_BAK_FULL01';
Operation executed
 Elapsed time: 00:00:03.972. Execution number:404.

---Create two more tables after the backup is complete
SQL> create table ttt as select * from dba_objects;
Operation executed
 Elapsed time: 68.788(millisecond). Execution number:500.
SQL> create table tt as select * from dba_objects;
Operation executed
 Elapsed time: 89.548(millisecond). Execution number:507.
SQL> select count(*) from ttt;

Line number     COUNT(*)            
---------- --------------------
1          1367

Elapsed time: 0.778(millisecond). Execution number:601.
SQL> select count(*) from tt;

Line number     COUNT(*)            
---------- --------------------
1          1369

Elapsed time: 1.011(millisecond). Execution number:602.
SQL> exit

The standby database switches online logs and executes checkpoint to generate archive logs.

Step 2: copy the backup files and backup archive logs to the destination database

[dmdba@localhost ~]$ scp -r DB_BAK_FULL01 192.168.15.50:/home/dmdba
dmdba@192.168.15.50's password: 
DB_BAK_FULL01.bak              100%   27MB  32.8MB/s   00:00    
DB_BAK_FULL01_1.bak            100%   11KB   5.3MB/s   00:00    
DB_BAK_FULL01.meta             100%   81KB  23.5MB/s   00:00 

[dmdba@localhost arch]$ scp *.log 192.168.15.50:/data/dmarch/stb_arch
dmdba@192.168.15.50's password: 
STANDBY_ARCHIVE_0x137E5B0D[0]_2021-05-11_18-30-39.log       100%  25KB  7.8MB/s  00:00   
STANDBY_ARCHIVE_0x137E5B0D[0]_2021-05-11_18-35-34.log       100%  128MB 57.5MB/s 00:02  

The third step is to restore in the single machine destination database

It should be noted that:

By default, in the recovery phase, only the database DB to be recovered is collected when collecting archives_ MAGIC,PERMANENT_MAGIC consistent archive files, while permannet in the active and standby environment_ Magic is consistent. At this time, you can specify the DB of the archive log of the standby database_ Magic skips this limit if DB is not specified_ Magic will report an error.

(1) You can use DMRMAN to view the DB of the backup file of the primary database first_ Magic value:

RMAN> show backupset '/home/dmdba/DB_BAK_FULL01';
show backupset '/home/dmdba/DB_BAK_FULL01';

<backupset [DEVICE TYPE:DISK, BACKUP_PATH: /home/dmdba/DB_BAK_FULL01] info start ..........>

<DB INFO>
system path:           /dm/dm134/data/DAMENG
pmnt_magic:            197080140
src_db_magic:          327047949
db_magic:              327047949    ---Of backup files DB_MAGIC
dsc node:              1
sys mode:              1
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:             16KB
extent size:           16
case sensitive:        1
log page size:         512B
unicode_flag/charset:  1
data version:          0x7000C
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:         DAMENG
backup name:           DB_FULL_20210511_182553_195320
backupset description: 
n_magic:               0x3F029C24
parent n_magic:        0xFFFFFFFF
meta file size :       82432
compressed level:      0
encrypt type:          0
parallel num:          1
backup range:          database
mpp_timestamp:         1620728753
with_huge:             FALSE
backupset_type:        NORMAL
mpp_flag:              FALSE
backup level:          online
backup type:           full
without log:           FALSE
end_lsn:               49319
max_trxid:             48413
base begin_lsn:        -1
base end_lsn:          -1
base n_magic:          0xFFFFFFFF
base name:             
base backupset:        
backup time:           2021-05-11 18:25:57
min exec ver:          0x08010101
min dct ver:           4
pkg size:              0x02000000

<EP INFO>
EP[0]:
begin_pkg_seq:         4077
begin_lsn:             49304
end_pkg_seq:           4086
end_lsn:               49319

<FILE INFO>
backupset directory: /home/dmdba/DB_BAK_FULL01
backupset name:        DB_BAK_FULL01
backup data file num:  4
backup piece num:      2
backup huge file num:  0

<backup_piece_list>
$file_seq |$size(KB) |$pos_desc                                               |$content_type
0         |27430     |DB_BAK_FULL01.bak                                       |DATA      
1         |11        |DB_BAK_FULL01_1.bak                                     |LOG       

<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         |/dm/dm134/data/DAMENG/SYSTEM.DBF |                                 |45088768            |0         |0         
2         |1         |ROLL            |0         |/dm/dm134/data/DAMENG/ROLL.DBF   |                                 |134217728           |0         |0         
3         |4         |MAIN            |0         |/dm/dm134/data/DAMENG/MAIN.DBF   |                                 |134217728           |0         |0         

<arch_file_list>
$file_seq |$dsc_seq |$file_len           |$begin_seqno        |$begin_lsn          |$end_seqno          |$end_lsn            
4         |0        |6144                |4077                |49304               |4086                |49319               

<huge_file_list>
$group_id |$schema_id|$table_id |$column_id|$file_id  |$file_len |$path

<backupset [DEVICE TYPE:DISK, BACKUP_PATH: /home/dmdba/DB_BAK_FULL01] info end .>
show backupsets successfully.
time used: 26.900(ms)
RMAN> 

(2) Use the dmrachk tool to view the DB of the backup archive log file_ Magic value:

[dmdba@localhost bin]$ ./dmrachk help
rachk V8
 format: dmrachk keyword=value

routine: dmrachk arch_fil=/opt/a.log

Mandatory parameters: Must specify arch_fil perhaps arch_path

keyword              explain(Default value)
--------------------------------------------------------------------------------
ARCH_FIL            Specify an archive
CMP_FIL             Specify an archive for comparison
ARCH_PATH           Specify an archive directory
CMP_PATH            Specify an archive directory for comparison
TRUNC_FIL           Specify a new file to store valid data extracted from the error archive.
EXTRACT_FIL         Specify a new file to store the data from the specified seq Extract data from a range of archive files
ARCH_BAK_PATH       Specify the backup file path to store duplicate files during archive repair
CHECK               Verification level(0, 1, 2, 3, 4) 0: File verification, 1: Package verification(seq & magic),2: ptx Verification, 3: rrec check, 4: Clean up invalid archive files,default(0)
BEGIN_LSN           When specifying the archive directory, specify exclude less than that LSN Documents
END_LSN             When the specified archive directory is larger than the specified archive directory, exclude LSN Documents
BEGIN_SEQ           When specifying the archive directory, the extraction is greater than this SEQ Documents
END_SEQ             When specifying the archive directory, extract less than SEQ Documents
BEFORE_LSN          CHECK=4,Specify the archive directory and delete it LSN Previous documents. Default = 0, all LSN Delete all logs within the scope
BEFORE_SEQ          CHECK=4,Specify the archive directory and delete it SEQ Previous documents. Default = 0, all SEQ Delete all logs within the scope
BEFORE_TIME         CHECK=4,Specify the time point before deleting the file in the directory. Delete archives at all time points by default
EXCLUDE_DB_MAGIC    CHECK=4,Specify the archive directory and delete the specified DB_MAGIC Other documents.
OUTPUT_FIL          LOG You can specify output to a file
DCR_INI             appoint dmdcr.ini Path, if not specified, is not used
DM_INI              Target library dm.ini Path to get log encryption information
AFTER_FREE          appoint TRUNC_FIL Whether to check and extract FREE What follows. 0 no extraction; 1 extraction. Default 0
HELP                display help information

[dmdba@localhost bin]$ ./dmrachk ARCH_PATH=/data/dmarch/stb_arch
rachk V8
the database pmnt_magic: 197080140
the database db_magic: 1125819454
/*******************************************************************/
Archive file/data/dmarch/stb_arch/STANDBY_ARCHIVE_0x137E5B0D[0]_2021-05-11_18-30-39.log detailed.
version        : 0x7006
status         : INACTIVE
enc_flag       : FALSE
n_rpkgs        : 2
pmnt_magic     : 197080140
db_magic       : 1125819454    ---Of backup archive log files DB_MAGIC
src_db_magic   : 327047949
arch_lsn       : 50279
arch_seq       : 4102
clsn           : 50510
next_seq       : 4103
g_next_seq     : 4103
file len       : 25088
file free      : 25088
dsc seqno      : 0
dsc node       : 1
create time    : 2021-05-11 20:45:58.000000
close time     : 2021-05-11 18:31:54.429738
/*******************************************************************/
/*******************************************************************/
Archive file/data/dmarch/stb_arch/STANDBY_ARCHIVE_0x137E5B0D[0]_2021-05-11_18-35-34.log detailed.
version        : 0x7006
status         : ACTIVE
enc_flag       : FALSE
n_rpkgs        : 16
pmnt_magic     : 197080140
db_magic       : 1125819454
src_db_magic   : 327047949
arch_lsn       : 50511
arch_seq       : 4104
clsn           : 51779
next_seq       : 4119
g_next_seq     : 4119
file len       : 134217728
file free      : 168960
dsc seqno      : 0
dsc node       : 1
create time    : 2021-05-11 18:31:54.429738
close time     : 2021-05-11 18:35:34.056232
/*******************************************************************/

Summary (node)[0]):
total: 2 Files
 correct: 2 Files
 error: 0 Files
 repeat: 0 Files

the rachk tool running cost 2.969 ms

(3) Start restore

RMAN> restore database '/data/dmdata/TEST2/dm.ini' from backupset '/home/dmdba/DB_BAK_FULL01';

(4) Start recovery

If you do not specify the DB of the backup archive file_ Magic, using the default DB_ Magic (that is, DB_MAGIC of the primary database, DB_MAGIC in the backup file of the primary database, and src_db_magic in the archive log of the backup database) will report an error. As follows:

Specifies the DB of the archive_ Magic performs recovery:

RMAN> recover database '/data/dmdata/TEST2/dm.ini' with archivedir '/data/dmarch/stb_arch' use db_magic 1125819454;

Update DB_MAGIC:

RMAN>  recover database '/data/dmdata/TEST2/dm.ini' update db_magic;

Step 4 start the database and OPEN to verify the data

After the main database backup is restored to a single machine, it can only be started to mount state by default. You need to change the database to normal mode and OPEN manually.

SQL> alter database normal;
SQL> alter database open;
SQL> select count(*) from t; 
SQL> select count(*) from ttt;
SQL> select count(*) from tt;

At this point, the restore is complete.

epilogue

The scenario in which the primary and standby clusters use the backup archive for recovery is quite practical. After the primary archive is deleted, we can use the backup archive log to restore the data to the latest state.
When using the backup file of the primary database + the archive log of the standby database for restore and recovery, you need to specify the DB of the archive log file of the standby database during recovery_ Magic, if DB is not specified_ Magic will report an error. Because by default, only the database DB to be recovered is collected during archive collection in the RECOVER phase_ MAGIC,PERMANENT_MAGIC consistent archive files, while permannet in the active and standby environment_ Magic is consistent, so you need to specify DB_MAGIC to skip this limit.