バックアップからのリストアによるリカバリ手順

Published Sep 26 2021 07:01 PM 682 Views
Microsoft

みなさん、こんにちは。今回はバックアップからのリストアによる SQL Server リカバリ手順についてご紹介します。

本手順では SQL Server 2019 を使用して、下記 の2 通りのリカバリ手順について記載しています。

A. 障害発生直前までのリカバリ手順

B. ある特定の時点までのリカバリ手順 

 

前提条件 

障害発生直前、またはある特定の時点までデータベースを復旧するためには、下記 の 3 つの条件を満たしていることが必要です。 

  1. 完全バックアップを取得済みであること。
  2. トランザクション ログが破損していないこと。
  3. データベースの復旧モデルが「完全」であること。

※ 本手順は ServerA という名前のサーバー上にインストールされた SQL Server  test データベースについて、2021   9  18 日に下記のバックアップを取得済みであることを前提として記載しています。

※復旧モデルは Microsoft SQL Server Management Studio から、該当データベースを右クリックして、[タスク]メニューの[バックアップ]をクリックすることで確認できます。

 No

バックアップ日時

バックアップの種類

バックアップ ファイル名

 1

2021-09-18 02:00

完全バックアップ

c:\work\full.bak

 2

2021-09-18 02:30

ログバックアップ

c:\work\log1.trn

 3

2021-09-18 12:00

差分バックアップ

c:\work\diff.bak

 4 

2021-09-18 12:30

ログバックアップ

c:\work\log2.trn

 

 

A. 障害発生直前までのリカバリ手順

下記の流れで障害発生直前まで復元します。

  1. まだバックアップしていないトランザクションログを取得する(A-1)
  2. 最新の完全バックアップを復元する。(A-2)
  3. 最新の完全バックアップ以降に差分バックアップを取得している場合には、最新の差分バックアップを復元する。(A-3)
  4. すでに復元したバックアップ以降に取得したトランザクション ログバックアップをすべて復元する。(A-4,5)

具体的にディスク障害等でデータファイル (.mdf) が破損してしまった場合に、障害発生直前 (2021 9 18 12:30 時点) までデータベースを復旧する手順を下記にご紹介します。

 

A-1. コマンド プロンプトを起動し、下記のコマンドを実行して、残ったトランザクション ログ(まだバックアップしていないログ)を、NO_TRUNCATE オプションを使用してバックアップします。

    ---------------------------------------------------------------------------------------  

      C:\> sqlcmd -E -S ServerA

      1> BACKUP LOG test TO DISK = 'C:\work\log3.trn' WITH NO_TRUNCATE

      2> GO 

    ---------------------------------------------------------------------------------------  

※このログは、ログ末尾 ’TAIL ログとも呼ばれます。

NO_TRUNCATE オプションは、ログ末尾をバックアップするとともに、ログを切り捨てないという効果もあります。

 

A-2. 下記のコマンドを実行して、02:00 に取得した完全バックアップをリストアします。

    --------------------------------------------------------------------------------------------------------

      1> USE master

      2> RESTORE DATABASE test FROM DISK = 'C:\work\full.bak' WITH NORECOVERY, REPLACE

      3> GO  

    --------------------------------------------------------------------------------------------------------

NORECOVERY  オプションは、まだリストアすべきバックアップがある場合に使用するオプションです。NORECOVERY  を指定してリストアを行った場合は、データベースが「復旧中」(リストア中)となり、ユーザーからの接続を一切できないようにブロックします。復旧状態のオプションに関しては以下の公式ドキュメントをご参照ください。

データベースの復元 ([オプション] ページ) - SQL Server | Microsoft Docs   

REPLACE  オプションは、指定したデータベースと同じ名前のデータベースが既に存在している場合でも、データベースとその関連ファイルが作成されます。その場合、既存のデータベースは削除されます。

 

A-3. 下記のコマンドを実行して、12:00 に取得した差分バックアップをリストアします。

    -----------------------------------------------------------------------------------------------

      1> USE master

      2> RESTORE DATABASE test FROM DISK = 'C:\work\diff.bak' WITH NORECOVERY

      3> GO 

    -----------------------------------------------------------------------------------------------    

 

