Restore

一次使用多個日誌文件(共 24 個)恢復數據庫的策略

  • May 19, 2021

我想看看如果我執行多行 SQL 命令來一次恢復多個(總共 24 個)日誌文件,這是否是安全有效的方法。

這些文件以bak文件格式格式化,但它們都是每小時事務日誌文件。

我有這些 SQL 語句一起執行:

RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051800.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051801.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051802.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051803.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051804.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051805.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051806.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051807.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051808.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051809.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051810.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051811.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051812.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051813.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051814.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051815.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051816.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051817.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051818.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051819.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051820.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051821.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051822.bak' WITH NORECOVERY
RESTORE LOG [LOG_us_bcan_multi_replica] FROM DISK = 'F:\LOG_us_bcan_multi_replica_2021051823.bak' WITH NORECOVERY

底部是每個文件的螢幕截圖及其大小:

在此處輸入圖像描述

因為每個文件的大小在某一時刻可能非常大(例如:“ .._ 2021051804.bak ”文件比其他文件大得多,我不確定一次執行整個 SQL 語句是否是一個好方法。

還是應該將這些整個過程分解為單獨的 SQL Server 代理作業步驟?

我不確定當這些整個 SQL 語句一次執行時 SQL 的行為如何。

它是否從頂部一個接一個地執行(停止直到一個完成然後轉到下一行)並且不會跳過該行的任何程序(如果一個程序比另一個程序花費更長的時間)?

你的方法是正確的。

SQL Server 在開始下一個語句之前執行批處理中的每個語句直到完成。

序列中的最後一次還原應指定STANDBY您是否希望生成的數據庫可讀,並可選擇在將來應用更多日誌。

.bak不是文件格式,它是普通的 Windows 文件副檔名。SQL Server 不關心這一點。不同的人使用不同的約定。一種流行的方法是.bak用於完整備份和.trn事務日誌,但這只是一種約定。

引用自:https://dba.stackexchange.com/questions/291877