1. 程式人生 > 其它 >【DATAGUARD】Oracle 通過Dataguard指定恢復時間用於找回丟失資料

【DATAGUARD】Oracle 通過Dataguard指定恢復時間用於找回丟失資料

一朋友公司環境,因測試庫、生產庫錯連,造成大批量資料丟失,通過Oracle資料庫回收站方式已找回絕大部分資料,還有部分資料丟失, 檢視dg備端,發現備端歸檔都在,但沒有應用到資料庫裡。 可通過指定時間方式,先恢復資料庫到刪除之前的節點。 參考命令如下:

  1. #示例為19c dg
  2. #因操作不當,誤刪除了一個pdb,根據刪除時間,通過備端進行恢復
  3. 2021-07-22T15:55:44.291222+08:00
  4. drop pluggable database testpdb including datafiles
  5. 2021-07-22T15:55:55.145297+08:00
  6. Deleted file /u01/app/oracle/oradata/MYDB19C/testpdb/testpdb_user01.dbf
  7. 2021-07-22T15:55:56.436102+08:00
  8. Deleted file /u01/app/oracle/oradata/MYDB19C/testpdb/testpdb_temp01.dbf
  9. #dg備端為mount狀態,通過rman恢復
  10. RMAN> recover database until time "to_date('2021-07-22 15:51:00','YYYY-MM-DD HH24:MI:SS')";
  11. Starting recover at 22-JUL-21
  12. using target database control file instead of recovery catalog
  13. allocated channel: ORA_DISK_1
  14. channel ORA_DISK_1: SID=35 device type=DISK
  15. starting media recovery
  16. archived log for thread 1 with sequence 153 is already on disk as file /arch/1_153_1029107282.arc
  17. archived log for thread 1 with sequence 154 is already on disk as file /arch/1_154_1029107282.arc
  18. archived log for thread 1 with sequence 155 is already on disk as file /arch/1_155_1029107282.arc
  19. archived log for thread 1 with sequence 156 is already on disk as file /arch/1_156_1029107282.arc
  20. archived log for thread 1 with sequence 157 is already on disk as file /arch/1_157_1029107282.arc
  21. archived log for thread 1 with sequence 158 is already on disk as file /arch/1_158_1029107282.arc
  22. archived log for thread 1 with sequence 159 is already on disk as file /arch/1_159_1029107282.arc
  23. archived log for thread 1 with sequence 160 is already on disk as file /arch/1_160_1029107282.arc
  24. archived log for thread 1 with sequence 161 is already on disk as file /arch/1_161_1029107282.arc
  25. archived log for thread 1 with sequence 162 is already on disk as file /arch/1_162_1029107282.arc
  26. archived log for thread 1 with sequence 163 is already on disk as file /arch/1_163_1029107282.arc
  27. archived log for thread 1 with sequence 164 is already on disk as file /arch/1_164_1029107282.arc
  28. archived log file name=/arch/1_153_1029107282.arc thread=1 sequence=153
  29. archived log file name=/arch/1_154_1029107282.arc thread=1 sequence=154
  30. archived log file name=/arch/1_155_1029107282.arc thread=1 sequence=155
  31. archived log file name=/arch/1_156_1029107282.arc thread=1 sequence=156
  32. archived log file name=/arch/1_157_1029107282.arc thread=1 sequence=157
  33. archived log file name=/arch/1_158_1029107282.arc thread=1 sequence=158
  34. archived log file name=/arch/1_159_1029107282.arc thread=1 sequence=159
  35. archived log file name=/arch/1_160_1029107282.arc thread=1 sequence=160
  36. archived log file name=/arch/1_161_1029107282.arc thread=1 sequence=161
  37. archived log file name=/arch/1_162_1029107282.arc thread=1 sequence=162
  38. archived log file name=/arch/1_163_1029107282.arc thread=1 sequence=163
  39. archived log file name=/arch/1_164_1029107282.arc thread=1 sequence=164
  40. media recovery complete, elapsed time: 00:02:16
  41. Finished recover at 22-JUL-21

檢查備端情況

  1. --開啟資料庫
  2. SQL> alter database open;
  3. Database altered.
  4. SQL> show pdbs
  5. CON_ID CON_NAME OPEN MODE RESTRICTED
  6. ---------- ------------------------------ ---------- ----------
  7. 2 PDB$SEED READ ONLY NO
  8. 3 TESTPDB MOUNTED
  9. 4 MYPDB MOUNTED
  10. --如果開啟recover,後續就刪除了testpdb
  11. SQL> alter database recover managed standby database using current logfile disconnect from session;
  12. Database altered.
  13. SQL> show pdbs
  14. CON_ID CON_NAME OPEN MODE RESTRICTED
  15. ---------- ------------------------------ ---------- ----------
  16. 2 PDB$SEED READ ONLY NO
  17. 4 MYPDB MOUNTED

另,注意,Oracle19c 在mount資料庫時,dg備端會自動開啟recover模式,應用歸檔日誌。 alert日誌參考:

  1. ARCc started with pid=64, OS id=88513
  2. 2021-07-22T16:10:49.636837+08:00
  3. MRP0 (PID:88499): Managed Standby Recovery starting Real Time Apply
  4. 2021-07-22T16:10:49.672074+08:00
  5. ARCd started with pid=65, OS id=88518
  6. 2021-07-22T16:10:49.672676+08:00
  7. Starting background process ARCe
  8. 2021-07-22T16:10:51.903729+08:00
  9. max_pdb is 8
  10. 2021-07-22T16:10:55.411248+08:00
  11. Starting background process ARCf
  12. 2021-07-22T16:10:55.420715+08:00
  13. ARCe started with pid=66, OS id=88524
  14. 2021-07-22T16:10:57.850452+08:00
  15. Starting background process ARCg
  16. 2021-07-22T16:10:57.967273+08:00
  17. ARCf started with pid=67, OS id=88528
  18. 2021-07-22T16:11:01.664535+08:00
  19. stopping change tracking
  20. 2021-07-22T16:11:01.682638+08:00
  21. MRP0 (PID:88499): Media Recovery Log /arch/1_151_1029107282.arc
  22. 2021-07-22T16:11:02.562368+08:00
  23. Completed: ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT NODELAY
  24. 2021-07-22T16:11:03.176818+08:00
  25. ARCg started with pid=68, OS id=88532
  26. 2021-07-22T16:11:03.177282+08:00