Skip to main content
The backup operation creates snapshots of your data and stores them in the rustic repository.

backup()

Performs a backup operation, creating a new snapshot.
pub fn backup<S: IndexedIds>(
    repo: &Repository<S>,
    opts: &BackupOptions,
    source: &PathList,
    snap: SnapshotFile,
) -> RusticResult<SnapshotFile>

Parameters

  • repo: The repository to backup to
  • opts: Backup options
  • source: The source paths to backup
  • snap: Snapshot metadata

Returns

Returns the created SnapshotFile containing metadata about the backup.

Errors

  • If sending messages to the packer fails
  • If the index file cannot be serialized
  • If time conversion fails

BackupOptions

Configuration options for the backup operation.
stdin_filename
String
default:"stdin"
Filename to use when backing up from stdin.
stdin_command
Option<CommandInput>
Call the given command and use its output as stdin.
as_path
Option<PathBuf>
Manually set the backup path in the snapshot.
no_scan
bool
default:false
Don’t scan the backup source for its size. This disables ETA estimation for backup.
dry_run
bool
default:false
Dry-run mode: Don’t write any data or snapshot.
parent_opts
ParentOptions
Options for how to use a parent snapshot.
ignore_save_opts
LocalSourceSaveOptions
Options for how to save entries from a local source.
excludes
Excludes
Files and patterns to exclude from backup.
ignore_filter_opts
LocalSourceFilterOptions
Options for how to filter files from a local source.

ParentOptions

Options for using parent snapshots during backup.
group_by
Option<SnapshotGroupCriterion>
Group snapshots by any combination of host, label, paths, tags to find a suitable parent. Default: host, label, paths.
parents
Vec<String>
Snapshot(s) to use as parent. Can be specified multiple times.
skip_if_unchanged
bool
default:false
Skip writing the snapshot if nothing changed compared to the parent snapshot.
force
bool
default:false
Use no parent, read all files.
ignore_ctime
bool
default:false
Ignore ctime changes when checking for modified files.
ignore_inode
bool
default:false
Ignore inode number changes when checking for modified files.

PathList

Represents a list of paths to backup.
pub struct PathList(Vec<PathBuf>);
PathList can be created from a string using - for stdin or file paths.

Example

use rustic_core::{
    BackupOptions,
    PathList,
    Repository,
    SnapshotFile,
};

// Create backup options
let opts = BackupOptions {
    stdin_filename: "myfile.txt".to_string(),
    dry_run: false,
    no_scan: false,
    ..Default::default()
};

// Define source paths
let source = PathList::from_string("/home/user/documents")?;

// Create snapshot metadata
let mut snap = SnapshotFile::default();
snap.hostname = "myhost".to_string();
snap.paths = vec!["/home/user/documents".into()];

// Perform backup
let snapshot = backup(&repo, &opts, &source, snap)?;
println!("Created snapshot: {}", snapshot.id);

Notes

  • The backup process uses deduplication to avoid storing duplicate data
  • Parent snapshots are used to detect unchanged files
  • Backup supports reading from stdin using - as the source path
  • Use dry_run to test backup operations without writing data

Build docs developers (and LLMs) love