Backup
Links
BACKUPstatement to efficiently back up cluster's schemas and data to NFSRESTOREstatement to efficiently restore schema and data as necessary.
Backup a cluster (To S3)
Full Backup
BACKUP INTO 's3://{BUCKET NAME}?AWS_ACCESS_KEY_ID={KEY ID}&AWS_SECRET_ACCESS_KEY={SECRET ACCESS KEY}' AS OF SYSTEM TIME '-10s';
Backup database/s
Requires an enterprise license
BACKUP DATABASE bank, employees INTO 's3://{BUCKET NAME}?AWS_ACCESS_KEY_ID={KEY ID}&AWS_SECRET_ACCESS_KEY={SECRET ACCESS KEY}' AS OF SYSTEM TIME '-10s';
Perform Core backup and restore
Backup
cockroach dump <database_name> <flags> > backup.sql
Restore
cockroach sql --database=[database name] < backup.sql
Scheduling automated backups
Fully automated backups
CREATE SCHEDULE core_schedule_label
FOR BACKUP INTO 's3://{BUCKET NAME}/{PATH}?AWS_ACCESS_KEY_ID={KEY ID}&AWS_SECRET_ACCESS_KEY={SECRET ACCESS KEY}'
RECURRING '@daily'
FULL BACKUP ALWAYS
WITH SCHEDULE OPTIONS first_run = 'now';
Incremental Backups
If cluster grows too large for nightly full backups,
- less frequent full backups (e.g., weekly)
- Nightly incremental backups.
Incremental backups are storage efficient and faster than full backups for larger clusters.
BACKUP INTO LATEST IN '{collectionURI}';
This will add the incremental backup to the default /incrementals directory at the root of the backup collection's directory.
Incremental Backups from existing full backups
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.
View Backups at collection URI
SHOW BACKUPS IN 's3://{bucket name}/{path}?AWS_ACCESS_KEY_ID={placeholder}&AWS_SECRET_ACCESS_KEY={placeholder}';
Restore from Collection URI
RESTORE FROM LATEST IN '{collectionURI}';