在 RDS for SQL Server 中使用原生備份和還原時,可能會發生哪些常見問題?

6 分的閱讀內容
0

我正在為我的微軟 SQL 伺服器執行個體 Amazon Relational Database Service (Amazon RDS) 執行原生備份或還原。此過程可能會遇到哪些常見錯誤?

解決方案

使用 RDS for SQL Server 原生備份和還原選項時,您可能會碰到驗證錯誤。這些錯誤將立即顯示,而不會建立工作。以下是常見錯誤和建議的修正方式:

錯誤:作業失敗或並行 RESTORE_DB 要求因而中止工作

從 Amazon Elastic Compute Cloud (Amazon EC2) 或內部部署還原備份時,如果您在資料庫執行個體上遇到空間相關問題,就會發生此錯誤:

[2022-04-07 05:21:22.317] Aborted the task because of a task failure or a concurrent RESTORE_DB request.
[2022-04-07 05:21:22.437] Task has been aborted
[2022-04-07 05:21:22.440] There is not enough space on the disk to perform restore database operation.

若要解決此錯誤,請執行下列操作:

選項 1:

1.    在來源執行個體 (EC2 或內部部署) 上執行下列指令。此指令會驗證資料庫大小,包括資料檔案和 Tlog 檔案。在下列範例中,將 [DB_NAME] 取代為資料庫名稱。

SELECT DB_NAME(database_id) AS DatabaseName,
Name AS Logical_Name,
Physical_Name, (size*8)/1024/1024 SizeGB
FROM sys.master_files
WHERE DB_NAME(database_id) = '[DB_NAME]'
GO
Database Size = (DB_Name size + DB_Name_Log size)

2.    比較來源執行個體資料庫大小與資料庫執行個體上的可用儲存體。相應增加可用的儲存空間,然後還原資料庫。

選項 2:

壓縮來源 SQL Server 上目前的資料庫日誌檔,以清空未使用的空間,然後執行資料庫備份。

使用下列指令壓縮日誌檔。

DBCC SHRINKFILE (LogFileName, Desired Size in MB)

錯誤:作業失敗或並行 RESTORE_DB 要求因而中止工作

當您有與 AWS Identity and Access Management (IAM) 角色或與 SQLSERVER_BACKUP_RESTORE 選項有關政策相關的權限問題時,會發生下列錯誤:

[2020-12-15 08:56:22.143] Aborted the task because of a task failure or a concurrent RESTORE_DB request.
[2020-12-15 08:56:22.213] Task has been aborted
[2020-12-15 08:56:22.217] Access Denied

若要解決此錯誤,請執行下列操作:

1.    驗證還原查詢以確保 S3 儲存貯體和資料夾前置詞正確:

exec msdb.dbo.rds_restore_database
      @restore_db_name='database_name',
      @s3_arn_to_restore_from='arn:aws:s3:::bucket_name/file_name_and_extension';

2.    驗證 IAM 政策包含下列屬性:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket",
        "s3:GetBucketLocation"
      ],
      "Resource": "arn:aws:s3:::bucket_name"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetObjectAttributes",
        "s3:GetObject",
        "s3:PutObject",
        "s3:ListMultipartUploadParts",
        "s3:AbortMultipartUpload"
      ],
      "Resource": "arn:aws:s3:::bucket_name/*"
    }
  ]
}

**注意:**將 arn:aws:s3:::bucket_name 替換為 S3 儲存貯體的 ARN。

3.    確認原則與 SQLSERVER_BACKUP_RESTORE 還原選項中指定的角色有正確的關聯。

4.    確認 SQLSERVER_BACKUP_RESTORE 選項是與資料庫執行個體相關聯的選項群組:

S3 儲存貯體 ARN
S3 資料夾前置詞 (選用)

如需詳細資訊,請參閱如如何對執行 SQL Server 的 Amazon RDS 資料庫執行個體執行原生備份?

錯誤:作業失敗或並行 RESTORE_DB 要求因而中止工作

此錯誤通常與跨帳戶的資料庫還原相關。

範例:

  • 帳戶 A 具有存放備份的 S3 儲存貯體。
  • 帳戶 B 具有需要在其內部進行還原的 RDS 資料庫執行個體。

當您在 IAM 角色或與選項關聯的政策中出現權限相關問題時,就會發生此錯誤。或者,與跨帳戶中的 S3 儲存貯體關聯的儲存貯體政策存在權限問題。

[2022-02-03 15:57:22.180] Aborted the task because of a task failure or a concurrent
RESTORE_DB request.
[2022-02-03 15:57:22.260] Task has been aborted
[2022-02-03 15:57:22.263] Error making request with Error Code Forbidden and Http Status Code Forbidden. No further error information was returned by the service.

