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 . For a full list of features, refer to .Backup collections
A backup collection defines a set of backups and their metadata. The collection can contain multiple full backups and their subsequent incremental backups. The path to a backup is created using a date-based naming scheme and stored at the passed with theBACKUP statement.
For a . The backup collection will be stored according to the URIs passed with the BACKUP statement: BACKUP INTO LATEST IN {collectionURI}, {localityURI}, {localityURI}. Here, the collectionURI represents the default locality.
By default, full backups are stored at the root of the collection’s URI in a date-based path, and incremental backups are stored in the /incrementals directory. The following example shows a backup collection created using these default values, where all backups reside in one storage bucket:
users the full backup and incremental backup should have the same storage URI for the full and incremental schedule. (CREATE SCHEDULE FOR BACKUP will automatically create two schedules for the full and incremental backup to the same storage URI.) If there is another backup schedule, for the database accounts, the full and incremental backups for accounts should have the same storage URI. However, the storage URI for the accounts backup collection should be different to the storage URI for the users backup collection.
Full backups
Full backups contain an un-replicated copy of your data and can always be used to restore your cluster. These files are roughly the size of your data and require greater resources to produce than incremental backups. You can take full backups as of a given timestamp. Optionally, you can include the available in the backup. In most cases, it’s recommended to take nightly full backups of your cluster. A cluster backup allows you to do the following:- Restore table(s) from the cluster
- Restore database(s) from the cluster
- Restore a full cluster
To set a target for the amount of backup data written to each backup file, use the
bulkio.backup.file_size .See the page for more details on using cluster settings.Take a full backup
To perform a full cluster backup, use the statement:-
To restore the latest backup of a table:
-
To restore the latest backup of a database:
-
To restore the latest backup of your full cluster:
A full cluster restore can only be run on a destination cluster that has never had user-created databases or tables.
-
To restore a backup from a specific subdirectory:
Incremental backups
If your cluster grows too large for daily full backups, you can take less frequent full backups (e.g., weekly) with daily incremental backups. Incremental backups are storage efficient and faster than full backups for larger clusters. If you are taking backups on a regular cadence, we recommend for your backups.Recommendations for incremental backup frequency
Incremental backups form chains between full backups. Each incremental backup contains only the data that has changed since a base set of backups. This base set of backups must include one full backup and can include multiple incremental backups, which are typically smaller and faster to run than full backups. You can take incremental backups either as of a given timestamp or with full . Cockroach Labs supports up to 48 incremental backups between full backups. Taking more than 48 incremental backups between full backups increases the risk of performance issues due to the size of the backup chain. The maximum supported frequency for incremental backups is every five minutes.Garbage collection and backups
Incremental backups with are created by finding what data has been created, deleted, or modified since the timestamp of the last backup in the chain of backups. For the first incremental backup in a chain, this timestamp corresponds to the timestamp of the base (full) backup. For subsequent incremental backups, this timestamp is the timestamp of the previous incremental backup in the chain. determines the period for which CockroachDB retains revisions of a key. If the GC TTL of the is shorter than the frequency at which you take incremental backups with revision history, then the revisions become susceptible to garbage collection before you have backed them up. This will cause the incremental backup with revision history to fail. We recommend configuring the garbage collection period to be at least the frequency of incremental backups and ideally with a buffer to account for slowdowns. You can configure garbage collection periods using thettlseconds .
If an incremental backup is created outside of the garbage collection period, you will receive a protected ts verification error…. To resolve this issue, see the page.
If you are creating incremental backups as part of a , will ensure the backup revision data is not garbage collected, which allows you to lower the GC TTL. See for more detail.
Take an incremental backup
Periodically run theBACKUP command to take a full backup of your cluster:
LATEST syntax:
/incrementals directory at the root of the backup collection’s directory. With incremental backups in the /incrementals directory, you can apply different lifecycle/retention policies from cloud storage providers to the /incrementals directory as needed.
If it’s ever necessary, you can then use the RESTORE statement to restore your cluster, database(s), and/or table(s). Restoring from incremental backups requires previous full and incremental backups.
To restore from the latest backup in the collection, stored in the default /incrementals collection subdirectory, run:
RESTORE will re-validate when are created from an older version (v20.2.2 and earlier or v20.1.4 and earlier), but restored by a newer version (v21.1.0+). These earlier releases may have included incomplete data for indexes that were in the process of being created.Examples
The examples in this section use one of the following storage URIs:- External connections, which allow you to represent an external storage or sink URI. You can then specify the external connection’s name in statements rather than the provider-specific URI. For detail on using external connections, see the page.
- Amazon S3 connection strings with the default
AUTH=specifiedparameter. For guidance on usingAUTH=implicitauthentication with Amazon S3 buckets instead, read .
Scheduled backups
You can use to set a recurring schedule for full and incremental backups. Include theFULL BACKUP ALWAYS clause for a schedule to take only full backups. For example, to create a schedule for taking full cluster backups:
Exclude a table’s data from backups
In some situations, you may want to exclude a table’s row data from a . For example, you have a table that contains high-churn data that you would like to more quickly than the incremental backup schedule for the database or cluster holding the table. You can use theexclude_data_from_backup = true parameter with a or statement to mark a table’s row data for exclusion from a backup.
It is important to note that the backup produced contains an empty table with the data excluded. The backup process does not attempt to contact the ranges to retrieve data when exclude_data_from_backup = true. Thus, backups will continue to succeed even when some ranges or regions are unavailable, if and only if, the unavailable ranges are in tables excluded from the backups.
Setting this parameter prevents the cluster or database backup from delaying on the key span for this table, and it also respects the configured GC TTL. This is useful when you want to set a shorter garbage collection window for tables containing high-churn data to avoid an accumulation of unnecessary data and improves the reliability in partially unavailable clusters.
Using the movr database as an example:
user_promo_codes table’s data does not need to be included in future backups, you can run the following to exclude the table’s row data:
movr database:
user_promo_codes table has no row data:
exclude_data_from_backup, see .
Advanced examples
For examples of advancedBACKUP and RESTORE use cases, see:

