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:
Backup Compression¶
Best Practices¶
- Backup Strategy
- Regular scheduled backups
- Mix of full and incremental backups
- Store backups in different locations
-
Test restore procedures
-
Resource Management
- Monitor backup size
- Manage disk space
-
Configure appropriate retention
-
Security
- Enable encryption for sensitive data
- Secure backup storage
- 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¶
- Stop the service
- Identify latest valid backup
- Restore from backup
- Verify data integrity
- 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¶
- Learn about Persistence
- Explore Security Features
- Understand Monitoring