Crate rustic_core
source ·Expand description
A library for deduplicated and encrypted backups, using repositories as specified in the restic repository design
.
§Overview
This section gives a brief overview of the primary types in this crate:
The main type is the Repository
type which describes a way to access a repository.
It can be in different states and allows - depending on the state - various high-level
actions to be performed on the repository like listing snapshots, backing up or restoring.
Besides this, various *Option
types exist which allow to specify options for accessing a
Repository
or for the methods used within a Repository
. Those types usually offer
setter methods as well as implement serde::Serialize
and serde::Deserialize
.
Other main types are typically result types obtained by Repository
methods which sometimes
are also needed as input for other Repository
method, like computing a PrunePlan
and
performing it.
There are also lower level data types which represent the stored repository format or
help accessing/writing it. Those are collected in the repofile
module. These types typically
implement serde::Serialize
and serde::Deserialize
.
§Example - initialize a repository, backup to it and get snapshots
use rustic_backend::BackendOptions;
use rustic_core::{BackupOptions, ConfigOptions, KeyOptions, PathList,
Repository, RepositoryOptions, SnapshotOptions
};
// Initialize the repository in a temporary dir
let repo_dir = tempfile::tempdir().unwrap();
let repo_opts = RepositoryOptions::default()
.password("test");
// Initialize Backends
let backends = BackendOptions::default()
.repository(repo_dir.path().to_str().unwrap())
.to_backends()
.unwrap();
let key_opts = KeyOptions::default();
let config_opts = ConfigOptions::default();
let _repo = Repository::new(&repo_opts, backends.clone()).unwrap().init(&key_opts, &config_opts).unwrap();
// We could have used _repo directly, but open the repository again to show how to open it...
let repo = Repository::new(&repo_opts, backends).unwrap().open().unwrap();
// Get all snapshots from the repository
let snaps = repo.get_all_snapshots().unwrap();
// Should be zero, as the repository has just been initialized
assert_eq!(snaps.len(), 0);
// Turn repository state to indexed (for backup):
let repo = repo.to_indexed_ids().unwrap();
// Pre-define the snapshot-to-backup
let snap = SnapshotOptions::default()
.add_tags("tag1,tag2").unwrap()
.to_snapshot().unwrap();
// Specify backup options and source
let backup_opts = BackupOptions::default();
let source = PathList::from_string("src").unwrap().sanitize().unwrap();
// run the backup and return the snapshot pointing to the backup'ed data.
let snap = repo.backup(&backup_opts, &source, snap).unwrap();
// assert_eq!(&snap.paths, ["src"]);
// Get all snapshots from the repository
let snaps = repo.get_all_snapshots().unwrap();
// Should now be 1, we just created a snapshot
assert_eq!(snaps.len(), 1);
assert_eq!(snaps[0], snap);
§Crate features
This crate exposes a few features for controlling dependency usage.
-
cli - Enables support for CLI features by enabling
clap
andmerge
features. This feature is disabled by default. -
clap - Enables a dependency on the
clap
crate and enables parsing from the commandline. This feature is disabled by default. -
merge - Enables support for merging multiple values into one, which enables the
merge
dependency. This is needed for parsing commandline arguments and merging them into one (e.g.config
). This feature is disabled by default. -
webdav - Enables a dependency on the
dav-server
andfutures
crate. This enables us to run aWebDAV
server asynchronously on the commandline. This feature is disabled by default.
Modules§
- archiver 🔒
- backend 🔒Module for backend related functionality.
- blob 🔒
- cdc 🔒
- chunker 🔒
- commands 🔒The commands that can be run by the CLI.
- crypto 🔒
- error 🔒Error types and Result module.
- id 🔒The
Id
type and related functions - index 🔒
- progress 🔒
- Structs which are saved in JSON or binary format in the repository
- Virtual File System support - allows to act on the repository like on a file system
Structs§
- Options for the
backup
command. - Information about blobs within
repoinfo
- Options for the
check
command - Options for the
config
command, used to set repository-wide options - This struct enhances
[SnapshotFile]
with the attributerelevant
which indicates if the snapshot is relevant for copying. - Statistics for files or directories
- All snapshots of a group with group and forget information
- A newtype for
[Vec<ForgetGroup>]
- This struct enhances
[SnapshotFile]
with the attributeskeep
andreasons
which indicates if the snapshot should be kept and why. - An
Id
in hexadecimal format Id
is the hash id of an object.- Index information from
repoinfo
- Options which snapshots should be kept. Used by the
forget
command. - Options for the
key
command. These are used when creating a new key. - Local destination, used when restoring.
- A
LocalSource
is a source from local paths which is used to be read from (i.e. to backup it). LocalSourceFilterOptions
allow to filter a local source by various criteria.LocalSourceSaveOptions
describes how entries from a local source will be saved in the repository.- Options for listing the
Nodes
of aTree
- A dummy struct which shows no progress but only logs titles and end of a progress.
- Don’t show progress bars, only log rudimentary progress information.
- Open Status: This repository is open, i.e. the password has been checked and the decryption key is available.
- Information about packs within
repoinfo
backup
subcommand Options how the backup command uses a parent snapshot.PathList
is a rustic-internal list ofPathBuf
s. It is used in thecrate::Repository::backup
command.- Options for the
prune
command - A plan what should be repacked or removed by a
prune
run - Statistics about a
PrunePlan
- Information about an entry to be able to open it.
- Options for the
repair index
command - Options for the
repair snapshots
command - Information about a repository files of a given
FileType
- Information about repository files
- A
Repository
allows all kind of actions to be performed. - The backends a repository can be initialized and operated on
- Options for using and opening a
Repository
- Options for the
restore
command - Information about what will be restored.
- Restore statistics
- Errors that can result from rustic.
SnapshotGroup
specifies the group after a grouping usingSnapshotGroupCriterion
.SnapshotGroupCriterion
determines how to group snapshots.- Options for creating a new
SnapshotFile
structure for a new backup snapshot. StringList
is a rustic-internal list of Strings. It is used withinSnapshotFile
Enums§
- Type for describing the kind of a file that can occur.
Constants§
- All
FileType
s which are located in separated directories
Traits§
- A repository which is indexed such that all blob information is fully contained in the index.
- Trait to report progress information for any rustic action which supports that.
- Trait to start progress information report progress information for any rustic action which supports that.
- Trait for backends that can read.
- Trait for backends that can read from a source.
- Trait for backends that can read and open sources. This trait is implemented by all backends that can read data and open from a source.
- Trait for backends that can write. This trait is implemented by all backends that can write data.
Functions§
- The accepted range of compression levels.
- An ordering function returning the latest node by mtime
- The maximum compression level allowed by zstd
Type Aliases§
- Result type that is being returned from methods that can fail and thus have
RusticError
s.