-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
120 additions
and
137 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,24 @@ | ||
//! `backup` example | ||
use rustic_core::{BackupOpts, PathList, Repository, RepositoryOptions, SnapshotFile}; | ||
use simplelog::{Config, LevelFilter, SimpleLogger}; | ||
use std::error::Error; | ||
|
||
fn main() { | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
// 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_ids() | ||
.unwrap(); | ||
let repo_opts = RepositoryOptions::default() | ||
.repository("tmp/repo") | ||
.password("test"); | ||
let repo = Repository::new(&repo_opts)?.open()?.to_indexed_ids()?; | ||
|
||
let backup_opts = BackupOpts::default(); | ||
let source = PathList::from_string(".", true).unwrap(); // true: sanitize the given string | ||
let source = PathList::from_string(".", true)?; // true: sanitize the given string | ||
let dry_run = false; | ||
|
||
let snap = repo | ||
.backup(&backup_opts, source, SnapshotFile::default(), dry_run) | ||
.unwrap(); | ||
let snap = repo.backup(&backup_opts, source, SnapshotFile::default(), dry_run)?; | ||
|
||
println!("successfully created snapshot:\n{snap:#?}") | ||
println!("successfully created snapshot:\n{snap:#?}"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
//! `check` example | ||
use rustic_core::{CheckOpts, Repository, RepositoryOptions}; | ||
use simplelog::{Config, LevelFilter, SimpleLogger}; | ||
use std::error::Error; | ||
|
||
fn main() { | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
// 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(); | ||
let repo_opts = RepositoryOptions::default() | ||
.repository("tmp/repo") | ||
.password("test"); | ||
let repo = Repository::new(&repo_opts)?.open()?; | ||
|
||
// Check respository with standard options | ||
let opts = CheckOpts::default(); | ||
repo.check(opts).unwrap() | ||
repo.check(opts)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
//! `config` example | ||
use rustic_core::{ConfigOpts, Repository, RepositoryOptions}; | ||
use simplelog::{Config, LevelFilter, SimpleLogger}; | ||
use std::error::Error; | ||
|
||
fn main() { | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
// 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(); | ||
let repo_opts = RepositoryOptions::default() | ||
.repository("tmp/repo") | ||
.password("test"); | ||
let repo = Repository::new(&repo_opts)?.open()?; | ||
|
||
// Set Config, e.g. Compression level | ||
let config_opts = ConfigOpts { | ||
set_compression: Some(22), | ||
..Default::default() | ||
}; | ||
repo.apply_config(&config_opts).unwrap(); | ||
repo.apply_config(&config_opts)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,26 @@ | ||
//! `forget` example | ||
use rustic_core::{KeepOptions, Repository, RepositoryOptions, SnapshotGroupCriterion}; | ||
use simplelog::{Config, LevelFilter, SimpleLogger}; | ||
use std::error::Error; | ||
|
||
fn main() { | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
// 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(); | ||
let repo_opts = RepositoryOptions::default() | ||
.repository("tmp/repo") | ||
.password("test"); | ||
let repo = Repository::new(&repo_opts)?.open()?; | ||
|
||
// Check respository with standard options | ||
let group_by = SnapshotGroupCriterion::default(); | ||
let mut keep = KeepOptions::default(); | ||
keep.keep_daily = 5; | ||
keep.keep_weekly = 10; | ||
let snaps = repo | ||
.get_forget_snapshots(&keep, group_by, |_| true) | ||
.unwrap(); | ||
let snaps = repo.get_forget_snapshots(&keep, group_by, |_| true)?; | ||
println!("{snaps:?}"); | ||
// to remove the snapshots-to-forget, uncomment this line: | ||
// repo.delete_snapshots(&snaps.into_forget_ids()).unwrap() | ||
// repo.delete_snapshots(&snaps.into_forget_ids())? | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
//! `init` example | ||
use rustic_core::{ConfigOpts, KeyOpts, Repository, RepositoryOptions}; | ||
use simplelog::{Config, LevelFilter, SimpleLogger}; | ||
use std::error::Error; | ||
|
||
fn main() { | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
// Display info logs | ||
let _ = SimpleLogger::init(LevelFilter::Info, Config::default()); | ||
|
||
// Init repository | ||
let repo_opts = RepositoryOptions { | ||
repository: Some("/tmp/repo".to_string()), | ||
password: Some("test".to_string()), | ||
..Default::default() | ||
}; | ||
let repo_opts = RepositoryOptions::default() | ||
.repository("tmp/repo") | ||
.password("test"); | ||
let key_opts = KeyOpts::default(); | ||
let config_opts = ConfigOpts::default(); | ||
let _repo = Repository::new(&repo_opts) | ||
.unwrap() | ||
.init(&key_opts, &config_opts) | ||
.unwrap(); | ||
let _repo = Repository::new(&repo_opts)?.init(&key_opts, &config_opts)?; | ||
|
||
// -> use _repo for any operation on an open repository | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
//! `key` example | ||
use rustic_core::{KeyOpts, Repository, RepositoryOptions}; | ||
use simplelog::{Config, LevelFilter, SimpleLogger}; | ||
use std::error::Error; | ||
|
||
fn main() { | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
// 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(); | ||
let repo_opts = RepositoryOptions::default() | ||
.repository("tmp/repo") | ||
.password("test"); | ||
let repo = Repository::new(&repo_opts)?.open()?; | ||
|
||
// Add a new key with the given password | ||
let key_opts = KeyOpts::default(); | ||
repo.add_key("new_password", &key_opts).unwrap(); | ||
repo.add_key("new_password", &key_opts)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,27 @@ | ||
//! `ls` example | ||
use rustic_core::{Repository, RepositoryOptions, TreeStreamerOptions}; | ||
use simplelog::{Config, LevelFilter, SimpleLogger}; | ||
use std::error::Error; | ||
|
||
fn main() { | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
// 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(); | ||
let repo_opts = RepositoryOptions::default() | ||
.repository("tmp/repo") | ||
.password("test"); | ||
let repo = Repository::new(&repo_opts)?.open()?.to_indexed()?; | ||
|
||
// use latest snapshot without filtering snapshots | ||
let node = repo.node_from_snapshot_path("latest", |_| true).unwrap(); | ||
let node = repo.node_from_snapshot_path("latest", |_| true)?; | ||
|
||
// recursively list the snapshot contents using no additional filtering | ||
let recursive = true; | ||
let streamer_opts = TreeStreamerOptions::default(); | ||
for item in repo.ls(&node, &streamer_opts, recursive).unwrap() { | ||
let (path, _) = item.unwrap(); | ||
for item in repo.ls(&node, &streamer_opts, recursive)? { | ||
let (path, _) = item?; | ||
println!("{path:?} "); | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
//! `prune` example | ||
use rustic_core::{PruneOpts, Repository, RepositoryOptions}; | ||
use simplelog::{Config, LevelFilter, SimpleLogger}; | ||
use std::error::Error; | ||
|
||
fn main() { | ||
fn main() -> Result<(), Box<dyn Error>> { | ||
// 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(); | ||
let repo_opts = RepositoryOptions::default() | ||
.repository("tmp/repo") | ||
.password("test"); | ||
let repo = Repository::new(&repo_opts)?.open()?; | ||
|
||
let prune_opts = PruneOpts::default(); | ||
let prune_plan = repo.prune_plan(&prune_opts).unwrap(); | ||
let prune_plan = repo.prune_plan(&prune_opts)?; | ||
println!("{:?}", prune_plan.stats); | ||
println!("to repack: {:?}", prune_plan.repack_packs()); | ||
// to run the plan uncomment this line: | ||
// prune_plan.do_prune(&repo, &prune_opts).unwrap(); | ||
// prune_plan.do_prune(&repo, &prune_opts)?; | ||
Ok(()) | ||
} |
Oops, something went wrong.