Overview
Backups are designed primarily for disaster recovery when your cluster loses a majority of its nodes. CockroachDB is built to be fault-tolerant with automatic recovery, but regular backups are an essential part of a robust disaster recovery plan.Scheduled backups ensure that data is protected from garbage collection until successfully backed up. This active management means you can run backups at a cadence independent from the GC TTL of the data.
Creating Backups
Choose backup scope
You can back up different scopes depending on your needs:
- Full cluster: Includes all databases, tables, views, scheduled jobs, and relevant system tables
- Database: Includes all tables and views in the database
- Table: Includes the table with its indexes and views
Configure storage location
Backups require a storage URI pointing to cloud storage:
- AWS S3:
s3://{bucket}/{path}?AWS_ACCESS_KEY_ID={key}&AWS_SECRET_ACCESS_KEY={secret} - Google Cloud Storage:
gs://{bucket}/{path}?AUTH=specified - Azure Storage:
azure://{container}/{path}?AZURE_ACCOUNT_NAME={account}&AZURE_ACCOUNT_KEY={key}
Scheduled Backups
Create automated backup schedules for regular protection:Manage backup schedules
Restoring from Backups
Restore cluster, database, or tables
Full cluster restore
Full cluster restore
Full cluster restores can only run on a destination cluster with no user-created databases or tables:
Database restore
Database restore
Table restore
Table restore
Backup Validation
Verify your backups are restorable without performing a full restore:Backup Performance
The backup process minimizes cluster performance impact through:- Even work distribution: Backup work is distributed across nodes with range replicas
- Elastic CPU limiting: Integration with the elastic CPU limiter prevents backups from overwhelming foreground traffic
- Configurable file sizes: Control backup file sizes with the
bulkio.backup.file_sizecluster setting (default 128 MiB)
Monitor backup jobs
Required Privileges
Backup and restore operations require specific privileges:| Operation | Privilege Required |
|---|---|
| Full cluster backup | admin role membership |
| Database backup | BACKUP privilege on database |
| Table backup | SELECT privilege on tables |
| Full cluster restore | admin role or system-level RESTORE privilege |
| Database restore | System-level RESTORE privilege |
| Table restore | Database-level RESTORE privilege |
Best Practices
Storage considerations
Storage considerations
- Enable object locking in cloud storage buckets to prevent backup tampering
- Use separate storage locations for different backup collections
- Test restores regularly to ensure backup validity
- Monitor backup job completion and storage utilization
Backup strategy
Backup strategy
- Schedule automated backups with appropriate frequency for your RPO requirements
- Combine full and incremental backups to optimize storage and backup time
- Use revision history for point-in-time recovery capabilities
- Store backups in multiple regions for additional disaster recovery protection
Security
Security
- Use encrypted backups with KMS or passphrases for sensitive data
- Restrict access to backup storage using IAM roles and policies
- Audit backup and restore operations using SQL audit logging
- Exclude sensitive table data using
exclude_data_from_backupparameter
Troubleshooting
Common issues
Backup fails with 'transaction deadline exceeded'
Backup fails with 'transaction deadline exceeded'
This error indicates the backup is taking too long. Consider:
- Using
DETACHEDoption for asynchronous execution - Breaking large backups into smaller database or table backups
- Increasing the
gc.ttlsecondsreplication zone setting
Restore fails with 'table already exists'
Restore fails with 'table already exists'
The destination database contains tables with the same names. You can:
- Drop existing tables before restoring
- Use
new_db_nameoption to restore to a different database - Use
into_dboption for table restores
Cannot restore multi-region backup to single-region cluster
Cannot restore multi-region backup to single-region cluster
Multi-region backups cannot be restored to single-region clusters. Use
skip_localities_check option only if you understand the implications, or create a multi-region destination cluster.