กิจกรรม
31 มี.ค. 23 - 2 เม.ย. 23
อิเกีย เหตุการณ์การเรียนรู้ SQL, Fabric และ Power BI ที่ใหญ่ที่สุด 31 มีนาคม – 2 เมษายน ใช้รหัส FABINSIDER เพื่อบันทึก $400
ลงทะเบียนวันนี้เบราว์เซอร์นี้ไม่ได้รับการสนับสนุนอีกต่อไป
อัปเกรดเป็น Microsoft Edge เพื่อใช้ประโยชน์จากคุณลักษณะล่าสุด เช่น การอัปเดตความปลอดภัยและการสนับสนุนด้านเทคนิค
Applies to:
SQL Server
This topic explains how to restore to the point of failure. The topic is relevant only for databases that are using the full or bulk-logged recovery models.
Back up the tail of the log by running the following basic BACKUP statement:
BACKUP LOG <database_name> TO <backup_device>
WITH NORECOVERY, NO_TRUNCATE;
Restore a full database backup by running the following basic RESTORE DATABASE statement:
RESTORE DATABASE <database_name> FROM <backup_device>
WITH NORECOVERY;
Optionally, restore a differential database backup by running the following basic RESTORE DATABASE statement:
RESTORE DATABASE <database_name> FROM <backup_device>
WITH NORECOVERY;
Apply each transaction log, including the tail-log backup you created in step 1, by specifying WITH NORECOVERY in the RESTORE LOG statement:
RESTORE LOG <database_name> FROM <backup_device>
WITH NORECOVERY;
Recover the database by running the following RESTORE DATABASE statement:
RESTORE DATABASE <database_name>
WITH RECOVERY;
Before you can run the example, you must complete the following preparations:
The default recovery model of the AdventureWorks2022
database is the simple recovery model. Because this recovery model does not support restoring to the point of a failure, set AdventureWorks2022
to use the full recovery model by running the following ALTER DATABASE statement:
USE master;
GO
ALTER DATABASE AdventureWorks2022 SET RECOVERY FULL;
Create a full database back of the database by using the following BACKUP statement:
BACKUP DATABASE AdventureWorks2022 TO DISK = 'C:\AdventureWorks2022_Data.bck';
Create a routine log backup:
BACKUP LOG AdventureWorks2022 TO DISK = 'C:\AdventureWorks2022_Log.bck';
The following example restores the backups that are created previously, after creating a tail-log backup of the AdventureWorks2022
database. (This step assumes that the log disk can be accessed.)
First, the example creates a tail-log backup of the database that captures the active log and leaves the database in the Restoring state. Then, the example restores the database backup, applies the routine log backup created previously, and applies the tail-log backup. Finally, the example recovers the database in a separate step.
หมายเหตุ
The default behavior is to recover a database as part of the statement that restores the final backup.
/* Example of restoring a to the point of failure */
-- Step 1: Create a tail-log backup by using WITH NORECOVERY.
BACKUP LOG AdventureWorks2022
TO DISK = 'C:\AdventureWorks2022_Log.bck'
WITH NORECOVERY;
GO
-- Step 2: Restore the full database backup.
RESTORE DATABASE AdventureWorks2022
FROM DISK = 'C:\AdventureWorks2022_Data.bck'
WITH NORECOVERY;
GO
-- Step 3: Restore the first transaction log backup.
RESTORE LOG AdventureWorks2022
FROM DISK = 'C:\AdventureWorks2022_Log.bck'
WITH NORECOVERY;
GO
-- Step 4: Restore the tail-log backup.
RESTORE LOG AdventureWorks2022
FROM DISK = 'C:\AdventureWorks2022_Log.bck'
WITH NORECOVERY;
GO
-- Step 5: Recover the database.
RESTORE DATABASE AdventureWorks2022
WITH RECOVERY;
GO
กิจกรรม
31 มี.ค. 23 - 2 เม.ย. 23
อิเกีย เหตุการณ์การเรียนรู้ SQL, Fabric และ Power BI ที่ใหญ่ที่สุด 31 มีนาคม – 2 เมษายน ใช้รหัส FABINSIDER เพื่อบันทึก $400
ลงทะเบียนวันนี้การฝึกอบรม
ใบรับรอง
รับรองโดย Microsoft: Azure Database Administrator Associate - Certifications
จัดการโครงสร้างพื้นฐานฐานข้อมูล SQL Server สําหรับคลาวด์ ภายในองค์กร และฐานข้อมูลเชิงสัมพันธ์แบบไฮบริดโดยใช้ข้อเสนอของฐานข้อมูลเชิงสัมพันธ์ของ Microsoft PaaS
เอกสาร
Restore a SQL Server Database to a Point in Time (Full Recovery Model) - SQL Server
Restore a SQL Server Database to a Point in Time (Full Recovery Model)
Restore a Transaction Log Backup (SQL Server) - SQL Server
This article describes how to restore a transaction log backup in SQL Server by using SQL Server Management Studio or Transact-SQL.
Restart interrupted restore operation - SQL Server
This example shows you how to restart an interrupted restore operation in SQL Server using Transact-SQL.