Skip to content

Commit

Permalink
refactor restore command
Browse files Browse the repository at this point in the history
  • Loading branch information
aawsome committed Jul 10, 2023
1 parent 40da0fc commit fe6bd32
Show file tree
Hide file tree
Showing 10 changed files with 705 additions and 778 deletions.
45 changes: 45 additions & 0 deletions crates/rustic_core/examples/restore.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//! `restore` example
use rustic_core::{
LocalDestination, Repository, RepositoryOptions, RestoreOpts, TreeStreamerOptions,
};
use simplelog::{Config, LevelFilter, SimpleLogger};

fn main() {
// Display info logs
let _ = SimpleLogger::init(LevelFilter::Info, Config::default());

// Open repository
let repo_opts = RepositoryOptions {
repository: Some("/tmp/repo".to_string()),
password: Some("test".to_string()),
..Default::default()
};

let repo = Repository::new(&repo_opts)
.unwrap()
.open()
.unwrap()
.to_indexed()
.unwrap();

// use latest snapshot without filtering snapshots
let node = repo.node_from_snapshot_path("latest", |_| true).unwrap();

// use list of the snapshot contents using no additional filtering
let recursive = true;
let streamer_opts = TreeStreamerOptions::default();
let ls = repo.ls(&node, &streamer_opts, recursive).unwrap();

let destination = "./restore/"; // restore to this destination dir
let create = true; // create destination dir, if it doesn't exist
let dest = LocalDestination::new(destination, create, !node.is_dir()).unwrap();

let opts = RestoreOpts::default();
let dry_run = false;
// create restore infos. Note: this also already creates needed dirs in the destination
let restore_infos = repo
.prepare_restore(&opts, ls.clone(), &dest, dry_run)
.unwrap();

repo.restore(restore_infos, &opts, ls, &dest).unwrap();
}
2 changes: 1 addition & 1 deletion crates/rustic_core/src/backend/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl LocalDestination {
Ok(Self { path, is_file })
}

fn path(&self, item: impl AsRef<Path>) -> PathBuf {
pub(crate) fn path(&self, item: impl AsRef<Path>) -> PathBuf {
if self.is_file {
self.path.clone()
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/rustic_core/src/blob/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub struct TreeStreamerOptions {
}

/// [`NodeStreamer`] recursively streams all nodes of a given tree including all subtrees in-order
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct NodeStreamer<BE>
where
BE: IndexedBackend,
Expand Down
1 change: 1 addition & 0 deletions crates/rustic_core/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pub mod init;
pub mod key;
pub mod prune;
pub mod repoinfo;
pub mod restore;
pub mod snapshots;
Loading

0 comments on commit fe6bd32

Please sign in to comment.