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 and merge 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 and futures crate. This enables us to run a WebDAV 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
  • repository 🔒
  • Virtual File System support - allows to act on the repository like on a file system

Structs§

Enums§

  • Type for describing the kind of a file that can occur.

Constants§

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§

Type Aliases§