Understanding snapshots and how they preserve your backup history
A snapshot represents the state of your backed-up data at a specific point in time. Snapshots are the primary way you interact with your backup history in rustic_core.
The SnapshotFile structure contains comprehensive metadata:
pub struct SnapshotFile { /// Timestamp of this snapshot pub time: Zoned, /// The tree blob id where contents are stored pub tree: TreeId, /// The list of paths contained in this snapshot pub paths: StringList, /// The hostname where snapshot was created pub hostname: String, /// Tags for filtering and organization pub tags: StringList, /// Optional label for the snapshot pub label: String, /// Parent snapshot ID for incremental backups pub parent: Option<SnapshotId>, /// Summary statistics from the backup pub summary: Option<SnapshotSummary>, /// Optional description pub description: Option<String>, // ... additional fields}
Snapshots are immutable once created. You cannot modify an existing snapshot’s data or metadata.
This immutability provides:
Integrity: Snapshots cannot be corrupted or tampered with
Consistency: What you backed up is what you’ll restore
Audit trail: Complete history of all backups
If you need to “modify” a snapshot (e.g., add tags), rustic creates a new snapshot with the updated metadata:
// Modifying creates a new snapshotpub fn modify(&mut self, modification: &SnapshotModification) -> RusticResult<bool> { modification.apply_to(self) // Returns true if changed}// Original snapshot ID stored for referencepub original: Option<SnapshotId>,
// Full IDlet snap = repo.get_snapshot_from_str( "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", |_| true)?;// Partial ID (must be unique)let snap = repo.get_snapshot_from_str("0123456", |_| true)?;
Get recent snapshots with latest or latest~N:
// Most recent snapshotlet snap = repo.get_snapshot_from_str("latest", |_| true)?;// Second most recentlet snap = repo.get_snapshot_from_str("latest~1", |_| true)?;// Third most recentlet snap = repo.get_snapshot_from_str("latest~2", |_| true)?;
Filter snapshots by criteria:
let snapshots = repo.get_matching_snapshots(|snap| { snap.hostname == "myserver" && snap.tags.contains("important")})?;
Snapshots can be removed (respecting deletion policies):
// Check if snapshot must be keptif snapshot.must_keep(&Zoned::now()) { println!("Cannot delete: snapshot has deletion protection");} else { repo.delete_snapshots(&[snapshot.id])?;}
Deleting snapshots only removes the metadata. The actual data blobs are removed during prune operations.