Skip to content

Commit

Permalink
Merge branch 'main' into dump-tar
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsan authored Nov 30, 2024
2 parents 660534f + 852635e commit c4040c2
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 34 deletions.
79 changes: 79 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rustic - fast, encrypted, deduplicated backups powered by Rust
"""

[features]
default = ["tui", "webdav"]
default = ["tui", "webdav", "rhai", "jq"]
release = ["default", "self-update"]

# Allocators
Expand All @@ -37,6 +37,10 @@ webdav = [
]
mount = ["dep:fuse_mt"]

# Filtering
rhai = ["dep:rhai"]
jq = ["dep:jaq-core", "dep:jaq-std", "dep:jaq-json"]

[[bin]]
name = "rustic"
path = "src/bin/rustic.rs"
Expand Down Expand Up @@ -87,7 +91,6 @@ serde_with = { version = "3", features = ["base64"] }
aho-corasick = "1"
chrono = { version = "0.4", default-features = false, features = ["clock", "serde"] }
comfy-table = "7"
rhai = { version = "1", features = ["sync", "serde", "no_optimize", "no_module", "no_custom_syntax", "only_i64"] }
scopeguard = "1"
semver = { version = "1", optional = true }
simplelog = "0.12"
Expand All @@ -100,6 +103,7 @@ clap = { version = "4", features = ["derive", "env", "wrap_help"] }
clap_complete = "4"
conflate = "0.3.3"
convert_case = "0.6.0"
ctrlc = { version = "3.4.5", features = ["termination"] }
dateparser = "0.2.1"
derive_more = { version = "1", features = ["debug"] }
dialoguer = "0.11.0"
Expand All @@ -119,6 +123,12 @@ toml = "0.8"
flate2 = "1.0.34"
zip = { version = "2.2.0", default-features = false, features = ["deflate", "chrono"] }

# filtering
jaq-core = { version = "2", optional = true }
jaq-json = { version = "1", features = ["serde_json"], optional = true }
jaq-std = { version = "2", optional = true }
rhai = { version = "1", features = ["sync", "serde", "no_optimize", "no_module", "no_custom_syntax", "only_i64"], optional = true }

[dev-dependencies]
abscissa_core = { version = "0.8.1", default-features = false, features = ["testing"] }
assert_cmd = "2.0.16"
Expand Down
31 changes: 16 additions & 15 deletions config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,22 @@ See [Global Hooks](#global-hooks-globalhooks).

### Snapshot-Filter Options `[snapshot-filter]`

| Attribute | Description | Default Value | Example Value | CLI Option |
| ------------------ | ---------------------------------------------------------------------- | ------------- | ------------------------ | -------------------- |
| filter-hosts | Array of hosts to filter snapshots. | Not set | ["myhost", "host2"] | --filter-host |
| filter-labels | Array of labels to filter snapshots. | Not set | ["mylabal"] | --filter-label |
| filter-paths | Array of pathlists to filter snapshots. | Not set | ["/home,/root"] | --filter-paths |
| filter-paths-exact | Array or string of paths to filter snapshots. Exact match. | Not set | ["path1,path2", "path3"] | --filter-paths-exact |
| filter-tags | Array of taglists to filter snapshots. | Not set | ["tag1,tag2"] | --filter-tags |
| filter-tags-exact | Array or string of tags to filter snapshots. Exact match. | Not set | ["tag1,tag2", "tag3"] | --filter-tags-exact |
| filter-before | Filter snapshots before the given date/time | Not set | "2024-01-01" | --filter-before |
| filter-after | Filter snapshots after the given date/time | Not set | "2023-01-01 11:15:23" | --filter-after |
| filter-size | Filter snapshots for a total size in the size range. | Not set | "1MB..1GB" | --filter-size |
| | If a single value is given, this is taken as lower bound. | | "500 k" | |
| filter-size-added | Filter snapshots for a size added to the repository in the size range. | Not set | "1MB..1GB" | --filter-size-added |
| | If a single value is given, this is taken as lower bound. | | "500 k" | |
| filter-fn | Custom filter function for snapshots. | Not set | | --filter-fn |
| Attribute | Description | Default Value | Example Value | CLI Option |
| ------------------ | ---------------------------------------------------------------------- | ------------- | -------------------------- | -------------------- |
| filter-hosts | Array of hosts to filter snapshots. | Not set | ["myhost", "host2"] | --filter-host |
| filter-labels | Array of labels to filter snapshots. | Not set | ["mylabal"] | --filter-label |
| filter-paths | Array of pathlists to filter snapshots. | Not set | ["/home,/root"] | --filter-paths |
| filter-paths-exact | Array or string of paths to filter snapshots. Exact match. | Not set | ["path1,path2", "path3"] | --filter-paths-exact |
| filter-tags | Array of taglists to filter snapshots. | Not set | ["tag1,tag2"] | --filter-tags |
| filter-tags-exact | Array or string of tags to filter snapshots. Exact match. | Not set | ["tag1,tag2", "tag3"] | --filter-tags-exact |
| filter-before | Filter snapshots before the given date/time | Not set | "2024-01-01" | --filter-before |
| filter-after | Filter snapshots after the given date/time | Not set | "2023-01-01 11:15:23" | --filter-after |
| filter-size | Filter snapshots for a total size in the size range. | Not set | "1MB..1GB" | --filter-size |
| | If a single value is given, this is taken as lower bound. | | "500 k" | |
| filter-size-added | Filter snapshots for a size added to the repository in the size range. | Not set | "1MB..1GB" | --filter-size-added |
| | If a single value is given, this is taken as lower bound. | | "500 k" | |
| filter-fn | Custom filter function for snapshots. | Not set | | --filter-fn |
| filter-jq | Custom filter jq function for snapshots. Should return bool | Not set | ".summary.files_added > 1" | --filter-jq |

### Backup Options `[backup]`

Expand Down
2 changes: 2 additions & 0 deletions config/full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ filter-before = "2024-02-05 12:15" # Default: not set
filter-size = "200MiB" # Default: not set
filter-size-added = "1 MB..10MB" # Default: not set
filter-fn = '|sn| {sn.host == "host1" || sn.description.contains("test")}' # Default: no filter function
filter-jq = '.description | contains ("test")' # Default: no jq filter function

# Backup options: These options are used for all sources when calling the backup command.
# They can be overwritten by source-specific options (see below) or command line options.
Expand Down Expand Up @@ -174,6 +175,7 @@ filter-before = "2024-02-05 12:15" # Default: not set
filter-size = "200MiB" # Default: not set
filter-size-added = "1 MB..10MB" # Default: not set
filter-fn = '|sn| {sn.host == "host1" || sn.description.contains("test")}' # Default: no filter function
filter-jq = '.description | contains ("test")' # Default: no jq filter function
# The retention options follow. All of these are not set by default.
keep-tags = ["tag1", "tag2,tag3"] # Default: not set
keep-ids = [
Expand Down
17 changes: 16 additions & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use std::fmt::Debug;
use std::fs::File;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::mpsc::channel;

#[cfg(feature = "mount")]
use crate::commands::mount::MountCmd;
Expand Down Expand Up @@ -64,7 +65,7 @@ use clap::builder::{
};
use convert_case::{Case, Casing};
use human_panic::setup_panic;
use log::{log, Level};
use log::{info, log, Level};
use simplelog::{CombinedLogger, LevelFilter, TermLogger, TerminalMode, WriteLogger};

use self::find::FindCmd;
Expand Down Expand Up @@ -179,6 +180,20 @@ impl Runnable for EntryPoint {
// Set up panic hook for better error messages and logs
setup_panic!();

// Set up Ctrl-C handler
let (tx, rx) = channel();

ctrlc::set_handler(move || tx.send(()).expect("Could not send signal on channel."))
.expect("Error setting Ctrl-C handler");

_ = std::thread::spawn(move || {
// Wait for Ctrl-C
rx.recv().expect("Could not receive from channel.");
info!("Ctrl-C received, shutting down...");
RUSTIC_APP.shutdown(Shutdown::Graceful)
});

// Run the subcommand
self.commands.run();
RUSTIC_APP.shutdown(Shutdown::Graceful)
}
Expand Down
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Error types
use abscissa_core::error::{BoxError, Context};
#[cfg(feature = "rhai")]
use rhai::EvalAltResult;
use std::{
fmt::{self, Display},
Expand All @@ -18,6 +19,7 @@ pub(crate) enum ErrorKind {
}

/// Kinds of [`rhai`] errors
#[cfg(feature = "rhai")]
#[derive(Debug, Error)]
pub(crate) enum RhaiErrorKinds {
#[error(transparent)]
Expand Down
Loading

0 comments on commit c4040c2

Please sign in to comment.