-
|
Hi all, I'm a fairly satisfied restic user but I prefer rust to go and have kept my eye on rustic for a while. One of my primary interests would be using the My current restic repo is accessed over sftp. I started tinkering yesterday and could not figure out how to run a Hello World (just listing snapshots) to SFTP without requiring an external configuration file (something I'm hoping to avoid). Is something like this possible? Does anyone have any examples? Many thanks for your time. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
For examples about how to use let backends = BackendOptions::default().repository("opendal:sftp").options(stfp_opts).to_backends();and Then, use the methods |
Beta Was this translation helpful? Give feedback.
-
|
Sorry it's taken so long to test this out -- I ran into #1394 which confused me mightily for a bit, but once I generated a new key got the below PoC working: use rustic_backend::BackendOptions;
use rustic_core::{Credentials, Repository, RepositoryOptions};
use simplelog::{Config, LevelFilter, SimpleLogger};
use std::{collections::BTreeMap, error::Error};
fn main() -> Result<(), Box<dyn Error>> {
let _ = SimpleLogger::init(LevelFilter::Info, Config::default());
let sftp_opts: BTreeMap<_, _> = [
("endpoint", "ssh://1.2.3.4:54321"),
("key", "/abspath/to/restic/privkey"),
("root", "relpath/from/~restic/to/repo"),
("user", "restic"),
]
.into_iter()
.map(|(a, b)| (a.to_string(), b.to_string()))
.collect();
let backends = BackendOptions::default()
.repository("opendal:sftp")
.options(sftp_opts)
.to_backends()?;
let repo_opts = RepositoryOptions::default();
let credentials = Credentials::password(r#"SUPERSECRET"#);
let repo = Repository::new(&repo_opts, &backends)?.open(&credentials)?;
dbg!(&repo);
dbg!(repo.get_all_snapshots()?.iter().next());
Ok(())
}Beautiful! |
Beta Was this translation helpful? Give feedback.
For examples about how to use
rustic_core, see https://github.com/rustic-rs/rustic_core/tree/main/examples.The idea is to create a
Repositoryinstance fromRepositoryOptionsandRepositoryBackendsbuilt fromBackendOptions. For sftp, this should be like:and
sftp_optscan be set e.g. by creating a BTreeMap using the parameter from https://nightlies.apache.org/opendal/opendal-docs-release-v0.46.0/docs/services/sftp/ .(Note that for sftp there are some limitations by opendal.)
Then, use the methods
Repositoryprovides, e.g.open()and thenget_all_snapshots().