Home / AWS

AWSRunbookIntermediate

RDS for SQL Server native backup and restore with S3: option group, IAM role and failed tasks

Take .bak backups from RDS for SQL Server to S3 and restore them, set up the option group and IAM role, track tasks with rds_task_status and fix the errors that stop them.

Deepak Bhardwaj7 min read

Applies toAmazon RDS for SQL Server (all editions) with the SQLSERVER_BACKUP_RESTORE option; Amazon S3; AWS KMS

When you need this

Automated RDS snapshots restore a whole instance. They don't give you a .bak file. You need native backup and restore when you want to:

  • Copy one database to another RDS instance, an EC2 SQL Server or an on-premises server.
  • Load a .bak from on-premises into RDS.
  • Keep a database-level copy before a risky change or a schema release.
  • Hand a copy of one database to another team or account.

RDS doesn't allow BACKUP DATABASE ... TO DISK. Instead you call stored procedures in msdb, and RDS writes to and reads from an S3 bucket through an IAM role attached by an option group.

One-time setup

1. S3 bucket and IAM role

The bucket must be in the same Region as the DB instance. Create a role that RDS can assume:

cat > trust.json <<'EOF'
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "Service": "rds.amazonaws.com" },
    "Action": "sts:AssumeRole"
  }]
}
EOF

aws iam create-role --role-name rds-sqlserver-native-backup \
  --assume-role-policy-document file://trust.json

Grant it access to the bucket:

cat > s3.json <<'EOF'
{
  "Version": "2012-10-17",
  "Statement": [
    { "Effect": "Allow",
      "Action": ["s3:ListBucket", "s3:GetBucketLocation"],
      "Resource": "arn:aws:s3:::sql-native-backups" },
    { "Effect": "Allow",
      "Action": ["s3:GetObject", "s3:PutObject",
                 "s3:ListMultipartUploadParts", "s3:AbortMultipartUpload"],
      "Resource": "arn:aws:s3:::sql-native-backups/*" }
  ]
}
EOF

aws iam put-role-policy --role-name rds-sqlserver-native-backup \
  --policy-name s3-access --policy-document file://s3.json

If you'll encrypt the backup files with a KMS key, or the bucket uses SSE-KMS, also allow kms:Encrypt, kms:Decrypt, kms:GenerateDataKey and kms:DescribeKey on that key. Make sure the key policy allows the role too.

2. Option group

Use an option group that matches the engine edition and major version of your instance:

aws rds create-option-group \
  --option-group-name sqlserver-se-2019-native-backup \
  --engine-name sqlserver-se --major-engine-version 15.00 \
  --option-group-description "Native backup and restore"

aws rds add-option-to-option-group \
  --option-group-name sqlserver-se-2019-native-backup \
  --options "OptionName=SQLSERVER_BACKUP_RESTORE,OptionSettings=[{Name=IAM_ROLE_ARN,Value=arn:aws:iam::111122223333:role/rds-sqlserver-native-backup}]" \
  --apply-immediately

aws rds modify-db-instance --db-instance-identifier sql-prod-01 \
  --option-group-name sqlserver-se-2019-native-backup --apply-immediately

Warning

If the instance already has a custom option group with other options (for example TDE or SSAS), add SQLSERVER_BACKUP_RESTORE to that group. Don't swap it for a new group, or you'll lose the other options. Some options can't be removed once they're in use.

Check that the option is active:

aws rds describe-db-instances --db-instance-identifier sql-prod-01 \
  --query "DBInstances[0].OptionGroupMemberships"

The status should be in-sync.

Back up a database to S3

EXEC msdb.dbo.rds_backup_database
  @source_db_name = 'Sales',
  @s3_arn_to_backup_to = 'arn:aws:s3:::sql-native-backups/sales/Sales_full_20261124.bak',
  @overwrite_s3_backup_file = 1,
  @type = 'FULL';

Optional parameters:

Parameter Use
@type = 'DIFFERENTIAL' Differential backup, based on the last full backup
@number_of_files = 4 Split large backups into several files. Put * in the file name, for example Sales_full_*.bak
@kms_master_key_arn Encrypt the backup files on the client side with that KMS key. You need the same key to restore
@overwrite_s3_backup_file = 1 Replace an existing object with the same name