A-4. 下記のコマンドを実行して、12:30 に取得したログ バックアップをリストアします。

    --------------------------------------------------------------------------------------- 

      1> USE master

      2> RESTORE LOG test FROM DISK = 'C:\work\log2.trn' WITH NORECOVERY

      3> GO 

     --------------------------------------------------------------------------------------

 

A-5. 下記のコマンドを実行して、上記手順 1 で取得した TAIL ログをリストアします。

   ------------------------------------------------------------------------------------- 

     1> USE master

     2> RESTORE LOG test FROM DISK = 'C:\work\log3.trn' WITH RECOVERY

     3> GO 

   -------------------------------------------------------------------------------------  

RECOVERY  オプションは、リストア後にデータベースを完全復旧した状態にします。これは、リストアが完了したことの合図になり、残りのこれ以降のバックアップをリストアすることはできません。

 

A-6. 下記のコマンドを実行して、test データベースに接続します。

   ------------------ 

     1> USE test

     2> GO 

   ------------------

接続できればリカバリは完了です。 test データベースは、障害発生直前の状態まで復旧しています。

 

B. ある特定の時点までのリカバリ方法

データを誤って削除してしまった場合等に、ある特定の時点までデータベースを復旧する手順を下記にご紹介します。

本手順では、2021 9 18 日 の 12 15 00   に誤ってデータを削除してしまい、2021 9 18 日 の 12 14 59   の時点までデータベースを復旧することを想定しています。

 

B-1. 上記 ‘A.  障害発生直前までのリカバリ手順’ の手順 1 から 手順 3 までを実行します。

 

B-2.  下記のコマンドを実行して、12:30 に取得したログ バックアップをリストアします。

     -------------------------------------------------------------------------------------------------------------------- 

      1> USE master

      2> RESTORE LOG test FROM DISK = 'C:\work\log2.trn' WITH RECOVERY, STOPAT = '2021-09-18 12:14:59'

      3> GO

     --------------------------------------------------------------------------------------------------------------------

STOPAT  オプションは、特定の時間までのデータへ復元したいという場合に使用するオプションです。

 

B-3. 下記のコマンドを実行して、test データベースに接続します。

     ------------------

       1> USE test

       2> GO 

     ------------------

接続できればリカバリは完了です。 test データベースは、データが削除される直前の状態まで復旧しています。

 

< 参考情報 >

SQL Server データベースを特定の時点に復元する方法(完全復旧モデル) - SQL Server | Microsoft Docs

