环境模拟
### 使用swingbench模拟业务
[oracle@cesdb3 bin]$ ./charbench -c ../configs/SOE_Server_Side_V2.xml -u soe -p soepassword -uc 10 -cs 192.168.10.8:1521/orcl -min 0 -max 10\
> -intermin 200 -intermax 500 -v "users,tps,dml"
Swingbench
Author : Dominic Giles
Version : 2.7.0.1511
Results will be written to results.xml
Hit Return to Terminate Run...
Time Users TPS Select Insert Update Delete Commit Rollback
09:17:20 [0/10] 0 0 0 0 0 0 0
09:17:21 [10/10] 21 244 23 13 0 21 0
09:17:22 [10/10] 30 616 100 72 0 51 0
09:17:23 [10/10] 30 920 151 97 0 81 0
09:17:24 [10/10] 27 1250 191 131 0 108 0
09:17:25 [10/10] 30 1560 257 179 0 138 0
09:17:26 [10/10] 28 1784 293 202 0 166 0
09:17:27 [10/10] 28 2071 349 243 0 194 0
09:17:28 [10/10] 28 2320 394 272 0 222 0
09:17:29 [10/10] 28 2617 441 305 0 250 0
09:17:30 [10/10] 27 2879 486 336 0 277 0
09:17:31 [10/10] 26 3215 552 383 0 303 0
09:17:32 [10/10] 30 3546 626 449 0 333 0
09:17:33 [10/10] 29 3882 691 501 0 362 0
09:17:34 [10/10] 28 4174 739 539 0 390 0
09:17:35 [10/10] 29 4458 778 565 0 419 0
09:17:36 [10/10] 31 4754 830 606 0 450 0
09:17:37 [10/10] 28 4972 889 637 0 478 0
09:17:38 [10/10] 29 5309 944 684 0 507 0
09:17:39 [10/10] 31 5608 971 706 0 538 0
09:17:40 [10/10] 26 5873 1019 742 0 564 0
09:17:41 [10/10] 28 6113 1065 768 0 592 0
09:17:42 [10/10] 29 6388 1129 816 0 621 0
09:17:43 [10/10] 28 6674 1199 857 0 649 0
### 查看redo文件
SQL> select group#,sequence#,bytes,member,b.status from v$logfile a join v$log b using(group#);
GROUP# SEQUENCE# BYTES MEMBER STATUS
---------- ---------- ---------- ---------------------------------------- ----------------
2 690 209715200 /oradata/ORCL/redo02.log CURRENT
1 689 209715200 /oradata/ORCL/redo01.log INACTIVE
3 688 209715200 /oradata/ORCL/redo03.log INACTIVE
### 删除redo,强制关库
SQL> ! rm -rf /oradata/ORCL/redo*.log
SQL> shu abort
ORACLE instance shut down.
开始恢复
这里感谢大大刺猬提供的xfs文件系统恢复已删除文件的xfs_recovery_v0.3.py脚本,恢复原理可以查看他的文章,这个版本的脚本的话可以去他文章下留言领取
https://www.modb.pro/db/1845729714352254976
### 数据库启动到 mount
SQL> startup mount
ORACLE instance started.
Total System Global Area 2315254288 bytes
Fixed Size 8899088 bytes
Variable Size 1711276032 bytes
Database Buffers 587202560 bytes
Redo Buffers 7876608 bytes
Database mounted.
### 查看日志组
SQL> select group#,sequence#,bytes,member,b.status from v$logfile a join v$log b using(group#);
GROUP# SEQUENCE# BYTES MEMBER STATUS
---------- ---------- ---------- -------------------------------------------------- ----------------
1 689 209715200 /oradata/ORCL/redo01.log INACTIVE
2 690 209715200 /oradata/ORCL/redo02.log CURRENT
3 688 209715200 /oradata/ORCL/redo03.log INACTIVE
可以看到v$log中记录日志文件为209715200字节,但是在操作系统中redo文件显示的大小会+512字节,因为多了个Oracle OS Header Block简称BLOCK 0,而redo块大小为512字节,这个就是多出的BLOCK 0大小
而这个恢复脚本是按操作系统块4k大小来恢复的,所以不足4k的块会补足4k,那么使用这个脚本恢复出来的文件那么就是209715200+4096=209719296大小
[root@cesdb3 tmp]# partprobe
[root@cesdb3 tmp]# python3 xfs_recovery_v0.3.py /dev/mapper/rhel-root|grep 209719296
inode: 137382533 209719296
inode: 137382534 209719296
inode: 137382535 209719296
[root@cesdb3 tmp]# python3 xfs_recovery_v0.3.py /dev/mapper/rhel-root 137382533 /tmp/recover1.log
[root@cesdb3 tmp]# python3 xfs_recovery_v0.3.py /dev/mapper/rhel-root 137382534 /tmp/recover2.log
[root@cesdb3 tmp]# python3 xfs_recovery_v0.3.py /dev/mapper/rhel-root 137382535 /tmp/recover3.log
### 接下来就是将这几个恢复出来的文件怎么和被删除的文件名对应的
### 经过hexdump,发现在redo header的102字节开始,用10个字节存放SEQUENCE#
[root@cesdb3 tmp]# hexdump -s 614 -n 10 -C recover1.log
00000266 30 30 30 30 30 30 30 36 39 30 |0000000690|
00000270
[root@cesdb3 tmp]# hexdump -s 614 -n 10 -C recover2.log
00000266 30 30 30 30 30 30 30 36 38 38 |0000000688|
00000270
[root@cesdb3 tmp]# hexdump -s 614 -n 10 -C recover3.log
00000266 30 30 30 30 30 30 30 36 38 39 |0000000689|
00000270
### 根据以上信息,可以将恢复出来的文件名和删除的文件名对应起来了
[oracle@cesdb3 ~]$ cp /tmp/recover1.log /oradata/ORCL/redo02.log
[oracle@cesdb3 ~]$ cp /tmp/recover2.log /oradata/ORCL/redo03.log
[oracle@cesdb3 ~]$ cp /tmp/recover3.log /oradata/ORCL/redo01.log
### 还有个问题需要解决,那就是实际文件比原来的文件大了(4096 - 512)=3584字节,只要将文件末尾的这些字节截掉就行,经过测试,不截取好像也行
[oracle@cesdb3 ~]$ truncate -s -3584 /oradata/ORCL/redo01.log
[oracle@cesdb3 ~]$ truncate -s -3584 /oradata/ORCL/redo02.log
[oracle@cesdb3 ~]$ truncate -s -3584 /oradata/ORCL/redo03.log
### open数据库
SQL> alter database open;
Database altered.
|