Backup and Restore SQL Server to Amazon RDS

Published on:

Backup and Restore SQL Server to Amazon RDS Instance

If you are using Amazon RDS, you can't backup and restore in the normal way
with SQL Server Management Studio.

You have to upload your .BAK file to S3 and then run one of the special stored
procedures documented here:
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.Procedural.Importing.html#SQLServer.Procedural.Importing.Native.Using.Restore

Once you have uploaded your .BAK file to S3 just run the following to restore it
to your RDS instance (the stored proc is already included in RDS).

exec msdb.dbo.rds_restore_database
  @restore_db_name='ydoyou',
  @s3_arn_to_restore_from='arn:aws:s3:::some-s3-bucket/ydoyou-raisers-edge.bak';

-- Check the status. Make sure to use the correct task id returned by
-- the above stored proc.
exec msdb.dbo.rds_task_status @db_name='ydoyou', @task_id='2'

Backing up is just the reverse.

exec msdb.dbo.rds_backup_database
  @source_db_name='ydoyou',
  @s3_arn_to_backup_to='arn:aws:s3:::some-s3-bucket/ydoyou-restored.bak',
  @overwrite_S3_backup_file=1;

Below is a specific implementation of the instructions in the link above.

S3 Bucket

some-s3-bucket

Upload your .BAK files to the some-s3-bucket S3 bucket and all will be well.

IAM Policy

The sql-server-backup IAM policy allows you to backup and restore SQL Server
.BAK files from the S3 bucket some-s3-bucket.

sql-server-backup

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

IAM Role

sql-server-backup

Create the sql-server-backup IAM role with one policy, sql-server-backup.

RDS Option Group

sqlserver-options

Create an option group called sqlserver-options. Make sure your RDS instance
uses this option group. You can specify this when you create the db or
afterwards.

The sqlserver-options option group must have an option named
SQLSERVER_BACKUP_RESTORE that points to the sql-server-backup IAM Role.

Thats all folks!