CREATE SCHEDULE FOR BACKUP statement creates a schedule for periodic backups.
For more information about creating, managing, monitoring, and restoring from a scheduled backup, see Manage a Backup Schedule.
Required privileges
Starting in v22.2, CockroachDB introduces a new system-level privilege model that provides finer control over a user’s privilege to work with the database, including taking backups.There is continued support for the legacy privilege model for backups in v22.2, however it will be removed in a future release of CockroachDB. We recommend implementing the new privilege model that follows in this section for all new and existing backups.
BACKUP privilege to a user or role depending on the type of backup:
The listed privileges do not cascade to objects lower in the schema tree. For example, if you are granted database-level
BACKUP privileges, this does not give you the privilege to back up a table. If you need the BACKUP privilege on a database to apply to all newly created tables in that database, use DEFAULT PRIVILEGES. You can add BACKUP to the user or role’s default privileges with ALTER DEFAULT PRIVILEGES.
You can grant the
BACKUP privilege to a user or role without the SELECT privilege on a table. As a result, these users will be able to take backups, but they will not be able to run a SELECT query on that data directly. However, these users could still read this data indirectly, by restoring it from any backups they produce.admin role can run all three types of backups (cluster, database, and table) without the need to grant a specific BACKUP privilege. However, we recommend using the BACKUP privilege model to create users or roles and grant them BACKUP privileges as necessary for stronger access control.
Privileges for managing a backup job
To manage a backup job withPAUSE JOB, RESUME JOB, or CANCEL JOB, users must have at least one of the following:
- Be a member of the
adminrole. - The
CONTROLJOBrole option.
SHOW JOB, users must have at least one of the following:
- The
VIEWJOBprivilege, which allows you to view all jobs (includingadmin-owned jobs). - Be a member of the
adminrole. - The
CONTROLJOBrole option.
GRANT for detail on granting privileges to a role or user.
Required privileges using the legacy privilege model
The following details the legacy privilege model that CockroachDB supports in v22.2 and earlier. Support for this privilege model will be removed in a future release of CockroachDB:- Full cluster backups can only be run by members of the
adminrole. By default, therootuser belongs to theadminrole. - For all other backups, the user must have read access on all objects being backed up. Database backups require
CONNECTprivileges, and table backups requireSELECTprivileges. Backups of user-defined schemas, or backups containing user-defined types, requireUSAGEprivileges.
Destination privileges
You can grant a user theEXTERNALIOIMPLICITACCESS system-level privilege.
Either the EXTERNALIOIMPLICITACCESS system-level privilege or the admin role is required for the following scenarios:
- Interacting with a cloud storage resource using
IMPLICITauthentication. - Using a custom endpoint on S3.
- Using the
cockroach nodelocal uploadcommand.
- Interacting with an Amazon S3 and Google Cloud Storage resource using
SPECIFIEDcredentials. Azure Storage is alwaysSPECIFIEDby default. - Using Userfile storage.
Synopsis
Parameters
For schedules that include both full and incremental backups, CockroachDB will create two schedules (one for each type). See Incremental backup schedules for more information.
Backup options
Schedule options
retry: Retry the backup right away.reschedule: Retry the backup by rescheduling it based on theRECURRINGexpression.pause: Pause the schedule. This requires manual intervention to resume the schedule.
reschedule
on_previous_running | start / skip / wait | If the previous backup started by the schedule is still running, do the following:
start: Start the new backup anyway, even if the previous one is still running.skip: Skip the new backup and run the next backup based on theRECURRINGexpression.wait: Wait for the previous backup to complete.
wait. The option affects backups started by the full backup schedule only. Incremental backups are always set to wait.
ignore_existing_backups | N/A | If backups were already created in the destination that the new schedule references, this option must be passed to acknowledge that the new schedule may be backing up different objects.
updates_cluster_last_backup_time_metric | N/A | (admin privileges required) When set during backup schedule creation, this option updates the schedules_backup_last_completed_time metric for the scheduled backup.
Considerations
- We recommend that you schedule your backups at a cadence that your cluster can keep up with; for example, if a previous backup is still running when it is time to start the next one, adjust the schedule so the backups do not end up falling behind or update the
on_previous_runningoption. - To prevent scheduled backups from falling behind, first determine how long a single backup takes and use that as your starting point for the schedule’s cadence.
- Ensure you are monitoring your backup schedule (e.g., Prometheus) and alerting metrics that will confirm that your backups are completing, but also that they’re not running more concurrently than you expect.
- The
AS OF SYSTEM TIMEclause cannot be set on scheduled backups. Scheduled backups are started shortly after the scheduled time has passed by an internal polling mechanism and are automatically run withAS OF SYSTEM TIMEset to the time at which the backup was scheduled to run. - If you want to schedule a backup using temporary credentials, we recommend that you use
implicitauthentication; otherwise, you’ll need to drop and then recreate schedules each time you need to update the credentials.
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 protected timestamps means that you can run scheduled backups at a cadence independent from the GC TTL of the data. This is unlike non-scheduled backups that are tightly coupled to the GC TTL. See Garbage collection and backups 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 dropping the backup schedule 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 Exclude a table’s data from backups for usage information.
We recommend monitoring your backup schedule to alert for failed backups:
- See the Backup and Restore Monitoring page for a general overview and list of metrics available for backup, scheduled backup, and restore jobs.
- See Set up monitoring for the backup schedule for metrics and monitoring backup schedules specifically.
Incremental backup schedules
The incremental backup schedule is created in a paused state, and is only un-paused on completion of the first, scheduled full backup. This ensures that the first incremental backup is only executed once it has a full backup to build a chain from. Thereafter, the incremental backups are scheduled to run at its specified cadence. Incremental backups always append to the latest, complete full backup. An incremental backup can run concurrently with a full backup, but in such a situation it will continue to append to the previous full backup that has already completed. An incremental backup will always wait for another incremental backup started by the same schedule to complete before running. This prevents incremental backups from backing up overlapping spans of time in the same backup chain. To enforce this, backup schedules created or altered using theon_previous_running option will have the full backup schedule created with the user specified option, but will always default the incremental backup schedule option to on_previous_running = wait.
View and control backup schedules
Once a backup schedule is successfully created, you can do the following:View and control a backup initiated by a schedule
After CockroachDB successfully initiates a scheduled backup, it registers the backup as a job. You can do the following with each individual backup job:
You can also visit the Jobs page of the DB Console to view job details. The
BACKUP statement will return when the backup is finished or if it encounters an error.
Examples
Create a schedule for full backups only
To schedule full backups of clusters, databases, or tables, use theFULL BACKUP ALWAYS clause, for example:
Create a scheduled backup for a cluster
This example creates a schedule for a cluster backup with revision history that’s taken every day at midnight:FULL BACKUP clause is not included, CockroachDB also scheduled a full backup to run @weekly. This is the default cadence for incremental backups RECURRING > 1 hour but <= 1 day.
Create a scheduled backup for a database
This example creates a schedule for a backup of the databasemovr with revision history that’s taken every day 1 minute past midnight (00:00:01):
FULL BACKUP clause is not included, CockroachDB also scheduled a full backup to run @weekly. This is the default cadence for incremental backups RECURRING > 1 hour but <= 1 day.
You will encounter an error if you run multiple backup collections to the same storage URI. Each collection’s URI must be unique.
Create a scheduled backup for a table
This example creates a schedule for a backup of the tablemovr.vehicles with revision history that’s taken every hour:
FULL BACKUP clause is not included, CockroachDB also scheduled a full backup to run @daily. This is the default cadence for incremental backups RECURRING <= 1 hour.
Create a scheduled backup with a scheduled first run
This example creates a schedule for a backup of the tablemovr.vehicles with revision history that’s taken every hour, with its first run scheduled for 2020-09-15 00:00:00.00 (UTC):
FULL BACKUP clause is not included, CockroachDB also scheduled a full backup to run @daily. This is the default cadence for incremental backups RECURRING <= 1 hour.
Create a scheduled backup with schedule options
This example creates a schedule for a cluster backup with theon_previous_running option:
on_previous_running = 'start'. The incremental backup remains PAUSED until the initial full backup is complete.
Because the FULL BACKUP clause is not included, CockroachDB also schedules a full backup to run @daily. This is the default cadence for incremental backups RECURRING <= 1 hour.
View scheduled backup details
When a backup is created by a schedule, 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 view a list of the full backup’s subdirectories.SHOW BACKUP FROM subdirectory IN collectionURIstatement to view a list of the full and incremental backups that are stored in a specific full backup’s subdirectory.- Use the Schedules page in the DB Console to view a list of created backup schedules and their individual details.
SHOW BACKUP.

