| name | create-incremental-backups-with-backup-into-latest |
| description | Create incremental backups using BACKUP INTO LATEST command to capture only data changed since last backup. Use when user asks for "incremental backup", "backup changes only", "reduce backup size", "hourly backups", or wants storage-efficient frequent backups. |
| metadata | {"domain":"Backup and Restore","bloom_level":"Apply","version":"1.0.0","cockroachdb_version":"v26.1.0+","status":"complete","tested":false} |
Create Incremental Backups with BACKUP INTO LATEST
Domain: Backup and Restore
Bloom's Level: Apply
CockroachDB Version: v26.1.0+
What This Skill Teaches
This skill teaches you how to create storage-efficient incremental backups using the BACKUP INTO LATEST command. You'll learn to capture only changed data since the last backup, build backup chains, and optimize storage costs while maintaining comprehensive backup coverage.
When to use this skill:
- Implementing hourly or frequent backup schedules
- Reducing backup storage costs by 70-90%
- Meeting tight RPO requirements without excessive storage
- Building automated backup strategies with schedules
- Managing backup chains for point-in-time recovery
Key concepts covered:
- Automatic chain detection and extension
- Full vs incremental backup creation
- Backup chain structure and dependencies
- Storage savings calculation
- Chain management and validation
Basic Syntax
BACKUP INTO LATEST IN 'nodelocal://1/backups/cluster';
BACKUP INTO LATEST IN 'nodelocal://1/backups/cluster'
AS OF SYSTEM TIME '-10s';
How It Works
First Backup Creates Full
If destination is empty, BACKUP INTO LATEST creates a full backup:
BACKUP INTO LATEST IN 'nodelocal://1/backups/new-location';
Subsequent Backups Create Incrementals
Once full backup exists, creates incrementals:
BACKUP INTO LATEST IN 'nodelocal://1/backups/new-location';
BACKUP INTO LATEST IN 'nodelocal://1/backups/new-location';
Automatic Chain Detection
CockroachDB automatically:
- Checks destination for existing backups
- Finds most recent backup timestamp
- Captures changes since that timestamp
- Maintains backup chain integrity
Step-by-Step
BACKUP INTO LATEST IN 'nodelocal://1/backups/prod' AS OF SYSTEM TIME '-10s';
BACKUP INTO LATEST IN 'nodelocal://1/backups/prod' AS OF SYSTEM TIME '-10s';
BACKUP INTO LATEST IN 'nodelocal://1/backups/prod' AS OF SYSTEM TIME '-10s';
SHOW BACKUPS IN 'nodelocal://1/backups/prod';
SHOW BACKUP FROM LATEST IN 'nodelocal://1/backups/prod';
Common Patterns
Pattern 1: Hourly Incrementals
CREATE SCHEDULE hourly_incremental
FOR BACKUP INTO 'nodelocal://1/backups/prod'
RECURRING '@hourly';
Pattern 2: Weekly Full + Daily Incrementals
CREATE SCHEDULE prod_backup
FOR BACKUP INTO 'nodelocal://1/backups/prod'
RECURRING '@daily'
FULL BACKUP '@weekly';
Result:
- Sunday: Full backup (new chain)
- Mon-Sat: Daily incrementals
- Next Sunday: New full backup (new chain)
Pattern 3: Manual Incremental After Changes
BACKUP INTO LATEST IN 'nodelocal://1/backups/post-migration' AS OF SYSTEM TIME '-10s';
Storage Savings Example
1 TB database, 2% daily change rate:
- Daily full backups: 7 TB/week
- Weekly full + daily incrementals: 1.12 TB/week (1 TB + 6ร20 GB)
- Savings: 84%
Advanced Options
Database-Level Incrementals
BACKUP DATABASE mydb INTO LATEST IN 'nodelocal://1/backups/mydb'
AS OF SYSTEM TIME '-10s';
Incremental with Revision History
BACKUP INTO LATEST IN 'nodelocal://1/backups/pitr'
WITH revision_history;
Cloud Storage Examples
S3 Backup Chain
BACKUP INTO LATEST IN 's3://my-company-backups/production?AWS_ACCESS_KEY_ID=xxx&AWS_SECRET_ACCESS_KEY=yyy'
AS OF SYSTEM TIME '-10s';
BACKUP INTO LATEST IN 's3://my-company-backups/production?AWS_ACCESS_KEY_ID=xxx&AWS_SECRET_ACCESS_KEY=yyy'
AS OF SYSTEM TIME '-10s';
GCS Backup Chain
BACKUP INTO LATEST IN 'gs://acme-backups/prod-cluster?AUTH=specified&CREDENTIALS=base64-encoded-key'
AS OF SYSTEM TIME '-10s';
Best practice: Store credentials in environment variables or use implicit auth (IAM roles)
Azure Blob Storage
BACKUP INTO LATEST IN 'azure://backups-container/prod?AZURE_ACCOUNT_NAME=myaccount&AZURE_ACCOUNT_KEY=xxx'
AS OF SYSTEM TIME '-10s';
Troubleshooting
Issue 1: Error "no full backup found"
Symptoms:
ERROR: no full backup found in destination
Cause: Attempting BACKUP INTO LATEST when no full backup exists at the destination
Diagnosis:
SHOW BACKUPS IN 'nodelocal://1/backups/new';
Solutions:
BACKUP INTO 'nodelocal://1/backups/new' AS OF SYSTEM TIME '-10s';
BACKUP INTO LATEST IN 'nodelocal://1/backups/new' AS OF SYSTEM TIME '-10s';
Prevention: Always verify backup destination exists or use BACKUP INTO LATEST consistently (it auto-creates full on first run)
Issue 2: Incremental Unexpectedly Large
Symptoms:
- Incremental backup size approaching full backup size (>50%)
- Storage savings not meeting expectations (should be 5-15% typically)
- Backup duration similar to full backups
Diagnosis:
SHOW BACKUPS IN 'nodelocal://1/backups/prod';
SHOW BACKUP FROM '2026/03/01-000000.00' IN 'nodelocal://1/backups/prod';
SHOW BACKUP FROM '2026/03/02-000000.00' IN 'nodelocal://1/backups/prod';
SELECT table_name, rows, size_bytes/1024/1024/1024 AS size_gb
FROM [SHOW BACKUP FROM LATEST IN 'nodelocal://1/backups/prod']
ORDER BY size_bytes DESC;
Common Causes:
- High data change rate (20%+ daily) - Expected in write-heavy workloads
- Schema changes - ALTER TABLE operations cause table to be fully backed up
- Bulk operations - Large INSERT/UPDATE/DELETE between backups
- Compaction changes - RocksDB compaction reshuffling SSTables
Solutions:
CREATE SCHEDULE high_churn_tables
FOR BACKUP TABLE mydb.sessions INTO 'nodelocal://1/backups/sessions'
RECURRING '@daily'
FULL BACKUP '@daily';
ALTER TABLE sessions SET (ttl_expire_after = '24 hours');
BACKUP INTO 'nodelocal://1/backups/prod' AS OF SYSTEM TIME '-10s';
Issue 3: Chain Broken - Cannot Restore
Symptoms:
ERROR: backup layer missing in chain
ERROR: unable to find full backup
Cause: Deleted backup in the middle of chain, breaking dependency path
Example of broken chain:
Timeline:
[Full Sun] -> [Incr Mon] -> [DELETED Tue] -> [Incr Wed]
Trying to restore Wed fails because it depends on Tue
Diagnosis:
SHOW BACKUPS IN 'nodelocal://1/backups/prod';
SHOW BACKUP FROM '2026/03/05-000000.00' IN 'nodelocal://1/backups/prod';
Solutions:
RESTORE FROM '2026/03/04-000000.00' IN 'nodelocal://1/backups/prod';
BACKUP INTO 'nodelocal://1/backups/prod-new' AS OF SYSTEM TIME '-10s';
SHOW BACKUPS IN 'nodelocal://1/backups/prod';
RESTORE FROM '2026/03/01-000000.00' IN 'nodelocal://1/backups/prod';
Prevention Best Practices:
CREATE SCHEDULE prod_backup
FOR BACKUP INTO 'gs://backups/prod'
RECURRING '@hourly'
FULL BACKUP '@weekly'
WITH SCHEDULE OPTIONS gc_protect_expires_after = '30 days';
Issue 4: AS OF SYSTEM TIME Too Old
Symptoms:
ERROR: AS OF SYSTEM TIME is too far in the past
Cause: Trying to backup data older than GC window (default 25 hours)
Solution:
SHOW CLUSTER SETTING kv.gc.ttl;
BACKUP INTO LATEST IN 'nodelocal://1/backups/prod'
AS OF SYSTEM TIME '-10s';
SET CLUSTER SETTING kv.gc.ttl = '48h';
Backup Chain Structure
Timeline:
Week 1:
[Full Sun] -> [Incr Mon] -> [Incr Tue] -> ... -> [Incr Sat]
Week 2:
[Full Sun] -> [Incr Mon] -> [Incr Tue] -> ... -> [Incr Sat]
Restore from Tuesday Week 1:
- Restore Full (Sunday)
- Apply Incr Mon
- Apply Incr Tue
= Data as of Tuesday
Monitoring Incremental Backups
Check backup sizes:
SHOW BACKUPS IN 'nodelocal://1/backups/prod';
Look for:
- First backup (largest = full)
- Subsequent backups (smaller = incrementals)
- Trend in incremental sizes (should be consistent)
Monitor job history:
SELECT job_id, status, created, description
FROM [SHOW JOBS]
WHERE job_type = 'BACKUP'
ORDER BY created DESC
LIMIT 20;
Best Practices
- Always use same destination for chain integrity
- Start new chain weekly/monthly to limit restore chain length
- Monitor incremental sizes for unexpected growth
- Test restore from chain to verify backup validity
- Automate with schedules for consistency
- Use cloud storage for production incrementals
Best Practices
-
Use Consistent Destinations
- Always use the same storage path for a backup chain
- Never mix backups from different sources in same destination
- Document backup destinations in runbooks
-
Start New Chains Periodically
- Weekly or monthly full backups create new chains
- Limits restore chain length (faster recovery)
- Reduces risk of chain corruption affecting long history
-
Monitor Incremental Sizes
- Alert on incrementals >30% of full backup size
- Investigate sudden size increases (schema changes, bulk operations)
- Track storage usage trends for capacity planning
-
Automate with Schedules
- Use
CREATE SCHEDULE for consistency
- Avoid manual backup runs (prone to human error)
- Set up monitoring for schedule failures
-
Test Restore Regularly
- Monthly: Restore from incremental chain to validate
- Verify restore completes successfully
- Measure restore time for RTO planning
-
Use Cloud Storage for Production
- S3/GCS/Azure Blob for durability and availability
- Nodelocal only for development/testing
- Enable versioning on cloud buckets for protection
-
Implement Retention Policies
- Define retention based on compliance requirements
- Use garbage collection options to auto-delete old backups
- Keep at least 2 full backup chains for safety
Performance Considerations
Incremental backup performance factors:
- Data change rate: Higher churn = larger incrementals = longer backup time
- Network bandwidth: Cloud storage backups limited by network throughput
- Cluster load: Backups consume CPU/IO; schedule during low-usage periods
- Storage destination: S3/GCS performance varies by region and tier
Optimization strategies:
CREATE SCHEDULE off_hours_backup
FOR BACKUP INTO 's3://backups/prod'
RECURRING '0 2 * * *'
FULL BACKUP '0 2 * * 0';
BACKUP INTO LATEST IN 's3://backups/prod'
WITH execution_locality = 'region=us-east1';
Comparison: BACKUP INTO vs BACKUP INTO LATEST
| Aspect | BACKUP INTO | BACKUP INTO LATEST |
|---|
| Behavior | Always creates full backup | Creates full if empty, else incremental |
| Use case | Starting new chain | Extending existing chain |
| Storage | ~10 GB per backup | ~500 MB per incremental |
| Automation | Requires logic to switch | Automatic detection |
| Best for | Weekly/monthly baseline | Hourly/daily backups |
Example workflow:
BACKUP INTO 'gs://backups/prod-week-10' AS OF SYSTEM TIME '-10s';
BACKUP INTO LATEST IN 'gs://backups/prod-week-10' AS OF SYSTEM TIME '-10s';
BACKUP INTO LATEST IN 'gs://backups/prod-week-10' AS OF SYSTEM TIME '-10s';
BACKUP INTO 'gs://backups/prod-week-11' AS OF SYSTEM TIME '-10s';
BACKUP INTO LATEST IN 'gs://backups/prod-week-11' AS OF SYSTEM TIME '-10s';
Related Skills
- understand-incremental-backup-concepts: Learn how incrementals work architecturally
- execute-cluster-level-full-backups: Create initial full backup to start chain
- inspect-backup-contents-with-show-backup: Verify backup chain integrity
- list-available-backups-with-show-backups: List all backups in chain
- create-automated-backup-schedules: Automate LATEST backups with schedules
- analyze-incremental-backup-efficiency: Calculate storage savings and optimize strategy
- manage-backup-retention-policies: Implement retention and garbage collection
- restore-cluster-from-full-backup: Restore using incremental chains