在2023-09-22 15:06:46的时候误删(delete)了一张业务表,需要要紧急恢复,使用全量备份+归档日志的方式恢复整库,再将删除表数据导入到生产库相应表(导入导出单张表可以使用dts迁移数据,可以通过逻辑导出导入表数据)。
①.检查误删数据库的全库备份和归档文件是否连续完整;②.在测试环境新建一个数据库实例;③.传输完整的全库和增量备份到测试库,传输能连接备份数据的归档文件至目标端;④.恢复数据库数据并导出导入误删数据。
我们模拟生产环境,该操作过程包括:初始化实例、数据库的启停、归档模式的配置、准备测试数据和数据库备份等过程。但是不要在生产环境中直接作这样的危险操作。
[dmdba@localhost bin]# ./dminit path=/opt/dmdbms/data page_size=32
[dmdba@localhost bin]# ./dmserver /opt/dmdbms/data/DAMENG/dm.ini
[dmdba@localhost bin]$ ./disql SYSDBA/SYSDBA
ALTER DATABASE MOUNT;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE ADD ARCHIVELOG 'DEST=/opt/dmdbms/data/DAMENG/arch, TYPE=LOCAL, FILE_SIZE=1024, SPACE_LIMIT=51200';
ALTER DATABASE OPEN;
create table T1(C1 varchar(10));
insert into T1(C1) VALUES (1);
insert into T1(C1) VALUES (2);
insert into T1(C1) VALUES (3);
insert into T1(C1) VALUES (4);
insert into T1(C1) VALUES (5);
insert into T1(C1) VALUES (6);
insert into T1(C1) VALUES (7);
insert into T1(C1) VALUES (8);
insert into T1(C1) VALUES (9);
insert into T1(C1) VALUES (10);
commit;
SQL> BACKUP DATABASE BACKUPSET '/opt/dmdbms/data/DAMENG/bak/db_all_bak';
insert into T1(C1) VALUES (11);
insert into T1(C1) VALUES (12);
commit;
[dmdba@localhost DAMENG]$ date
2023年 09月 26日 星期三 15:06:46 CST
delete table T1;
把生产环境的物理备份文件和归档日志问价拷贝到测试环境后,利用备份文件和归档文件进行全库恢复,恢复过程不要在生产环境直接操作,防止误操作带来其他不可挽回的问题。
[dmdba@localhost bin]# ./dminit path=/opt/dmdbms/data page_size=32
RMAN> REPAIR ARCHIVELOG DATABASE '/opt/dmdbms/data/DAMENG/dm.ini';
RMAN> RESTORE DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' FROM BACKUPSET '/opt/dmdbms/data/DAMENG/bak/db_all_bak';
RESTORE DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' FROM BACKUPSET '/opt/dmdbms/data/DAMENG/bak/db_all_bak';
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
[Percent:100.00%][Speed:0.00M/s][Cost:00:00:02][Remaining:00:00:00]
restore successfully.
time used: 00:00:02.281
RMAN> RECOVER DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' WITH ARCHIVEDIR '/opt/dmdbms/data/DAMENG/arch' UNTIL TIME '2023-09-22 15:06:46';
RECOVER DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' WITH ARCHIVEDIR '/opt/dmdbms/data/DAMENG/arch' UNTIL TIME '2023-09-22 15:06:46';
Database mode = 0, oguid = 0
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
EP[0]'s cur_lsn[40342], file_lsn[40342]
[Percent:100.00%][Speed:0.00PKG/s][Cost:00:00:00][Remaining:00:00:00]
recover successfully!
time used: 278.380(ms)
RMAN> RECOVER DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' UPDATE DB_MAGIC;
RECOVER DATABASE '/opt/dmdbms/data/DAMENG/dm.ini' UPDATE DB_MAGIC;
Database mode = 0, oguid = 0
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
EP[0]'s cur_lsn[41837], file_lsn[41837]
recover successfully!
time used: 984.052(ms)
[dmdba@localhost bin]# ./dmserver /opt/dmdbms/data/DAMENG/dm.ini
[dmdba@localhost bin]$ ./disql SYSDBA/SYSDBA
disql V8
服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间 : 1.641(ms)
SQL> select * from T1;
行号 C1
---------- --
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
12 rows got
已用时间: 1.001(毫秒). 执行号:600.
至此,在测试环境中误删除的表数据就全部恢复出来了,接着使用DTS迁移数据工具或通过逻辑导出导入表数据到生产环境即可。
文章
阅读量
获赞