> ## Documentation Index
> Fetch the complete documentation index at: https://cockroachlabs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Backup and Restore in CockroachDB Cloud Overview

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

CockroachDB is built to be <InternalLink version="stable" path="demo-cockroachdb-resilience">fault-tolerant through automatic recovery</InternalLink>, but unforeseen disasters can happen. Backup and restore is an important part of a resilient disaster recovery plan. CockroachDB Cloud clusters run routine *managed backups* that are stored by Cockroach Labs in cloud storage. Additionally, you can also manually create *self-managed backups* using [CockroachDB's backup features](#get-started-with-self-managed-backups).

## CockroachDB Cloud backups

CockroachDB Cloud clusters can run two types of backups:

* Automated [managed backups](#managed-backups)
* Manual [self-managed backups](#self-managed-backups)

### Managed backups

<InternalLink version="cockroachcloud" path="backup-and-restore-overview">*Managed backups*</InternalLink> are automated backups of CockroachDB Cloud clusters that are stored by Cockroach Labs in cloud storage. By default, Cockroach Labs takes and retains managed backups in all Cloud clusters. In Standard and Advanced clusters, you can adjust the default managed backup settings to meet your organization's disaster recovery requirements. For details on the available settings for each cluster tier, refer to <InternalLink path="managed-backups#managed-backup-settings">Managed backup settings</InternalLink>.

You can view and configure managed backups through the **Backup and Restore** menu in the Cloud Console and with the <InternalLink path="cloud-api">CockroachDB Cloud API</InternalLink>.

<Note>
  When a cluster is deleted, Cockroach Labs will retain the managed backups for for the <InternalLink path="managed-backups#managed-backup-settings">configured retention time</InternalLink>, after which the backups will be deleted.

  If a customer’s agreement with Cockroach Labs has terminated, all managed backups will be retained for a maximum of 30 days and then deleted. If a backup’s retention time was set to **less** than 30 days, Cockroach Labs will retain the managed backups for the configured retention time, after which the backups will be deleted.

  To restore a backup from a deleted cluster, you must contact the <InternalLink version="stable" path="support-resources">Cockroach Labs Support team</InternalLink>.
</Note>

### Self-managed backups

You can take manual backups and store them in your <InternalLink version="stable" path="use-cloud-storage">cloud storage buckets</InternalLink> using the <InternalLink version="stable" path="backup">`BACKUP`</InternalLink> statement. Self-managed backups are supported in all CockroachDB Cloud products. For a list of backup features that are available, refer to the following section [Get started with self-managed backups](#get-started-with-self-managed-backups).

## Get started with self-managed backups

The following sections outline some of the features and resources for taking backups to your own storage bucket. For more practical examples, refer to the <InternalLink path="take-and-restore-self-managed-backups">Take and Restore Self-Managed Backups</InternalLink> page and the [Video demo](#video-demo).

You can run the following types of self-managed backups:

* <InternalLink version="stable" path="take-full-and-incremental-backups#full-backups">Full backup</InternalLink>: An un-replicated copy of your cluster, database, or table's data. A full backup is the base for any further backups.
* <InternalLink version="stable" path="take-full-and-incremental-backups#incremental-backups">Incremental backup</InternalLink>: A copy of the changes in your data since the specified base backup (either a full backup or a full backup plus an incremental backup).
* <InternalLink version="stable" path="manage-a-backup-schedule">Scheduled backup</InternalLink>: A schedule for periodic backups.
* <InternalLink version="stable" path="take-backups-with-revision-history-and-restore-from-a-point-in-time">Backup with revision history</InternalLink>: A backup with revision history allows you to back up every change made within the garbage collection period leading up to and including the given timestamp.
* <InternalLink version="stable" path="take-backups-with-revision-history-and-restore-from-a-point-in-time">Point-in-time restore</InternalLink>: A restore from an arbitrary point in time within the revision history of a backup.
* <InternalLink version="stable" path="take-and-restore-encrypted-backups">Encrypted backup and restore</InternalLink>: An encrypted backup using a KMS or passphrase.
* <InternalLink version="stable" path="take-and-restore-locality-aware-backups">Locality-aware backup</InternalLink>: A backup where each node writes files to the backup destination that matches the node locality configured at node startup.
* <InternalLink version="stable" path="take-locality-restricted-backups">Locality-restricted backup execution</InternalLink>: A backup with the `EXECUTION LOCALITY` option restricts the nodes that can execute a backup job with a defined locality filter.

### Scheduled backups

<Tip>
  We recommend using scheduled backups to automate daily backups of your cluster.
</Tip>

CockroachDB supports <InternalLink version="stable" path="create-schedule-for-backup">creating schedules for periodic backups</InternalLink>. Scheduled backups ensure that the data to be backed up is protected from garbage collection until it has been successfully backed up. This active management of <InternalLink version="stable" path="architecture/storage-layer#protected-timestamps">protected timestamps</InternalLink> means that you can run scheduled backups at a cadence independent from the <InternalLink version="stable" path="configure-replication-zones">GC TTL</InternalLink> of the data.

For detail on scheduled backup features CockroachDB supports:

* <InternalLink version="stable" path="manage-a-backup-schedule#set-up-monitoring-for-the-backup-schedule">Set up monitoring for the backup schedule</InternalLink>
* <InternalLink version="stable" path="manage-a-backup-schedule#view-the-schedule">View</InternalLink>, <InternalLink version="stable" path="manage-a-backup-schedule">pause</InternalLink>, <InternalLink version="stable" path="manage-a-backup-schedule">resume</InternalLink>, or <InternalLink version="stable" path="manage-a-backup-schedule">drop</InternalLink> the schedule.

### Backup and restore SQL statements

The following table outlines SQL statements you can use to create, configure, pause, and show backup and restore jobs:

| SQL Statement                                                                                                | Description                                                                                                                                                                    |
| ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <InternalLink version="stable" path="backup">`BACKUP`</InternalLink>                                         | Create full and incremental backups.                                                                                                                                           |
| <InternalLink version="stable" path="show-jobs">`SHOW JOBS`</InternalLink>                                   | Show a list of all running jobs or show the details of a specific job by its `job ID`.                                                                                         |
| <InternalLink version="stable" path="pause-job">`PAUSE JOB`</InternalLink>                                   | Pause a backup or restore job with its `job ID`.                                                                                                                               |
| <InternalLink version="stable" path="resume-job">`RESUME JOB`</InternalLink>                                 | Resume a backup or restore job with its `job ID`.                                                                                                                              |
| <InternalLink version="stable" path="cancel-job">`CANCEL JOB`</InternalLink>                                 | Cancel a backup or restore job with its `job ID`.                                                                                                                              |
| <InternalLink version="stable" path="show-backup">`SHOW BACKUP`</InternalLink>                               | Show a backup's details at the <InternalLink version="stable" path="take-full-and-incremental-backups#backup-collections">backup collection's</InternalLink> storage location. |
| <InternalLink version="stable" path="restore">`RESTORE`</InternalLink>                                       | Restore full and incremental backups.                                                                                                                                          |
| <InternalLink version="stable" path="alter-backup">`ALTER BACKUP`</InternalLink>                             | Add a new <InternalLink version="stable" path="take-and-restore-encrypted-backups#use-key-management-service">KMS encryption key</InternalLink> to an encrypted backup.        |
| <InternalLink version="stable" path="create-schedule-for-backup">`CREATE SCHEDULE FOR BACKUP`</InternalLink> | Create a schedule for periodic backups.                                                                                                                                        |
| <InternalLink version="stable" path="alter-backup-schedule">`ALTER BACKUP SCHEDULE`</InternalLink>           | Alter an existing backup schedule.                                                                                                                                             |
| <InternalLink version="stable" path="show-schedules">`SHOW SCHEDULES`</InternalLink>                         | View information on backup schedules.                                                                                                                                          |
| <InternalLink version="stable" path="pause-schedules">`PAUSE SCHEDULES`</InternalLink>                       | Pause backup schedules.                                                                                                                                                        |
| <InternalLink version="stable" path="resume-schedules">`RESUME SCHEDULES`</InternalLink>                     | Resume paused backup schedules.                                                                                                                                                |
| <InternalLink version="stable" path="drop-schedules">`DROP SCHEDULES`</InternalLink>                         | Drop backup schedules.                                                                                                                                                         |

### Backup storage

We recommend taking backups to <InternalLink version="stable" path="use-cloud-storage">cloud storage</InternalLink> and enabling object locking to protect the validity of your backups. CockroachDB supports Amazon S3, Azure Storage, and Google Cloud Storage for backups. Read the following usage information:

* <InternalLink version="stable" path="use-cloud-storage#example-file-urls">Example file URLs</InternalLink> to form the URL that you pass to `BACKUP` and `RESTORE` statements.
* <InternalLink version="stable" path="cloud-storage-authentication">Authentication</InternalLink> to set up authentication to a cloud storage bucket and include those credentials in the URL.

<Danger>
  Cockroach Labs does not officially support S3-compatible storage solutions other than AWS S3, Google Cloud Storage (GCS), and Azure Blob Storage. Some common compatibility issues may be fixed by adding the `AWS_SKIP_CHECKSUM` option to the S3 URLs.

  The <InternalLink version="stable" path="support-resources">Cockroach Labs Support team</InternalLink> is available to offer assistance where possible. If you encounter issues when using unsupported S3-compatible storage, drivers, or frameworks, contact the maintainer directly.
</Danger>

For detail on additional cloud storage features CockroachDB supports:

* Prevent backups from being overwritten or deleted with <InternalLink version="stable" path="use-cloud-storage#immutable-storage">immutable storage buckets</InternalLink>.
* Set a specific storage class for your backups with <InternalLink version="stable" path="use-cloud-storage#amazon-s3-storage-classes">Storage Class (AWS S3 only)</InternalLink>.
* <InternalLink version="stable" path="expire-past-backups">Expire past backups</InternalLink> from cloud storage.

<Note>
  Cockroach Labs recommends enabling Egress Perimeter Controls on CockroachDB Advanced clusters to mitigate the risk of data exfiltration when accessing external resources, such as cloud storage for change data capture or backup and restore operations. See <InternalLink version="cockroachcloud" path="egress-perimeter-controls">Egress Perimeter Controls</InternalLink> for detail and setup instructions.
</Note>

### Backup and restore observability

You can verify that your stored backups are restorable with backup validation. While a successful restore completely validates a backup, the validation tools offer a faster alternative and return an error message if a backup is not valid. There are three "levels" of verifying backups that give increasing validation coverage depending on the amount of runtime you want to invest in validating backups.

Refer to the <InternalLink version="stable" path="backup-validation">Backup Validation</InternalLink> page for detail and examples.

You can track backup jobs using metrics that cover scheduled backups, status of running jobs, and details on completed or failed jobs. Depending on your CockroachDB Cloud deployment, you can track these metrics with:

|                                                                                                               | CockroachDB Standard | CockroachDB Advanced | CockroachDB Basic |
| ------------------------------------------------------------------------------------------------------------- | -------------------- | -------------------- | ----------------- |
| <InternalLink path="metrics#cockroachdb-cloud-console-metrics-page">Cloud Console Metrics page</InternalLink> | ✔                    | ✔                    | ✔                 |
| <InternalLink path="backup-and-restore-monitoring#prometheus">Prometheus</InternalLink>                       | ✔                    | ✔                    |                   |
| <InternalLink path="backup-and-restore-monitoring#datadog">Datadog</InternalLink>                             | ✔                    | ✔                    |                   |

### Backup jobs with locality requirements

CockroachDB supports two backup features that use a node's locality to determine how a backup job runs or where the backup data is stored:

* <InternalLink version="stable" path="take-locality-restricted-backups">Locality-restricted backup execution</InternalLink>: Specify a set of locality filters for a backup job in order to restrict the nodes that can participate in the backup process to that locality. This ensures that the backup job is executed by nodes that meet certain requirements, such as being located in a specific region or having access to a certain storage bucket.
* <InternalLink version="stable" path="take-and-restore-locality-aware-backups">Locality-aware backup</InternalLink>: Partition and store backup data in a way that is optimized for locality. When you run a locality-aware backup, nodes write backup data to the <InternalLink version="stable" path="use-cloud-storage">cloud storage</InternalLink> bucket that is closest to the node locality configured at <InternalLink version="stable" path="cockroach-start">node startup</InternalLink>.

<Note>
  CockroachDB Basic and Standard clusters operate with a different architecture compared to CockroachDB self-hosted and CockroachDB Advanced clusters. These architectural differences have implications for how locality-aware backups can run. Basic and Standard clusters will scale resources depending on whether they are actively in use, which means that it is less likely to have a SQL pod available in every locality. As a result, your cluster may not have a SQL pod in the locality where the data resides, which can lead to the cluster uploading that data to a storage bucket in a locality where you do have active SQL pods. You should consider this as you plan a backup strategy that must comply with <InternalLink version="stable" path="data-domiciling">data domiciling</InternalLink> requirements.
</Note>

## Video demo

For practical examples of running backup and restore jobs, watch the following video:

## See also

* Considerations for using <InternalLink version="stable" path="backup#considerations">backup</InternalLink> and <InternalLink version="stable" path="restore#considerations">restore</InternalLink>.
* <InternalLink version="stable" path="take-full-and-incremental-backups#backup-collections">Backup collections</InternalLink> for details on how CockroachDB stores backups.
* <InternalLink version="stable" path="restoring-backups-across-versions">Restoring backups</InternalLink> across major versions of CockroachDB.
