Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
907 changes: 351 additions & 556 deletions Cargo.lock

Large diffs are not rendered by default.

36 changes: 21 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "backup"
version = "0.1.1"
edition = "2021"
version = "0.1.2"
edition = "2024"
license = "MIT"
build = "build.rs"
repository = "https://github.com/BoltzExchange/cln-backup"
Expand All @@ -19,24 +19,30 @@ webdav = ["reqwest_dav"]
s3 = ["rust-s3"]

[dependencies]
anyhow = "1.0.98"
async-trait = "0.1.88"
chrono = "0.4.41"
cln-plugin = "0.4.0"
cln-rpc = "0.4.0"
flate2 = "1.1.1"
log = "0.4.27"
reqwest_dav = { version = "0.2.1", optional = true, features = ["rustls-tls"] }
rust-s3 = { version = "0.35.1", optional = true }
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
tokio = { version = "1.44.2", features = [
anyhow = "1.0.100"
async-trait = "0.1.89"
chrono = "0.4.42"
cln-plugin = "0.5.0"
cln-rpc = "0.5.0"
flate2 = "1.1.5"
log = "0.4.29"
reqwest_dav = { version = "0.2.2", optional = true, default-features = false, features = [
"rustls-tls",
] }
rust-s3 = { version = "0.37.1", optional = true, default-features = false, features = [
"tokio-rustls-tls",
"tags",
"fail-on-err",
] }
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.148"
tokio = { version = "1.48.0", features = [
"macros",
"rt-multi-thread",
"sync",
"rt",
] }
toml = "0.9.2"
toml = "0.9.10"

[build-dependencies]
built = { version = "0.8.0", features = ["git2"] }
2 changes: 2 additions & 0 deletions backup.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[[s3]]
endpoint = "your-s3-endpoint-1"
# region = "your-s3-region-1" # optional
bucket = "your-s3-bucket-1"
# path = "your/s3/path-1" # optional
access_key = "your-s3-access-key-1"
secret_key = "your-s3-secret-key-1"

[[s3]]
endpoint = "your-s3-endpoint-2"
# region = "your-s3-region-2" # optional
bucket = "your-s3-bucket-2"
# path = "your/s3/path-2" # optional
access_key = "your-s3-access-key-2"
Expand Down
2 changes: 1 addition & 1 deletion src/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crate::compression::Compression;
use crate::provider::Provider;
use anyhow::Result;
use chrono::Utc;
use cln_rpc::ClnRpc;
use cln_rpc::model::requests::StaticbackupRequest;
use cln_rpc::model::responses::StaticbackupResponse;
use cln_rpc::ClnRpc;
use log::info;
use std::sync::Arc;
use tokio::sync::Mutex;
Expand Down
2 changes: 1 addition & 1 deletion src/command/upload.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::State;
use crate::compression::Compression;
use crate::provider::Provider;
use crate::State;
use cln_plugin::Plugin;
use serde::Serialize;
use serde_json::Value;
Expand Down
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::path::PathBuf;
#[derive(Clone, Debug, Deserialize)]
pub struct S3Config {
pub endpoint: String,
pub region: Option<String>,
pub bucket: String,
pub path: Option<String>,
pub access_key: String,
Expand Down
33 changes: 13 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::backup::Backup;
use crate::compression::{Compression, Gzip};
use crate::config::Config;
use crate::provider::{MultiProvider, Provider};
use anyhow::{anyhow, Result};
use cln_plugin::{options, Builder, RpcMethodBuilder};
use anyhow::{Result, anyhow};
use cln_plugin::{Builder, RpcMethodBuilder, options};
use log::{info, warn};
use std::path::Path;
use std::sync::Arc;
Expand Down Expand Up @@ -40,10 +40,12 @@ where

#[tokio::main]
async fn main() -> Result<()> {
std::env::set_var(
"CLN_PLUGIN_LOG",
"cln_plugin=trace,backup=trace,debug,info,warn,error",
);
unsafe {
std::env::set_var(
"CLN_PLUGIN_LOG",
"cln_plugin=trace,backup=trace,debug,info,warn,error",
)
};

let plugin = match Builder::new(tokio::io::stdin(), tokio::io::stdout())
.dynamic()
Expand Down Expand Up @@ -89,10 +91,10 @@ async fn main() -> Result<()> {

#[cfg(feature = "webdav")]
{
if let Some(webdav_config) = config.webdav {
if let Err(err) = setup_webdav(&mut multi_provider, &webdav_config) {
warn!("Setting up WebDav failed: {err}");
}
if let Some(webdav_config) = config.webdav
&& let Err(err) = setup_webdav(&mut multi_provider, &webdav_config)
{
warn!("Setting up WebDav failed: {err}");
}
}

Expand Down Expand Up @@ -128,16 +130,7 @@ async fn main() -> Result<()> {

#[cfg(feature = "s3")]
async fn setup_s3(m: &mut MultiProvider, config: &crate::config::S3Config) -> Result<()> {
m.add(Arc::new(
S3::new(
&config.endpoint,
&config.bucket,
config.path.as_deref().unwrap_or(""),
&config.access_key,
&config.secret_key,
)
.await?,
));
m.add(Arc::new(S3::new(config).await?));

Ok(())
}
Expand Down
35 changes: 18 additions & 17 deletions src/provider/s3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::provider::Provider;
use anyhow::{anyhow, Result};
use anyhow::{Result, anyhow};
use async_trait::async_trait;
use log::info;
use s3::creds::Credentials;
Expand All @@ -12,22 +12,22 @@ pub struct S3 {
}

impl S3 {
pub async fn new(
endpoint: &str,
bucket: &str,
path: &str,
access_key: &str,
secret_key: &str,
) -> Result<Self> {
info!("Using S3 bucket {bucket} at {endpoint}");
pub async fn new(config: &crate::config::S3Config) -> Result<Self> {
info!("Using S3 bucket {} at {}", config.bucket, config.endpoint);

let bucket = Bucket::new(
bucket,
&config.bucket,
Region::Custom {
endpoint: endpoint.to_string(),
region: "".to_string(),
endpoint: config.endpoint.to_string(),
region: config.region.as_deref().unwrap_or("").to_string(),
},
Credentials::new(Some(access_key), Some(secret_key), None, None, None)?,
Credentials::new(
Some(&config.access_key),
Some(&config.secret_key),
None,
None,
None,
)?,
)?
.with_path_style();
if !bucket.exists().await? {
Expand All @@ -36,10 +36,11 @@ impl S3 {

Ok(Self {
bucket,
path: path
.to_string()
.strip_suffix("/")
.unwrap_or(path)
path: config
.path
.as_deref()
.unwrap_or("")
.trim_end_matches('/')
.to_string(),
})
}
Expand Down
8 changes: 4 additions & 4 deletions src/provider/webdav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ impl WebDav {
info!("Using WebDAV endpoint: {endpoint}");

let mut auth = Auth::Anonymous;
if let Some(user) = user {
if let Some(password) = password {
auth = Auth::Basic(user, password);
}
if let Some(user) = user
&& let Some(password) = password
{
auth = Auth::Basic(user, password);
}

let client = ClientBuilder::new()
Expand Down
2 changes: 1 addition & 1 deletion src/subscription/channel_state_changed.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::State;
use crate::compression::Compression;
use crate::provider::Provider;
use crate::State;
use anyhow::Result;
use cln_plugin::Plugin;
use log::error;
Expand Down