Skip to content

Backup & Restore

Quiver provides comprehensive backup and restore capabilities to ensure data safety and disaster recovery.

Overview

The backup system includes:

  • Scheduled automatic backups
  • Configurable backup intervals
  • Compression options
  • Incremental backups
  • Backup rotation
  • Encryption support

Configuration

Basic Backup Settings

config := quiver.Config{
    BackupPath: "/path/to/backups",
    BackupInterval: 1 * time.Hour,
    BackupCompression: true,
    MaxBackups: 5,  // Keep last 5 backups
}

Advanced Configuration

config := quiver.Config{
    BackupPath: "/path/to/backups",
    BackupInterval: 1 * time.Hour,
    BackupCompression: true,
    MaxBackups: 5,
    EncryptionEnabled: true,
    EncryptionKey: "your-32-byte-encryption-key",
}

Backup Features

Automatic Backups

Quiver automatically creates backups based on your configuration:

// Backup worker runs in background
// Configured through BackupInterval
config := quiver.Config{
    BackupInterval: 1 * time.Hour,
}

Manual Backups

// Create an immediate backup
err := idx.Backup("/path/to/backup", false, true)  // path, incremental, compress
if err != nil {
    // Handle backup error
}

Incremental Backups

// Create an incremental backup
err := idx.Backup("/path/to/backup", true, true)  // incremental=true
if err != nil {
    // Handle backup error
}

Restore Operations

Basic Restore

// Restore from backup
err := idx.Restore("/path/to/backup")
if err != nil {
    // Handle restore error
}

Verify Restore

// After restore, verify index health
if err := idx.HealthCheck(); err != nil {
    // Handle verification error
}

Backup Management

Backup Rotation

Quiver automatically manages backup retention:

config := quiver.Config{
    MaxBackups: 5,  // Keep only last 5 backups
}

Backup Compression

config := quiver.Config{
    BackupCompression: true,  // Enable compression
}

Best Practices

  1. Backup Strategy
  2. Regular scheduled backups
  3. Mix of full and incremental backups
  4. Store backups in different locations
  5. Test restore procedures

  6. Resource Management

  7. Monitor backup size
  8. Manage disk space
  9. Configure appropriate retention

  10. Security

  11. Enable encryption for sensitive data
  12. Secure backup storage
  13. Manage encryption keys

Monitoring

Backup Status

// Get backup metrics
metrics := idx.CollectMetrics()
fmt.Printf("Last backup time: %s\n", metrics["last_backup_time"])
fmt.Printf("Backup age: %.2f seconds\n", metrics["backup_age_seconds"])

Backup Verification

// Verify backup integrity
manifest, err := idx.VerifyBackup("/path/to/backup")
if err != nil {
    // Handle verification error
}

Error Handling

err := idx.Backup("/path/to/backup", false, true)
if err != nil {
    switch {
    case errors.Is(err, ErrBackupPathNotFound):
        // Handle path issues
    case errors.Is(err, ErrInsufficientSpace):
        // Handle space issues
    default:
        // Handle other errors
    }
}

Disaster Recovery

Recovery Process

  1. Stop the service
  2. Identify latest valid backup
  3. Restore from backup
  4. Verify data integrity
  5. Resume service

Example Recovery

// 1. Load configuration
config := quiver.Config{
    StoragePath: "/path/to/storage",
}

// 2. Create new index
idx, err := quiver.New(config, logger)
if err != nil {
    // Handle error
}

// 3. Restore from backup
err = idx.Restore("/path/to/latest/backup")
if err != nil {
    // Handle restore error
}

// 4. Verify restoration
if err := idx.HealthCheck(); err != nil {
    // Handle verification error
}

Next Steps