Restoring Snapshots
This guide covers how to restore files and directories from rustic_core snapshots, including full restores, partial restores, and advanced restore options.Overview
rustic_core provides efficient restore capabilities that can:- Restore entire snapshots or specific paths
- Verify existing files and skip unchanged data
- Preserve file metadata (permissions, ownership, timestamps)
- Remove extraneous files from the restore destination
Basic Restore
use rustic_core::{
Repository, RepositoryOptions, Credentials,
RestoreOptions, LocalDestination, LsOptions
};
use rustic_backend::BackendOptions;
let backends = BackendOptions::default()
.repository("/path/to/repo")
.to_backends()?;
let repo = Repository::new(&RepositoryOptions::default(), &backends)?
.open(&Credentials::password("my-password"))?
.to_indexed()?;
// Use the latest snapshot
let node = repo.node_from_snapshot_path("latest", |_| true)?;
// Or use a specific snapshot ID
let node = repo.node_from_snapshot_path("a1b2c3d4", |_| true)?;
// Or filter snapshots
let node = repo.node_from_snapshot_path("latest", |snap| {
snap.tags.contains(&"important".to_string())
})?;
let destination = "./restore/";
let create = true; // Create destination if it doesn't exist
let dest = LocalDestination::new(destination, create, !node.is_dir())?;
Restore Options
See/home/daytona/workspace/source/crates/core/src/commands/restore.rs:40-65
Delete Extra Files
Remove files in the destination that aren’t in the snapshot:Ownership Handling
Verify Existing Files
Always verify existing files instead of trusting modification time:Partial Restore
Restore Specific Path
Restore only a specific file or directory:Filter During Restore
UseLsOptions to filter what gets restored:
Advanced Restore Scenarios
Dry Run Mode
Test a restore without actually writing files:Restore to Single File
Restore a single file from a snapshot:Incremental Restore
Restore only files that have changed or are missing:Restore Statistics
The restore plan provides detailed statistics:Metadata Restoration
See/home/daytona/workspace/source/crates/core/src/commands/restore.rs:336-421
rustic_core restores file metadata in a specific order:
- File permissions - Set via
chmod - Extended attributes - Platform-specific attributes
- Ownership - User and group (if not disabled)
- Timestamps - Access and modification times
- Directory metadata - Set after all contents are restored
RestoreOptions:
Common Restore Patterns
Complete Disaster Recovery
Selective File Restore
Restore with Progress Tracking
Error Handling
Handle common restore errors:See Also
- Backup Guide - Create snapshots to restore from
- Configuration - Repository configuration
- RestoreOptions API Reference
- LocalDestination API Reference