- Set up monitoring for the backup schedule
- View scheduled backup details
- View and control the backup schedule
- View and control a backup initiated by a schedule
- Restore from a scheduled backup
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 .Considerations
Protected timestamps and scheduled backups
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 means that you can run scheduled backups at a cadence independent from the of the data. This is unlike non-scheduled backups that are tightly coupled to the GC TTL. See for more detail. The data being backed up will not be eligible for garbage collection until a successful backup completes. At this point, the schedule will release the existing protected timestamp record and write a new one to protect data for the next backup that is scheduled to run. It is important to consider that when a scheduled backup fails there will be an accumulation of data until the next successful backup. Resolving the backup failure or will make the data eligible for garbage collection once again. You can also use theexclude_data_from_backup option with a scheduled backup as a way to prevent protected timestamps from prolonging garbage collection on a table. See the example for usage information.
Backup collection storage URI and schedule backups
You will encounter an error if you run multiple to the same storage URI. Backup collections can contain multiple full and incremental backups, but each collection’s URI must be unique. If you are using backup schedules, each schedule must have a unique URI. For example, if you have a backup schedule running backups for the databaseusers 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.
Backup compactions for scheduled backups
When are enabled, scheduled backups automatically merge incremental backups, allowing you to reduce the frequency of full backups without reducing the frequency of incremental backups. You can maintain the same RPO while limiting storage costs. Enabling backup compactions also improves restore performance and is required for usingWITH EXPERIMENTAL COPY.
Compactions run automatically on scheduled backups when the cluster setting is set to 4.
For more information, refer to .
Create a new backup schedule
To create a new backup schedule, use the statement. For example:schedule_label is created to take daily (incremental) backups with revision history in AWS S3, with the first backup being taken now. A second is also created by default. Both schedules have the same label (i.e., schedule_label).
For more information about the different options available when creating a backup schedule, see .
Further guidance on connecting to Amazon S3, Google Cloud Storage, Azure Storage, and other storage options is outlined in .
Set up monitoring for the backup schedule
We recommend that you , and alert when there are anomalies such as backups that have failed or no backups succeeding over a certain amount of time—at which point, you can inspect schedules by running . Metrics for scheduled backups fall into two categories:-
Backup schedule-specific metrics, aggregated across all schedules:
-
schedules.BACKUP.started: The total number of backups started by a schedule. -
schedules.BACKUP.succeeded: The number of backups started by a schedule that succeeded. -
schedules.BACKUP.failed: The number of backups started by a schedule that failed. Whenschedules.BACKUP.failedincrements, run to check which schedule is affected and to inspect the error in thestatuscolumn. If a backup job encounters too many retryable errors, it will enter a with the most recent error, which allows subsequent backups the chance to succeed. Refer to the page for metrics to track backup failures. -
schedules.BACKUP.protected_age_sec: The age of the oldest record protected by backup schedules. -
schedules.BACKUP.protected_record_count: The number of records held by backup schedules.
-
-
Scheduler-specific metrics:
-
schedules.round.reschedule-wait: The number of schedules that were rescheduled due to a currently running job. A value greater than 0 indicates that a previous backup was still running when a new scheduled backup was supposed to start. This corresponds to the schedule option. -
schedules.round.reschedule-skip: The number of schedules that were skipped due to a currently running job. A value greater than 0 indicates that a previous backup was still running when a new scheduled backup was supposed to start. This corresponds to the schedule option.
-
schedules.round.reschedule-wait and schedules.round.reschedule-skip are gauge metrics and can be graphed. A continual positive value for either of these metrics may indicate a misconfigured backup cadence, and you should consider adjusting the cadence to avoid waiting for or skipping the next backup.View scheduled backup details
When a , it is stored within a collection of backups in the given location. To view details for a backup created by a schedule, you can use the following:SHOW BACKUPS IN collectionURIstatement to .SHOW BACKUP FROM subdirectory IN collectionURIstatement to .- Use the in the to view a list of created backup schedules and their individual details.
View and control the backup schedule
Once a backup schedule is successfully created, you can view the schedule, pause the schedule, resume the schedule, or drop the schedule.View the schedule
id(s) inside the SHOW JOBS statement:
Pause the backup job
To pause jobs for a specific , use the schedule’sid:
id(s) inside the PAUSE JOBS statement:
Resume the backup job
To resume jobs for a specific , use the schedule’sid:
id(s) inside the PAUSE JOBS statement:
Cancel the backup job
To cancel jobs for a specific , use the schedule’sid:
id(s) inside the CANCEL JOBS statement:
Restore from a scheduled backup
To restore from a scheduled backup, use the statement:SHOW BACKUP statement.

