Skip to main content
Snapshots represent point-in-time backups in rustic. They contain metadata about what was backed up, when, and by whom.

SnapshotFile

Represents snapshot metadata stored in the repository.
pub struct SnapshotFile {
    pub time: Zoned,
    pub program_version: String,
    pub parent: Option<SnapshotId>,
    pub parents: Vec<SnapshotId>,
    pub tree: TreeId,
    pub label: String,
    pub paths: StringList,
    pub hostname: String,
    pub username: String,
    pub uid: u32,
    pub gid: u32,
    pub tags: StringList,
    pub original: Option<SnapshotId>,
    pub delete: DeleteOption,
    pub summary: Option<SnapshotSummary>,
    pub description: Option<String>,
    pub id: SnapshotId,
}

Fields

time
Zoned
Timestamp when the snapshot was created.
program_version
String
Program identifier and version used to create the snapshot.
parent
Option<SnapshotId>
The ID of the first parent snapshot this was based on.
parents
Vec<SnapshotId>
All parent snapshot IDs this snapshot was based on.
tree
TreeId
The tree blob ID where the snapshot contents are stored.
label
String
User-defined label for the snapshot.
paths
StringList
List of paths contained in this snapshot.
hostname
String
Hostname of the device where the snapshot was created.
username
String
Username that started the backup.
uid
u32
User ID of the user that started the backup.
gid
u32
Group ID of the user that started the backup.
tags
StringList
List of tags for categorizing the snapshot.
original
Option<SnapshotId>
Original snapshot ID if this snapshot is a modified version.
delete
DeleteOption
Deletion protection settings.
summary
Option<SnapshotSummary>
Summary statistics about the backup operation.
description
Option<String>
User-provided description of the snapshot contents.
id
SnapshotId
The unique identifier of this snapshot.

SnapshotOptions

Options for creating a new snapshot.
label
Option<String>
Label for the snapshot.
tags
Vec<StringList>
Tags to add to the snapshot (can be specified multiple times).
description
Option<String>
Description of what the snapshot contains.
description_from
Option<PathBuf>
Read description from a file. Conflicts with description.
time
Option<Zoned>
Set the backup time manually (e.g., “2021-01-21 14:15:23+0000”).
delete_never
bool
default:false
Mark snapshot as uneraseable. Conflicts with delete_after.
delete_after
Option<Span>
Mark snapshot to be deleted after given duration (e.g., “10d”).
host
Option<String>
Set the hostname manually.
command
Option<String>
Set the backup command manually.

DeleteOption

Options for snapshot deletion protection.
pub enum DeleteOption {
    NotSet,
    Never,
    After(Zoned),
}
NotSet
No deletion protection set.
Never
Snapshot should never be deleted (remove-protection).
After(Zoned)
Remove snapshot after the given timestamp, but prevent removing before.

SnapshotSummary

Summary information about a snapshot.
files_new
u64
New files compared to parent snapshot.
files_changed
u64
Changed files compared to parent snapshot.
files_unmodified
u64
Unchanged files compared to parent snapshot.
total_files_processed
u64
Total files processed during backup.
total_bytes_processed
u64
Total size of all processed files.
dirs_new
u64
New directories compared to parent.
dirs_changed
u64
Changed directories compared to parent.
dirs_unmodified
u64
Unchanged directories compared to parent.
data_blobs
u64
Total data blobs added by this snapshot.
tree_blobs
u64
Total tree blobs added by this snapshot.
data_added
u64
Total uncompressed bytes added.
data_added_packed
u64
Total bytes added to repository (compressed/encrypted).
backup_start
Zoned
When the backup started.
backup_end
Zoned
When the backup finished.
backup_duration
f64
Duration of backup in seconds.

Listing Snapshots

SnapshotFile::latest()

Get the latest snapshot matching a filter.
pub fn latest<F>(
    be: &impl DecryptReadBackend,
    filter: F,
    p: &Progress,
) -> RusticResult<SnapshotFile>
where
    F: FnMut(&SnapshotFile) -> bool,

SnapshotFile::from_strs()

Get snapshots from string identifiers.
pub fn from_strs<F>(
    be: &impl DecryptReadBackend,
    ids: &[String],
    filter: F,
    p: &Progress,
) -> RusticResult<Vec<SnapshotFile>>
where
    F: FnMut(&SnapshotFile) -> bool,
Supports:
  • Full snapshot IDs
  • Short IDs (prefix matching)
  • "latest" for most recent snapshot
  • "latest~N" for Nth most recent snapshot (N >= 0)

Filtering Snapshots

Snapshots can be filtered by:
  • Host: Filter by hostname
  • Label: Filter by label
  • Paths: Filter by backup paths
  • Tags: Filter by tags
  • Time range: Filter by creation time
Use SnapshotGroupCriterion to group snapshots:
pub enum SnapshotGroupCriterion {
    Host,
    Label,
    Paths,
    Tags,
}

Example

use rustic_core::{
    DeleteOption,
    SnapshotFile,
    SnapshotOptions,
};
use jiff::Span;

// Create snapshot with options
let opts = SnapshotOptions {
    label: Some("daily-backup".to_string()),
    tags: vec!["important".parse()?, "production".parse()?],
    description: Some("Database backup".to_string()),
    delete_after: Some(Span::new().days(30)),
    ..Default::default()
};

let snapshot = opts.to_snapshot()?;

// List all snapshots
let snapshots = repo.get_all_snapshots()?;

for snap in snapshots {
    println!("Snapshot {} created at {}", snap.id, snap.time);
    println!("  Paths: {:?}", snap.paths);
    println!("  Tags: {:?}", snap.tags);
}

// Get latest snapshot for a specific host
let latest = SnapshotFile::latest(
    repo.dbe(),
    |snap| snap.hostname == "myserver",
    &repo.progress_counter(""),
)?;

println!("Latest snapshot: {}", latest.id);

// Get snapshot by ID or prefix
let snapshots = SnapshotFile::from_strs(
    repo.dbe(),
    &["abc123".to_string(), "latest".to_string()],
    |_| true,
    &repo.progress_counter(""),
)?;

Snapshot Protection

Never Delete

let opts = SnapshotOptions {
    delete_never: true,
    ..Default::default()
};

Delete After Duration

use jiff::Span;

let opts = SnapshotOptions {
    delete_after: Some(Span::new().days(90)),
    ..Default::default()
};

Notes

  • Snapshots are immutable once created
  • Snapshot IDs are content-addressed (deterministic based on metadata)
  • Parent snapshots enable incremental backups
  • Tags and labels help organize and find snapshots
  • Deletion protection prevents accidental data loss
  • Snapshots can be compared and filtered by multiple criteria
  • The summary field contains detailed statistics about what was backed up

Build docs developers (and LLMs) love