> ## 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.

# Take Backups with Revision History and Restore from a Point-in-time

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>;
};

This page provides information about how to take backups with revision history and restore from a point-in-time.

You can create full or incremental backups <InternalLink path="backup">with revision history</InternalLink>:

* Taking full backups with revision history allows you to back up every change made within the garbage collection period leading up to and including the given timestamp.
* Taking incremental backups with revision history allows you to back up every change made since the last backup and within the garbage collection period leading up to and including the given timestamp. You can take incremental backups with revision history even when your previous full or incremental backups were taken without revision history.

You can configure garbage collection periods using the `ttlseconds` <InternalLink path="configure-replication-zones">replication zone setting</InternalLink>. Taking backups with revision history allows for point-in-time restores within the revision history.

<Note>
  If you are creating incremental backups as part of a <InternalLink path="create-schedule-for-backup">backup schedule</InternalLink>, <InternalLink path="architecture/storage-layer#protected-timestamps">protected timestamps</InternalLink> will ensure the backup revision data is not garbage collected, which allows you to lower the GC TTL. See <InternalLink path="create-schedule-for-backup#protected-timestamps-and-scheduled-backups">Protected timestamps and scheduled backups</InternalLink> for more detail.
</Note>

## Supported products

The feature described on this page is available in **CockroachDB Basic**, **CockroachDB Standard**, **CockroachDB Advanced**, and **CockroachDB self-hosted** clusters when you are running <InternalLink version="cockroachcloud" path="take-and-restore-self-managed-backups">self-managed backups</InternalLink>. For a full list of features, refer to <InternalLink path="backup-and-restore-overview#backup-and-restore-support">Backup and restore product support</InternalLink>.

## Create a backup with revision history

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> BACKUP INTO '{collectionURI}' AS OF SYSTEM TIME '-10s' WITH revision_history;
```

For guidance on connecting to Amazon S3, Google Cloud Storage, Azure Storage, and other storage options, read <InternalLink path="use-cloud-storage">Use Cloud Storage</InternalLink>.

## Point-in-time restore

<Danger>
  `RESTORE` will only restore the latest data in an object (table, database, cluster), or the latest data as per an `AS OF SYSTEM TIME` restore. A restore will not include historical data even if you ran your backup with `revision_history`. This means that if you issue an `AS OF SYSTEM TIME` query on a restored object, the query will fail or the response will be incorrect because there is no historical data to query.
</Danger>

If the full or incremental backup was taken [with revision history](#create-a-backup-with-revision-history), you can restore the data as it existed at an arbitrary point-in-time within the revision history captured by that backup. Use the <InternalLink path="as-of-system-time">`AS OF SYSTEM TIME`</InternalLink> clause to specify the point-in-time.

Additionally, if you want to restore a specific incremental backup, you can do so by specifying the `end_time` of the backup by using the <InternalLink path="as-of-system-time">`AS OF SYSTEM TIME`</InternalLink> clause. To find the incremental backup's `end_time`, use <InternalLink path="show-backup">`SHOW BACKUP`</InternalLink>.

If you do not specify a point-in-time, the data will be restored to the backup timestamp; that is, the restore will work as if the data was backed up without revision history.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> RESTORE FROM '/2021/12/13-211056.62' IN '{collectionURI}' AS OF SYSTEM TIME '2021-12-13 10:00:00';
```

To view the available backup subdirectories you can restore from, use <InternalLink path="restore#view-the-backup-subdirectories">`SHOW BACKUPS`</InternalLink>.

## See also

* [`BACKUP`][backup]
* [`RESTORE`][restore]
* <InternalLink path="take-full-and-incremental-backups">Take Full and Incremental Backups</InternalLink>
* <InternalLink path="take-and-restore-encrypted-backups">Take and Restore Encrypted Backups</InternalLink>
* <InternalLink path="take-and-restore-locality-aware-backups">Take and Restore Locality-aware Backups</InternalLink>
* <InternalLink path="cockroach-sql">Use the Built-in SQL Client</InternalLink>
* <InternalLink path="cockroach-commands">`cockroach` Commands Overview</InternalLink>

[backup]: /docs/v26.2/backup

[restore]: restore.html
