Backup to S3 from SQL Server
As we all know backing up to Azure Storage has been easy for some years now, but only since SQL Server 2022 have Microsoft supported backing up to S3. This includes third party providers that implement the S3 bucket protocol.
Why do this?
To keep backups safe and secure, best practise dictates that backup files should be off-site. Rather than backing up locally to a volume and then copying the file to S3, money can be saved by not having to provision space for local volumes. It is common in AWS to use an FSx volume for backups, or even a mounted EBS volume, but these costs can be removed by backing up directly to an S3 bucket.
It is best to backup to a different region to the one your SQL Server is hosted in. If your S3-compatible storage provider supports distributed regions, then this option can be added to the BACKUP statement to specify which region.
WITH BACKUP_OPTIONS = '{"s3": {"region":"eu-west-1"}}'
In my case I don’t need this because my S3 bucket is in a different region to my SQL Server already.
Requirements
To back up to URL an Access Key and Secret Key is required. If you do not have these, see your AWS administrator, they can be obtained from the AWS console.
Create a credential using the s3 bucket endpoint where
<bucket_name>
: Bucket Name<region>
: is the AWS region of the bucket. e.g.eu-west-1
<path>
: is the path inside the bucket to limit this credential to
|
|
e.g.
|
|
Backup database to URL
This will ALSO allow you to backup to sub-directories. You must specify the full path inside the bucket.
|
|
output:
|
|
Ola Hallengren command
|
|
Also check out the @BackupOptions
parameter for more S3 options.
Troubleshooting
The request could not be performed because of an I/O device error
If you get the below error it could be because the file sizes are too big.
|
|
Try splitting the files up with a command like this using the @MaxTransferSize
and @NumberOfFiles
parameters:
|
|
Operating system error 5(Access is denied.)
Permissions on the bucket are incorrect. Make sure that ListBucket
, GetObject
, PutObject
have been granted. The policy for the bucket should look something like this:
|
|
The value for the parameter @URL is not supported.
If you get this error
|
|
You need to get the latest version of Ola Hallengren scripts from https://ola.hallengren.com/scripts/MaintenanceSolution.sql
Performance tests
From EC2 instance to S3
125MB/s throughput
On-Prem to S3
120MB/s throughput
References
Backup and restore with S3-compatible object storage - SQL Server | Microsoft Learn
SQL Server backup to URL for S3-compatible object storage - SQL Server | Microsoft Learn