Performing Backups
This guide covers how to create backups using rustic_core, including basic backups, incremental backups, and advanced filtering options.Overview
Backups in rustic_core create immutable snapshots of your data. Each backup operation produces a new snapshot that efficiently stores only the data that has changed since the last backup.Basic Backup
use rustic_core::{
Repository, RepositoryOptions, Credentials,
BackupOptions, PathList, SnapshotOptions
};
use rustic_backend::BackendOptions;
let backends = BackendOptions::default()
.repository("/path/to/repo")
.to_backends()?;
let repo_opts = RepositoryOptions::default();
let credentials = Credentials::password("my-password");
let repo = Repository::new(&repo_opts, &backends)?
.open(&credentials)?
.to_indexed_ids()?;
let backup_opts = BackupOptions::default();
let source = PathList::from_string("/data/to/backup")?.sanitize()?;
let snap = SnapshotOptions::default().to_snapshot()?;
// Create the backup
let snapshot = repo.backup(&backup_opts, &source, snap)?;
println!("Created snapshot: {}", snapshot.id);
Backup Multiple Paths
Backup multiple directories in a single snapshot:Incremental Backups
rustic_core automatically performs incremental backups using parent snapshots.Using Parent Snapshots
By default, rustic_core finds a suitable parent snapshot based on hostname, paths, and labels:Grouping Criteria
Control how parent snapshots are selected:Explicit Parent
Specify an explicit parent snapshot:Force Full Backup
Force a backup without using a parent (reads all files):Filtering and Exclusions
See/home/daytona/workspace/source/crates/core/src/commands/backup.rs:186-199
Exclude Patterns
Exclude files matching glob patterns:Exclude Files
Use exclude files (like .gitignore):Size Filtering
Filter files by size:Advanced Options
Skip Unchanged Snapshots
Skip creating a snapshot if nothing has changed:Ignore File Metadata Changes
Ignore ctime or inode changes when detecting modifications:Custom Backup Path
Set a custom path in the snapshot metadata:Dry Run
Test backup without writing data:Disable Size Scanning
Skip scanning for total size (disables ETA):Backing Up from stdin
Backup data from stdin:Backup Command Output
Backup the output of a command:Save Options
Control how files are saved:Common Scenarios
Daily Backup Script
See Also
- Repository Management - Check and verify backups
- Restore Guide - Restore files from backups
- Configuration - Repository configuration options
- BackupOptions API Reference
- SnapshotOptions API Reference