Tip

Native backups don't break the automated backup chain on RDS, so you can run them at any time. They do add I/O load. Run large ones outside peak hours.

Restore a database from S3

EXEC msdb.dbo.rds_restore_database
  @restore_db_name = 'Sales_copy',
  @s3_arn_to_restore_from = 'arn:aws:s3:::sql-native-backups/sales/Sales_full_20261124.bak';

For a multi-file backup, use the same * pattern you used for the backup. To apply differentials or logs afterwards, restore the full backup with @with_norecovery = 1, apply the next files and then finish:

EXEC msdb.dbo.rds_restore_database
  @restore_db_name = 'Sales_copy',
  @s3_arn_to_restore_from = 'arn:aws:s3:::sql-native-backups/sales/Sales_full_20261124.bak',
  @with_norecovery = 1;

EXEC msdb.dbo.rds_restore_database
  @restore_db_name = 'Sales_copy',
  @s3_arn_to_restore_from = 'arn:aws:s3:::sql-native-backups/sales/Sales_diff_20261124.bak',
  @type = 'DIFFERENTIAL',
  @with_norecovery = 0;

If the last file was restored with NORECOVERY, bring the database online with:

EXEC msdb.dbo.rds_finish_restore @db_name = 'Sales_copy';

Track and cancel tasks

Each call returns a task ID and runs in the background. Check progress like this:

EXEC msdb.dbo.rds_task_status @db_name = 'Sales_copy';
-- or for a single task
EXEC msdb.dbo.rds_task_status @task_id = 7;

The lifecycle column moves through CREATED, IN_PROGRESS and then SUCCESS or ERROR. When a task fails, read the task_info column. It holds the real error message. % complete shows progress on long tasks.

Cancel a running task:

EXEC msdb.dbo.rds_cancel_task @task_id = 7;

The task goes to CANCEL_REQUESTED and then CANCELLED.

Errors in task_info and how to fix them

Symptom in task_info Likely cause Fix
Access Denied on the S3 object Role missing s3:PutObject/GetObject, bucket policy deny or an SCP Fix the role policy. Check the bucket policy for Deny statements, such as encryption or VPC endpoint conditions
Could not find stored procedure rds_backup_database Option not attached or not yet in-sync Attach the option group and wait for in-sync
File already exists Same S3 key used again Use a new name or @overwrite_s3_backup_file = 1
Key does not exist / KMS access denied Encrypted backup restored without the right key, or the key policy blocks the role Pass @kms_master_key_arn with the key used for the backup and grant the role kms:Decrypt
Database already exists Target name in use on the instance Restore under a new name, or drop the old database first after you've checked it
Backup from newer version .bak taken on a higher SQL Server version than the target Restore to an instance on the same or a later major version. SQL Server can't restore to an older version
Task waits in CREATED Other backup or restore tasks are running on the instance Wait for them, or cancel the ones you don't need
Bucket in a different Region Cross-Region ARN Copy the file to a bucket in the instance's Region first

Check the IAM side from the CLI:

aws iam simulate-principal-policy \
  --policy-source-arn arn:aws:iam::111122223333:role/rds-sqlserver-native-backup \
  --action-names s3:PutObject s3:GetObject \
  --resource-arns arn:aws:s3:::sql-native-backups/sales/Sales_full_20261124.bak

Caution

Don't drop a production database to make room for a restore under the same name until the restore source has been checked. First restore under a new name, check row counts and run DBCC CHECKDB, then rename.

Things native backup can't do

  • Databases with TDE can't be backed up natively on RDS. Check the current documentation for your version before you plan around it.
  • You can't back up master, model, msdb or tempdb. Script logins and SQL Agent jobs separately.
  • File size limits and the maximum number of files per backup are set by AWS. Check the current limits for very large databases.

Prevent it next time

  • Create the option group and role with infrastructure as code, so every SQL Server instance can back up from day one.
  • Add an S3 lifecycle rule on the backup prefix, so old .bak files expire or move to a cheaper storage class.
  • Schedule a SQL Agent job that runs rds_backup_database and then checks rds_task_status, and alert if the lifecycle is ERROR.
  • Test a restore to a scratch instance every quarter. A backup you haven't restored is not yet a backup you can rely on.