%3CLINGO-SUB%20id%3D%22lingo-sub-2787079%22%20slang%3D%22ja-JP%22%3ERecovery%20steps%20by%20restoring%20from%20backup%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2787079%22%20slang%3D%22ja-JP%22%3E%3CP%3E%3CSPAN%3EHello%20everyone.%20This%20time%2C%20I'll%3C%2FSPAN%3E%20show%20you%20how%20sql%20%3CSPAN%3Eserver%3C%2FSPAN%3E%20%3CSPAN%3Erecovers%3C%2FSPAN%3E%20from%20%3CSPAN%3Erestoring%3C%2FSPAN%3E%20from%20%3CSPAN%3Ebackup.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThis%20procedure%20describes%20two%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3Erecovery%3C%2FSPAN%3E%20procedures%20using%20SQL%20Server%202019%3A%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3EA.%20%20Recovery%20steps%20just%20before%20the%20failure%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%3CSTRONG%3EB.%20%20Recovery%20procedure%20to%20a%20certain%20point%20in%20time%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%E2%96%A0%3C%2FSPAN%3E%20%3CSTRONG%3EPrerequisites%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ETo%20recover%20the%20database%20just%20before%20a%20failure%20or%20to%20a%20specific%20point%20in%20time%2C%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20you%20must%20%3CSPAN%3Emeet%20three%20conditions%3A%20%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CSPAN%3EYou%20have%20obtained%20a%20full%20backup.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3EThe%20%3CSPAN%3Etransaction%3C%2FSPAN%3E%20%3CSPAN%3Elog%20is%20not%20corrupted.%20%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3EThe%20database%20recovery%20model%20is%20complete.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E*%20This%20procedure%20is%20for%3C%2FSPAN%3E%20a%20SQL%20Server%20%3CSPAN%3Etest%3C%2FSPAN%3E%20database%20installed%20on%20%3CSPAN%3Ea%3C%2FSPAN%3E%20server%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3Enamed%3C%2FSPAN%3E%20%3CSPAN%3EServerA%3C%2FSPAN%3E%20in%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3ESeptember%3C%2FSPAN%3E%20%3CSPAN%3E2021.%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E%20%3C%2FSPAN%3EIt%20is%20assumed%20that%20the%20following%20backups%20have%20been%20obtained%20on%20the%20%3CSPAN%3E18th.%3C%2FSPAN%3E%20%3CSPAN%3E%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E*%20You%3C%2FSPAN%3E%20can%20check%20the%20recovery%20model%20%3CSPAN%3Efrom%20Microsoft%20SQL%20Server%20Management%20Studio%20by%20right-clicking%20the%20database%20and%20clicking%20%5BBackup%5D%20on%20the%20%5BTasks%5D%20menu.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CTABLE%3E%0A%3CTBODY%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3ENo%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EBackup%20date%20and%20time%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EBackup%20type%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EBackup%20file%20name%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3E1%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E2021-09-18%2002%3A00%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EFull%20backup%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3Ec%3A%5Cwork%5Cfull.bak%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3E2%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E2021-09-18%2002%3A30%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3ELog%20backup%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3Ec%3A%5Cwork%5Clog1.trn%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3E3%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E2021-09-18%2012%3A00%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EDifferential%20backups%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3Ec%3A%5Cwork%5Cdiff.bak%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3E4%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E2021-09-18%2012%3A30%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3ELog%20backup%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3Ec%3A%5Cwork%5Clog2.trn%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3C%2FTBODY%3E%0A%3C%2FTABLE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CU%3E%3CSTRONG%3EA.%20%20Recovery%20steps%20just%20before%20the%20failure%3C%2FSTRONG%3E%3C%2FU%3E%3C%2FP%3E%0A%3CP%3ERestore%20until%20just%20before%20the%20failure%20occurs%20with%20the%20following%20flow.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EGet%20transaction%20logs%20that%20you%20haven't%20backed%20up%20yet%20(A-1)%3C%2FLI%3E%0A%3CLI%3E%3CSPAN%3ERestore%20the%20most%20recent%20full%20backup.%20%3C%2FSPAN%3E%20%3CSPAN%3E(A-2)%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3ERestore%20the%20latest%20differential%20backup%20if%20you%20have%20obtained%20a%20differential%20backup%20since%20the%20most%20recent%20full%20backup.%20(A-3)%3C%2FLI%3E%0A%3CLI%3ERestore%20all%20transaction%20log%20backups%20that%20you%20have%20already%20restored%20since%20the%20backup.%20(A-4%2C5)%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3ESpecifically%2C%20if%20the%20data%20file%20%3CSPAN%3E(.mdf)%3C%2FSPAN%3E%20is%20corrupted%20due%20to%20a%20disk%20%3CSPAN%3Efailure%2C%20etc.%2C%3C%2FSPAN%3E%20immediately%20before%20the%20failure%20(as%20of%20%3CSPAN%3E%20%3C%2FSPAN%3E%20%3CSPAN%3E%20%3C%2FSPAN%3E%20%3CSPAN%3ESeptember%20%3C%2FSPAN%3E%20%3CSPAN%3E18%2C%3C%2FSPAN%3E%20%3CSPAN%3E%20%3C%2FSPAN%3E%20%3CSPAN%3E2021%2C%3C%2FSPAN%3E%20%3CSPAN%3E12%3A30%3C%2FSPAN%3E%20%3CSPAN%3Ep.m.%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3EBelow%3C%2FSPAN%3E%20%3CSPAN%3Eare%20the%20steps%20to%20recover%20the%20database.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSTRONG%3EA-1.%3C%2FSTRONG%3E%20%3C%2FSPAN%3E%3CSPAN%3EStart%20the%20command%20prompt%20and%20run%20the%20following%20command%20to%3C%2FSPAN%3E%20back%20up%20any%20remaining%20%3CSPAN%3Etransaction%3C%2FSPAN%3E%20%3CSPAN%3Elogs%20(logs%20that%20you%20have%20not%20already%20backed%20up)%3C%2FSPAN%3Eusing%3CSPAN%3Ethe%20NO_TRUNCATE%3C%2FSPAN%3E%20%3CSPAN%3Eoption%3A%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E---------------------------------------------------------------------------------------%3C%2FP%3E%0A%3CP%3EC%3A%5C%26gt%3B%20sqlcmd%20-E%20-S%20ServerA%3C%2FP%3E%0A%3CP%3E1%26gt%3B%20BACKUP%20LOG%20test%20TO%20DISK%20%3D%20'C%3A%5Cwork%5Clog3.trn'%20WITH%20NO_TRUNCATE%3C%2FP%3E%0A%3CP%3E2%26gt%3B%20GO%3C%2FP%3E%0A%3CP%3E---------------------------------------------------------------------------------------%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E*This%20log%20is%3C%2FSPAN%3Ealso%20known%20%3CSPAN%3Eas%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E'endlog'%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20or%20%3CSPAN%3E'TAIL%3C%2FSPAN%3E%20%3CSPAN%3Elog'.%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E*%3C%2FSPAN%3E%20%3CSPAN%3E%20The%20NO_TRUNCATE%3C%2FSPAN%3E%20option%20also%20has%20the%20effect%20of%20%3CSPAN%3Ebacking%20up%20the%20end%20of%20the%20log%20and%20not%20truning%20the%20log.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EA-2.%20%3C%2FSTRONG%3E%3CSPAN%3ERun%20the%20following%20command%20to%3C%2FSPAN%3Erestore%20the%20full%20backup%20that%20you%20obtained%20at%3CSPAN%3E02%3A00.%3C%2FSPAN%3E%20%3CSPAN%3E%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E--------------------------------------------------------------------------------------------------------%3C%2FP%3E%0A%3CP%3E1%26gt%3B%20USE%20master%3C%2FP%3E%0A%3CP%3E2%26gt%3B%20RESTORE%20DATABASE%20test%20FROM%20DISK%20%3D%20'C%3A%5Cwork%5Cfull.bak'%20WITH%20NORECOVERY%2C%20REPLACE%3C%2FP%3E%0A%3CP%3E3%26gt%3B%20GO%3C%2FP%3E%0A%3CP%3E--------------------------------------------------------------------------------------------------------%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E*%3C%2FSPAN%3EThe%3CSPAN%3ENORECOVERY%3C%2FSPAN%3E%20%3CSPAN%3Eoption%20is%20used%20when%20there%20are%20still%20backups%20to%20restore.%20%3C%2FSPAN%3EIf%20you%20restore%20with%20%3CSPAN%3ENORECOVERY%2C%3C%2FSPAN%3E%20%3CSPAN%3Ethe%20database%20is%20%22in%20recovery%22%20(restoring)%20and%20blocks%20any%20connections%20from%20users.%20Please%20refer%20to%20the%20official%20documentation%20below%20for%20recovery%20status%20options.%20%3C%2FSPAN%3E%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fja-jp%2Fsql%2Frelational-databases%2Fbackup-restore%2Frestore-database-options-page%3Fview%3Dsql-server-ver15%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%3CSPAN%3ERestore%20Database%20(Options%20page)%20-%20SQL%20Server%20%7C%20Microsoft%20Docs%3C%2FSPAN%3E%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E*%3C%2FSPAN%3EThe%3CSPAN%3EREPLACE%3C%2FSPAN%3E%20%3CSPAN%3Eoption%20creates%20a%20database%20and%20its%20associated%20files%2C%20even%20if%20a%20database%20with%20the%20same%20name%20as%20the%20specified%20database%20already%20exists.%20In%20that%20case%2C%20the%20existing%20database%20is%20deleted.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSTRONG%3EA-3.%3C%2FSTRONG%3E%20%3C%2FSPAN%3E%3CSPAN%3ERun%20the%20following%20command%20to%3C%2FSPAN%3Erestore%20the%20differential%20%3CSPAN%3Ebackup%3C%2FSPAN%3E%20%3CSPAN%3Eretrieved%20at%3C%2FSPAN%3E%20%3CSPAN%3E12%3A00.%3C%2FSPAN%3E%20%3CSPAN%3E%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E-----------------------------------------------------------------------------------------------%3C%2FP%3E%0A%3CP%3E1%26gt%3B%20USE%20master%3C%2FP%3E%0A%3CP%3E2%26gt%3B%20RESTORE%20DATABASE%20test%20FROM%20DISK%20%3D%20'C%3A%5Cwork%5Cdiff.bak'%20WITH%20NORECOVERY%3C%2FP%3E%0A%3CP%3E3%26gt%3B%20GO%3C%2FP%3E%0A%3CP%3E-----------------------------------------------------------------------------------------------%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSTRONG%3EA-4.%3C%2FSTRONG%3E%20%3C%2FSPAN%3E%3CSPAN%3ERun%20the%20following%20command%20to%3C%2FSPAN%3Erestore%20the%20log%20backup%20that%20you%20obtained%20at%3CSPAN%3E12%3A30.%3C%2FSPAN%3E%20%3CSPAN%3E%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E---------------------------------------------------------------------------------------%3C%2FP%3E%0A%3CP%3E1%26gt%3B%20USE%20master%3C%2FP%3E%0A%3CP%3E2%26gt%3B%20RESTORE%20LOG%20test%20FROM%20DISK%20%3D%20'C%3A%5Cwork%5Clog2.trn'%20WITH%20NORECOVERY%3C%2FP%3E%0A%3CP%3E3%26gt%3B%20GO%3C%2FP%3E%0A%3CP%3E--------------------------------------------------------------------------------------%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSTRONG%3EA-5.%3C%2FSTRONG%3E%20%3C%2FSPAN%3E%3CSPAN%3ERun%20the%20following%20command%20to%3C%2FSPAN%3E%20restore%20the%20%3CSPAN%3ETAIL%3C%2FSPAN%3E%20log%20%3CSPAN%3Eobtained%20in%3C%2FSPAN%3E%20step%20%3CSPAN%3E1%3C%2FSPAN%3E%20%3CSPAN%3Eabove.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E-------------------------------------------------------------------------------------%3C%2FP%3E%0A%3CP%3E1%26gt%3B%20USE%20master%3C%2FP%3E%0A%3CP%3E2%26gt%3B%20RESTORE%20LOG%20test%20FROM%20DISK%20%3D%20'C%3A%5Cwork%5Clog3.trn'%20WITH%20RECOVERY%3C%2FP%3E%0A%3CP%3E3%26gt%3B%20GO%3C%2FP%3E%0A%3CP%3E-------------------------------------------------------------------------------------%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E*%3C%2FSPAN%3EThe%3CSPAN%3ERECOVERY%3C%2FSPAN%3E%20%3CSPAN%3Eoption%20makes%20the%20database%20fully%20restored%20after%20restore.%20This%20signals%20that%20the%20restore%20is%20complete%20and%20you%20cannot%20restore%20the%20remaining%20subsequent%20backups.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EA-6.%3C%2FSTRONG%3E%20Run%20the%20following%20command%20toconnect%20to%20thetest%20database.%20%3C%2FP%3E%0A%3CP%3E------------------%3C%2FP%3E%0A%3CP%3E1%26gt%3B%20USE%20test%3C%2FP%3E%0A%3CP%3E2%26gt%3B%20GO%3C%2FP%3E%0A%3CP%3E------------------%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EIf%20you%20can%20connect%2C%3C%2FSPAN%3E%20%3CSPAN%3Erecovery%3C%2FSPAN%3E%20%3CSPAN%3Eis%20complete.%20%3C%2FSPAN%3EThe%20%3CSPAN%3Etest%3C%2FSPAN%3E%20%3CSPAN%3Edatabase%20is%20recovering%20to%20the%20state%20it%20was%20in%20just%20before%20it%20failed.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CU%3E%3CSTRONG%3EB.%20%20Recovery%20method%20to%20a%20certain%20point%20in%20time%3C%2FSTRONG%3E%3C%2FU%3E%3C%2FP%3E%0A%3CP%3EHere%20are%20the%20steps%20to%20recover%20the%20database%20to%20a%20specific%20point%20in%20time%2C%20for%20example%2C%20if%20you%20accidentally%20delete%20data.%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EIn%20this%20procedure%2C%20on%3C%2FSPAN%3E%20%3CSPAN%3ESeptember%3C%2FSPAN%3E%20%3CSPAN%3E18%2C%202021%2C%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3Eat%2012%3A15%3A00%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3Ep.m.%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E%26nbsp%3B%20%3C%2FSPAN%3E%20%3CSPAN%3E%20accidentally%20deleted%20data%20on%3C%2FSPAN%3E%20%3CSPAN%3ESeptember%3C%2FSPAN%3E%20%3CSPAN%3E18%2C%202021%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3Eat%3C%2FSPAN%3E%20%3CSPAN%3E12%3A14%3C%2FSPAN%3E%20%3CSPAN%3Ep.m.%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E59%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3Ep.m.%3C%2FSPAN%3E%20%3CSPAN%3ESeconds%3C%2FSPAN%3E%20%3CSPAN%3E%26nbsp%3B%20%3C%2FSPAN%3E%20the%20database%20is%20%3CSPAN%3Eexpected%20to%20be%20recovered%20to%20the%20point%20in%20time.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSTRONG%3EB-1.%3C%2FSTRONG%3E%20%3C%2FSPAN%3E%3CSPAN%3EAbove%20'%3C%2FSPAN%3E%3CSPAN%3E%20A.%26nbsp%3B%20Perform%20steps%201%20%3C%2FSPAN%3E%3CSPAN%3Ethrough%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E3%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20%3CSPAN%3E%3C%2FSPAN%3E%20of%20recovery%20steps%20just%20before%20%3CSPAN%3Ethe%20failure.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EB-2.%26nbsp%3B%20%3C%2FSTRONG%3E%3CSPAN%3ERun%20the%20following%20command%20to%3C%2FSPAN%3Erestore%20the%20log%20backup%20that%20you%20obtained%20at%3CSPAN%3E12%3A30.%3C%2FSPAN%3E%20%3CSPAN%3E%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E--------------------------------------------------------------------------------------------------------------------%3C%2FP%3E%0A%3CP%3E1%26gt%3B%20USE%20master%3C%2FP%3E%0A%3CP%3E2%26gt%3B%20RESTORE%20LOG%20test%20FROM%20DISK%20%3D%20'C%3A%5Cwork%5Clog2.trn'%20WITH%20RECOVERY%2C%20STOPAT%20%3D%20'2021-09-18%2012%3A14%3A59'%3C%2FP%3E%0A%3CP%3E3%26gt%3B%20GO%3C%2FP%3E%0A%3CP%3E--------------------------------------------------------------------------------------------------------------------%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E*%3C%2FSPAN%3EThe%3CSPAN%3ESTOPAT%3C%2FSPAN%3E%20%3CSPAN%3Eoption%20is%20used%20when%20you%20want%20to%20restore%20data%20to%20a%20specific%20time.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSTRONG%3EB-3.%3C%2FSTRONG%3E%20%3C%2FSPAN%3E%3CSPAN%3ERun%20the%20following%20command%20to%3C%2FSPAN%3Econnect%20to%20the%3CSPAN%3Etest%3C%2FSPAN%3E%20%3CSPAN%3Edatabase.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E------------------%3C%2FP%3E%0A%3CP%3E1%26gt%3B%20USE%20test%3C%2FP%3E%0A%3CP%3E2%26gt%3B%20GO%3C%2FP%3E%0A%3CP%3E------------------%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EIf%20you%20can%20connect%2C%3C%2FSPAN%3E%20%3CSPAN%3Erecovery%3C%2FSPAN%3E%20%3CSPAN%3Eis%20complete.%20%3C%2FSPAN%3EThe%20%3CSPAN%3Etest%3C%2FSPAN%3E%20%3CSPAN%3Edatabase%20is%20recovering%20to%20the%20state%20it%20was%20in%20just%20before%20the%20data%20was%20deleted.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26lt%3B%20Reference%20information%20%26gt%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fnam06.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fdocs.microsoft.com%252Fja-jp%252Fsql%252Frelational-databases%252Fbackup-restore%252Frestore-a-sql-server-database-to-a-point-in-time-full-recovery-model%253Fview%253Dsql-server-ver15%26amp%3Bdata%3D04%257C01%257Ct-ttaniguchi%2540microsoft.com%257C2e5db99c0d0242b3ef0008d9810ee87d%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C637682723331423143%257CUnknown%257CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%253D%257C1000%26amp%3Bsdata%3Dxrye66Z3RRiiZzCP%252FwwZXUSITebddHZ3EsYBJjlXBSs%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EHow%20to%20Restore%20a%20SQL%20Server%20Database%20to%20a%20Specific%20Point%20in%20Time%20(Full%20Recovery%20Model)%20-%20SQL%20Server%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Co-Authors
Version history
Last update:
‎Sep 26 2021 07:13 PM
Updated by: