Backup SQL Server databases to a Cloud Storage bucket

This tutorial describes how to directly back up a Microsoft SQL Server 2022database to a Cloud Storage bucket, and restore it later on. Introduced in SQL Server 2022, the SQL Server backup native feature offers a seamlessand cost-effective strategy for cloud-based disaster recovery and datamigration.

The SQL Server backup native feature leverages theBACKUP TO URL andRESTORE FROM URL commands that support S3-compatible objectstorage, including Cloud Storage. This eliminates the need forintermediate local storage, simplifying the backup workflow and reducingoperational overhead.

This tutorial is intended for database administrators and engineers.

Objectives

This tutorial shows you how to complete the following tasks to reachyour objective:

  • Create a new Cloud Storage bucket
  • Configure a SQL Server connector
  • Back up your database
  • Restore your database from the backup

Costs

In this document, you use the following billable components of Google Cloud:

To generate a cost estimate based on your projected usage, use thepricing calculator.

New Google Cloud users might be eligible for afree trial.

When you finish the tasks that are described in this document, you can avoid continued billing by deleting the resources that you created. For more information, seeClean up.

Before you begin

  1. For this tutorial, you need a Google Cloud project. You can create anew one, or select a project you already created:

    1. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

      Roles required to select or create a project

      • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
      • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
      Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

      Go to project selector

    2. Verify that billing is enabled for your Google Cloud project.

    3. In the Google Cloud console, activate Cloud Shell.

      Activate Cloud Shell

  2. Ensure that Microsoft SQL Server 2022 or later is installed and running.

  3. Make sure that both your Google Cloud project and SQL Server have therequired permissions to perform backup and restoration tasks.

  4. Make sure that the user or service account associated with access keys has permissions tocreate and view objects in Cloud Storage bucket.

  5. Make sure that the SQL Server user account used to perform backup hasbackup database and backup log permissions.

Create a Cloud Storage bucket

You cancreate a Cloud Storage bucket using the Google Cloud console or usinggcloud storage command.

To create Cloud Storage bucket usingthegcloud storage command, use the followingsteps.

  1. Select your Google Cloud project.

    gcloud config set projectPROJECT_ID
  2. Create the bucket. To create the bucket run thegcloud storage buckets create command as follows.

      gcloud storage buckets create gs://BUCKET_NAME --location=BUCKET_LOCATION

    Replace the following:

  • BUCKET_NAME: with a unique name for your bucket.
  • BUCKET_LOCATION: with the location of your bucket.

Configure S3 interoperability and create an access key

To allow SQL Server to communicate with Cloud Storage using the S3 protocol, you must enable interoperability and generate an access key using the following steps:

  1. Navigate to your Cloud Storage settings in the Google Cloud console.

    Go to Cloud Storage settings

  2. Select theInteroperability tab.

  3. UnderAccess keys for your user account, clickCreate a key.

    Bucket Access Keys

  4. Save the generatedAccess key andSecret securely. You will need them in the next step.

For production environments, we recommend that you use aservice account hash-based message authentication code (HMAC) key for better security and management.

Add Credentials to SQL Server

To allow SQL Server to authenticate with your Cloud Storage bucket,you must create a credential object within SQL Server to store theCloud Storage access key and secret. To do this, run the followingT-SQL command in SQL Server Management Studio (SSMS).

CREATE CREDENTIALCREDENTIAL_NAMEWITH    IDENTITY = 'S3 Access Key',    SECRET = 'ACCESS_KEY:SECRET';

Replace the following:

  • CREDENTIAL_NAME: with a name for your credentials.
  • ACCESS_KEY: with you access key you created in the previous section.
  • SECRET: with the secret you created in the previous section.

IDENTITY = 'S3 Access Key' is crucial as it tells SQL Server to use the new S3 connector. The secret should be formatted as the access key, followed by a colon, and then the secret key.

Example:

CREATE CREDENTIAL sql_backup_credentialsWITH    IDENTITY = 'S3 Access Key',    SECRET = 'GOOGGE3SVF7OQE5JRMLQ7KWB:b31Pl8Tx1ARJfdGOsbgMFQNbk3nPdlT2UCYzs1iC';

Back up your data to Cloud Storage

With the credential in place, you can now back up your database directly to the Cloud Storage bucket using theBACKUP DATABASE command with theTO URL option. Prefix the URL withs3://storage.googleapis.com to use the S3 connector, as follows.

BACKUP DATABASEDATABASE_NAMETO URL = 's3://storage.googleapis.com/BUCKET_NAME/FOLDER_NAME/BACKUP_FILE_NAME.bak'WITH    CREDENTIAL = 'CREDENTIAL_NAME',    FORMAT,    STATS = 10,    MAXTRANSFERSIZE = 10485760,    COMPRESSION;

Replace the following:

  • CREDENTIAL_NAME The name of the credential you created instep 3. For example —sql_backup_credentials.
  • BUCKET_NAME The name of the bucket you created instep 1.
  • FOLDER_NAME The name of the folder you want to store the backup file in.
  • BACKUP_FILE_NAME The name of the backup file.

The descriptions of the backup parameters used in the command are as follows:

  • FORMAT: overwrites the existing backup files and creates a new media set.
  • STATS: reports the backup progress.
  • COMPRESSION: compresses the backup, which can reduce file size and upload time.
  • MAXTRANSFERSIZE: recommended to avoid I/O errors with large backup files.

For more information seeSQL Server back up to URL for S3-compatible object storage.

For very large databases, you can split the backup into multiple files as follows.

BACKUP DATABASEDATABASE_NAMETO    URL = 's3://storage.googleapis.com/BUCKET_NAME/FOLDER_NAME/BACKUP_FILE_NAME_0.bak',    URL = 's3://storage.googleapis.com/BUCKET_NAME/FOLDER_NAME/BACKUP_FILE_NAME_1.bak'    -- ... more filesWITH    CREDENTIAL = 'CREDENTIAL_NAME',    FORMAT,    STATS = 10,    MAXTRANSFERSIZE = 10485760,    COMPRESSION;

Restore your data from Cloud Storage

You can restore your database directly from a backup file stored in Cloud Storage using theRESTORE DATABASE command as follows.

RESTORE DATABASEDATABASE_NAMEFROM URL = 's3://storage.googleapis.com/BUCKET_NAME/FOLDER_NAME/BACKUP_FILE_NAME.bak'WITH    CREDENTIAL = 'CREDENTIAL_NAME';

Replace the following:

  • CREDENTIAL_NAME The name of the credential you created instep 3. For example —sql_backup_credentials.
  • BUCKET_NAME The name of the bucket you created instep 1.
  • FOLDER_NAME The name of the folder you want to store the backup file in.
  • BACKUP_FILE_NAME The name of the backup file.
Note: If database backup was split into multiple files, make sure to include all of them during restore process.

Clean up

To avoid incurring charges to your Google Cloud account for the resourcesused in this tutorial:

Delete the project

    Caution: Deleting a project has the following effects:
    • Everything in the project is deleted. If you used an existing project for the tasks in this document, when you delete it, you also delete any other work you've done in the project.
    • Custom project IDs are lost. When you created this project, you might have created a custom project ID that you want to use in the future. To preserve the URLs that use the project ID, such as anappspot.com URL, delete selected resources inside the project instead of deleting the whole project.
  1. In the Google Cloud console, go to theManage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then clickDelete.
  3. In the dialog, type the project ID, and then clickShut down to delete the project.

What's next

  • Explore reference architectures, diagrams, and best practices about Google Cloud.Take a look at ourCloud Architecture Center.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-11-25 UTC.