title | summary | toc |
---|---|---|
BACKUP |
Back up your CockroachDB cluster to a cloud storage services such as AWS S3, Google Cloud Storage, or other NFS. |
true |
{{site.data.alerts.callout_danger}}
The BACKUP
feature is only available to enterprise users. For non-enterprise backups, see cockroach dump
.
{{site.data.alerts.end}}
CockroachDB's BACKUP
statement allows you to create full or incremental backups of your cluster's schema and data that are consistent as of a given timestamp. Backups can be with or without revision history.
Because CockroachDB is designed with high fault tolerance, these backups are designed primarily for disaster recovery (i.e., if your cluster loses a majority of its nodes) through RESTORE
. Isolated issues (such as small-scale node outages) do not require any intervention.
You can backup entire tables (which automatically includes their indexes) or views. Backing up a database simply backs up all of its tables and views.
{{site.data.alerts.callout_info}}
BACKUP
only offers table-level granularity; it does not support backing up subsets of a table.
{{site.data.alerts.end}}
Dependent objects must be backed up at the same time as the objects they depend on.
Object | Depends On |
---|---|
Table with foreign key constraints | The table it REFERENCES ; however, this dependency can be removed during the restore. |
Table with a sequence | The sequence it uses; however, this dependency can be removed during the restore. |
Views | The tables used in the view's SELECT statement. |
Interleaved tables | The parent table in the interleaved hierarchy. |
Every backup you create includes system.users
, which stores your users and their passwords. To restore your users, you must use this procedure.
Restored tables inherit privilege grants from the target database; they do not preserve privilege grants from the backed up table because the restoring cluster may have different users.
Table-level privileges must be granted to users after the restore is complete.
CockroachDB offers two types of backups: full and incremental.
Full backups contain an unreplicated 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 and (optionally) include the available revision history.
Incremental backups are smaller and faster to produce than full backups because they contain only the data that has changed since a base set of backups you specify (which must include one full backup, and can include many incremental backups). You can take incremental backups either as of a given timestamp or with full revision history.
Note the following restrictions:
-
Incremental backups can only be created within the garbage collection period of the base backup's most recent timestamp. This is because incremental backups are created by finding which data has been created or modified since the most recent timestamp in the base backup––that timestamp data, though, is deleted by the garbage collection process.
You can configure garbage collection periods using the
ttlseconds
replication zone setting. -
It is not possible to create an incremental backup if one or more tables were created, dropped, or truncated after the full backup. In this case, you must create a new full backup.
{% include {{ page.version.version }}/misc/beta-warning.md %}
You can create full or incremental backups with revision history:
- 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
replication zone setting. Taking backups with revision history allows for point-in-time restores within the revision history.
The BACKUP
process minimizes its impact to the cluster's performance by distributing work to all nodes. Each node backs up only a specific subset of the data it stores (those for which it serves writes; more details about this architectural concept forthcoming), with no two nodes backing up the same data.
For best performance, we also recommend always starting backups with a specific timestamp at least 10 seconds in the past. For example:
> BACKUP...AS OF SYSTEM TIME '-10s';
This improves performance by decreasing the likelihood that the BACKUP
will be retried because it contends with other statements/transactions. However, because AS OF SYSTEM TIME
returns historical data, your reads might be stale.
We recommend automating daily backups of your cluster.
To automate backups, you must have a client send the BACKUP
statement to the cluster.
Once the backup is complete, your client will receive a BACKUP
response.
After CockroachDB successfully initiates a backup, it registers the backup as a job, which you can view with SHOW JOBS
.
After the backup has been initiated, you can control it with PAUSE JOB
, RESUME JOB
, and CANCEL JOB
.
{{site.data.alerts.callout_info}}
The BACKUP
statement cannot be used within a transaction.
{{site.data.alerts.end}}
Only members of the admin
role can run BACKUP
. By default, the root
user belongs to the admin
role.
Parameter | Description |
---|---|
table_pattern |
The table or view you want to back up. |
name |
The name of the database you want to back up (i.e., create backups of all tables and views in the database). |
destination |
The URL where you want to store the backup. For information about this URL structure, see Backup File URLs. |
AS OF SYSTEM TIME timestamp |
Back up data as it existed as of timestamp . The timestamp must be more recent than your cluster's last garbage collection (which defaults to occur every 25 hours, but is configurable per table). |
WITH revision_history |
Create a backup with full revision history that records every change made to the cluster within the garbage collection period leading up to and including the given timestamp. |
INCREMENTAL FROM full_backup_location |
Create an incremental backup using the full backup stored at the URL full_backup_location as its base. For information about this URL structure, see Backup File URLs.Note: It is not possible to create an incremental backup if one or more tables were created, dropped, or truncated after the full backup. In this case, you must create a new full backup. |
incremental_backup_location |
Create an incremental backup that includes all backups listed at the provided URLs. Lists of incremental backups must be sorted from oldest to newest. The newest incremental backup's timestamp must be within the table's garbage collection period. For information about this URL structure, see Backup File URLs. For more information about garbage collection, see Configure Replication Zones. |
We will use the URL provided to construct a secure API call to the service you specify. The path to each backup must be unique, and the URL for your backup's destination/locations must use the following format:
{% include {{ page.version.version }}/misc/external-urls.md %}
Per our guidance in the Performance section, we recommend starting backups from a time at least 10 seconds in the past using AS OF SYSTEM TIME
.
{% include copy-clipboard.html %}
> BACKUP bank.customers \
TO 'gs://acme-co-backup/database-bank-2017-03-27-weekly' \
AS OF SYSTEM TIME '-10s';
{% include copy-clipboard.html %}
> BACKUP bank.customers, bank.accounts \
TO 'gs://acme-co-backup/database-bank-2017-03-27-weekly' \
AS OF SYSTEM TIME '-10s';
{% include copy-clipboard.html %}
> BACKUP DATABASE bank \
TO 'gs://acme-co-backup/database-bank-2017-03-27-weekly' \
AS OF SYSTEM TIME '-10s';
{% include copy-clipboard.html %}
> BACKUP DATABASE bank \
TO 'gs://acme-co-backup/database-bank-2017-03-27-weekly' \
AS OF SYSTEM TIME '-10s' WITH revision_history;
Incremental backups must be based off of full backups you've already created.
{% include copy-clipboard.html %}
> BACKUP DATABASE bank \
TO 'gs://acme-co-backup/db/bank/2017-03-29-nightly' \
AS OF SYSTEM TIME '-10s' \
INCREMENTAL FROM 'gs://acme-co-backup/database-bank-2017-03-27-weekly', 'gs://acme-co-backup/database-bank-2017-03-28-nightly';
{% include copy-clipboard.html %}
> BACKUP DATABASE bank \
TO 'gs://acme-co-backup/database-bank-2017-03-29-nightly' \
AS OF SYSTEM TIME '-10s' \
INCREMENTAL FROM 'gs://acme-co-backup/database-bank-2017-03-27-weekly', 'gs://acme-co-backup/database-bank-2017-03-28-nightly' WITH revision_history;