Skip to main content
The prune operation removes unused data from the repository and optionally repacks data for optimal storage.

PrunePlan::from_prune_options()

Creates a prune plan from the given options.
pub fn from_prune_options<S: Open>(
    repo: &Repository<S>,
    opts: &PruneOptions,
) -> RusticResult<PrunePlan>

Parameters

  • repo: The repository to analyze
  • opts: Prune options

Returns

Returns a PrunePlan describing what will be deleted and repacked.

Errors

  • If repack_uncompressed is set and the repository is version 1
  • If keep_pack or keep_delete durations are invalid

prune_repository()

Executes a prune plan on the repository.
pub fn prune_repository<S: Open>(
    repo: &Repository<S>,
    opts: &PruneOptions,
    prune_plan: PrunePlan,
) -> RusticResult<()>

Errors

  • If the repository is in append-only mode
  • If pack operations fail

PruneOptions

Configuration options for the prune operation.
max_repack
LimitOption
default:"10%"
Maximum data to repack as percentage of repo size, absolute size (e.g., ‘5b’, ‘2 kB’, ‘3M’, ‘4TiB’), or ‘unlimited’.
max_unused
LimitOption
default:"5%"
Tolerate limit of unused data as percentage of repo size after pruning, absolute size, or ‘unlimited’.
keep_pack
Span
default:"0d"
Minimum duration (e.g., 90d) to keep packs before repacking or removing. More recently created packs won’t be processed.
keep_delete
Span
default:"23h"
Minimum duration (e.g., 10m) to keep packs marked for deletion. More recently marked packs won’t be deleted.
instant_delete
bool
default:false
Delete files immediately instead of marking them. Also removes all files already marked for deletion.
Only use if you are sure the repository is not accessed by parallel processes!
early_delete_index
bool
default:false
Delete index files early if instant_delete is chosen. Allows prune to run when space is limited.
If prune aborts, this can lead to a missing index which must be repaired!
fast_repack
bool
default:false
Simply copy blobs when repacking instead of decrypting, possibly compressing, and encrypting.
repack_uncompressed
bool
default:false
Repack packs containing uncompressed blobs. Cannot be used with fast_repack. Implies max_unused=0.
repack_all
bool
default:false
Repack all packs. Implies max_unused=0.
repack_cacheable_only
Option<bool>
Only repack packs which are cacheable. Default: true for hot/cold repository, else false.
no_resize
bool
default:false
Do not repack packs which only need to be resized.
ignore_snaps
Vec<SnapshotId>
default:"[]"
Ignore these snapshots when looking for data still in use.
Use with care! Specifying non-deleted snapshots will remove data used by those snapshots!

LimitOption

Specifies a size limit for prune operations.
pub enum LimitOption {
    Size(ByteSize),
    Percentage(u64),
    Unlimited,
}

Variants

Size(ByteSize)
Absolute size limit (e.g., “10 GB”, “500 MiB”).
Percentage(u64)
Percentage of repository size (e.g., “10%” means 10% of total repo size).
Unlimited
No limit.

PrunePlan

A plan describing what should be repacked or removed.
pub struct PrunePlan {
    pub stats: PruneStats,
}

Methods

repack_packs()

Get the list of packs to repack.
pub fn repack_packs(&self) -> Vec<PackId>

PruneStats

Statistics about a prune plan.
packs_to_delete
DeleteStats
Statistics about pack count to delete/keep/recover.
size_to_delete
DeleteStats
Statistics about pack sizes to delete/keep/recover.
packs
PackStats
Statistics about current pack situation.
blobs
BlobTypeMap<SizeStats>
Statistics about blobs in the repository.
size
BlobTypeMap<SizeStats>
Statistics about total sizes of blobs.
packs_unref
u64
Number of unreferenced pack files.
size_unref
u64
Total size of unreferenced pack files.
index_files
u64
Number of index files.
index_files_rebuild
u64
Number of index files to be rebuilt.

PackStats

Statistics about packs.
used
u64
Number of fully used packs.
partly_used
u64
Number of partly used packs.
unused
u64
Number of unused packs (equals packs-to-remove).
repack
u64
Number of packs to repack.
keep
u64
Number of packs to keep.

SizeStats

Statistics about sizes.
used
u64
Number of used blobs/bytes.
unused
u64
Number of unused blobs/bytes.
remove
u64
Number of blobs/bytes to remove.
repack
u64
Number of blobs/bytes to repack.
repackrm
u64
Number of blobs/bytes to remove after repacking.

Methods

pub fn total(&self) -> u64
pub fn total_after_prune(&self) -> u64
pub fn unused_after_prune(&self) -> u64

Example

use rustic_core::{
    LimitOption,
    PruneOptions,
    PrunePlan,
    Repository,
};
use jiff::Span;

// Configure prune options
let opts = PruneOptions {
    max_repack: LimitOption::Percentage(10),
    max_unused: LimitOption::Percentage(5),
    keep_pack: Span::new().days(7),
    keep_delete: Span::new().hours(23),
    instant_delete: false,
    ..Default::default()
};

// Create prune plan
let plan = PrunePlan::from_prune_options(&repo, &opts)?;

// Display statistics
println!("Packs to repack: {}", plan.stats.packs.repack);
println!("Packs to remove: {}", plan.stats.packs.unused);
println!("Size to repack: {} bytes", plan.stats.size_sum().repack);
println!("Size to remove: {} bytes", plan.stats.size_sum().remove);

// Execute prune
prune_repository(&repo, &opts, plan)?;
println!("Prune completed!");

Advanced Usage

Repack Uncompressed Data

let opts = PruneOptions {
    repack_uncompressed: true,
    max_repack: LimitOption::Unlimited,
    ..Default::default()
};

Instant Delete (Careful!)

let opts = PruneOptions {
    instant_delete: true,
    keep_delete: Span::new().hours(0),
    ..Default::default()
};

Fast Repack

let opts = PruneOptions {
    fast_repack: true,
    max_repack: LimitOption::Size(ByteSize::gb(10)),
    ..Default::default()
};

Notes

  • Prune is a two-step process: mark for deletion, then delete after keep_delete duration
  • Use instant_delete carefully - only when no other processes access the repository
  • Repacking consolidates partly-used packs to reclaim space
  • max_repack limits how much data is repacked to avoid long-running operations
  • max_unused ensures unused data stays below a threshold
  • Recently created packs (within keep_pack duration) are never repacked
  • Prune automatically rebuilds index files as needed
  • Append-only repositories cannot be pruned

Build docs developers (and LLMs) love