若要解決此錯誤,請執行下列操作:

1.    確認帳戶 B (打算還原的資料庫執行個體所在的帳戶) 中的 IAM 政策包含下列屬性:

{
  "Version": "2012-10-17",
  "Statement":
    [
      {
        "Effect": "Allow",
        "Action":
          [
            "s3:ListBucket",
            "s3:GetBucketLocation"
          ],
        "Resource": "arn:aws:s3:::name_of_bucket_present_in_Account_A"
      },
      {
        "Effect": "Allow",
        "Action":
          [
            "s3:GetObject",
            "s3:PutObject",
            "s3:ListMultipartUploadParts",
            "s3:AbortMultipartUpload"
          ],
        "Resource": "arn:aws:s3::: name_of_bucket_present_in_Account_A /*"
      },
      {
        "Action": [
          "kms:DescribeKey",
          "kms:GenerateDataKey",
          "kms:Decrypt",
          "kms:Encrypt"
          "kms:ReEncryptTo",
          "kms:ReEncryptFrom"
        ],
        "Effect": "Allow",
        "Resource": [
          "arn:aws: PUT THE NAME OF THE KEY HERE",
          "arn:aws:s3::: name_of_bucket_present_in_Account_A /*"
        ]
      }
    ]
}

2.    確認帳戶 A 中與 S3 儲存貯體關聯的儲存貯體政策包含下列屬性:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Permission to cross account",
      "Effect": "Allow",
      "Principal": {
        "AWS": [
          "arn:aws:iam::AWS-ACCOUNT-ID-OF-RDS:role/service-role/PUT-ROLE-NAME"   /*---- Change Details here
        ]
      },
      "Action": [
        "s3:ListBucket",
        "s3:GetBucketLocation"
             ],
      "Resource": [
        "arn:aws:s3:::PUT-BUCKET-NAME"   /*---- Change Details here
      ]
    },
    {
      "Sid": "Permission to cross account on object level",
      "Effect": "Allow",
      "Principal": {
        "AWS": [
          "arn:aws:iam::AWS-ACCOUNT-ID-OF-RDS:role/service-role/PUT-ROLE-NAME"   /*---- Change Details here
        ]
      },
      "Action": [
        "s3:GetObject",
        "s3:PutObject",
        "s3:ListMultipartUploadParts",
        "s3:AbortMultipartUpload"
      ],
      "Resource": [
        "arn:aws:s3::: PUT-BUCKET-NAME/*"  /*---- Change Details here
      ]
    }
  ]
}

如需詳細資訊,請參閱下列內容:

錯誤:找不到含有指紋 'XXXXXX' 的伺服器憑證

當您嘗試將具有透明資料加密 (TDE) 的資料庫從 EC2 或內部部署還原至 RDS for SQL Server 時,就會發生這個錯誤:

[2022-06-1511:55:22.280] Cannot find server certificate with thumbprint 'XXXXXXX'.
[2022-06-15 11:55:22.280] RESTORE FILELIST is terminating abnormally.
[2022-06-15 11:55:22.300] Aborted the task because of a task failure or a concurrent RESTORE_DB request.
[2022-06-15 11:55:22.333] Task has been aborted
[2022-06-15 11:55:22.337] Empty restore file list result retrieved.

此錯誤表示嘗試將 TDE 加密的資料庫備份,還原至其原始伺服器以外的 SQL 執行個體。原始伺服器的 TDE 憑證必須匯入目標伺服器。如需匯入伺服器憑證與個別限制的詳細資訊,請參閱 SQL Server 中的透明資料加密支援

除了匯入憑證外,若要解決此錯誤,請執行下列動作:

防止此錯誤有兩種方法。

選項 1:資料庫備份來自內部部署或 EC2 執行個體,但目標 RDS SQL Server 位於 MultiAZ

1.    TDE 開啟時下建立來源資料庫的備份。

2.    將備份還原為內部部署伺服器中新的資料庫。

3.    關閉新建立資料庫上的 TDE。使用下列指令關閉 TDE:

執行下列指令關閉資料庫的加密。在下面的指令中,用正確的資料庫名稱替換資料庫名稱

USE master;
GO
ALTER DATABASE [Databasename] SET ENCRYPTION OFF;
GO

執行下列指令刪除用於加密的 DEK。在下面的指令中,用正確的資料庫名稱替換資料庫名稱。

USE [Databasename];
GO
DROP DATABASE ENCRYPTION KEY;
GO

4.    建立原生 SQL Server 備份,並將新備份還原到所需的 RDS 執行個體。如需詳細資訊,請參閱如如何對執行 SQL Server 的 Amazon RDS 資料庫執行個體執行原生備份?

5.    在新的 RDS 資料庫中重新開啟 TDE

選項 2:資料庫來自使用 TDE 加密的 RDS for SQL Server 資料庫

1.    使用來源執行個體的快照,將資料庫還原至新執行個體

2.    關閉快照建立之資料庫的 TDE

3.    建立原生 SQL 備份,並將新備份還原到所需的 RDS 執行個體。

4.    在新的 RDS 資料庫中重新開啟 TDE

在 RDS for SQL Server 上觀察到的原生備份的常見錯誤

錯誤:由於工作失敗或與 RDS 自動備份的慣用備份視窗重疊,而中止工作

當您有與 IAM 角色或與 SQLSERVER_BACKUP_RESTORE 選項有關政策相關的權限問題時,會發生下列錯誤。

[2022-07-16 16:08:22.067]
Task execution has started. 
[2022-07-16 16:08:22.143] Aborted the task because of a task failure or an overlap with your preferred backup window for RDS automated backup.
[2022-07-16 16:08:22.147] Task has been aborted [2022-07-16 16:08:22.150] Access Denied

若要解決此問題,請執行下列動作:

1.    驗證還原查詢以確保 S3 儲存貯體和資料夾前置詞正確:

exec msdb.dbo.rds_restore_database
      @restore_db_name='database_name',
      @s3_arn_to_restore_from='arn:aws:s3:::bucket_name/file_name_and_extension';

2.    驗證 IAM 政策包含下列屬性:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket",
        "s3:GetBucketLocation"
      ],
      "Resource": "arn:aws:s3:::bucket_name"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetObjectAttributes",
        "s3:GetObject",
        "s3:PutObject",
        "s3:ListMultipartUploadParts",
        "s3:AbortMultipartUpload"
      ],
      "Resource": "arn:aws:s3:::bucket_name/*"
    }
  ]
}

**注意:**將 arn:aws:s3:::bucket_name 替換為 S3 儲存貯體的 ARN。

3.    確認原則與 SQLSERVER_BACKUP_RESTORE 還原選項中顯示的角色有正確的關聯。

4.    確認 SQLSERVER_BACKUP_RESTORE 選項在與資料庫執行個體相關聯的選項群組中。

S3 儲存貯體 ARN
S3 資料夾前置詞 (選用)

如需詳細資訊,請參閱如如何對執行 SQL Server 的 Amazon RDS 資料庫執行個體執行原生備份?

錯誤:在「XXX」上寫入失敗,無法將區塊寫入 S3,S3 寫入串流上傳失敗

這是 RDS for SQL Server 的已知問題。有時資料庫大小估計不正確,導致了備份程序失敗,並出現下列錯誤。

[2022-04-21 16:45:04.597] reviews_consumer/reviews_consumer_PostUpdate_042122.bak: Completed processing 100% of S3 chunks.
[2022-04-21 16:47:05.427] Write on "XXXX" failed: 995(The I/O operation has been aborted because of either a thread exit or an application request.) A nonrecoverable I/O error occurred on file "XXXX:" 995(The I/O operation has been aborted because of either a thread exit or an application request.). BACKUP DATABASE is terminating abnormally.
[2022-04-21 16:47:22.033] Unable to write chunks to S3 as S3 processing has been aborted. [2022-04-21 16:47:22.040] reviews_consumer/reviews_consumer_PostUpdate_042122.bak: Aborting S3 upload, waiting for S3 workers to clean up and exit
[2022-04-21 16:47:22.053] Aborted the task because of a task failure or an overlap with your preferred backup window for RDS automated backup.
[2022-04-21 16:47:22.060] reviews_consumer/reviews_consumer_PostUpdate_042122.bak: Aborting S3 upload, waiting for S3 workers to clean up and exit
[2022-04-21 16:47:22.067] S3 write stream upload failed. Encountered an error while uploading an S3 chunk: Part number must be an integer between 1 and 10000, inclusive S3 write stream upload failed. Encountered an error while uploading an S3 chunk: Part number must be an integer between 1 and 10000, inclusive S3 write stream upload failed. Encountered an error while uploading an S3 chunk: Part number must be an integer between 1 and 10000, inclusive S3 write stream upload failed. Encountered an error while uploading an S3 chunk: Part number must be an integer between 1 and 10000, inclusive

解決此錯誤的方法是開啟資料庫備份壓縮。這會壓縮備份,讓 S3 更容易接收檔案。

執行下列指令以開啟備份壓縮:

exec rdsadmin..rds_set_configuration 'S3 backup compression', 'true';

AWS 官方
AWS 官方已更新 2 年前