Skip to content
Draft
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
49 changes: 34 additions & 15 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ rustdoc-args = ["--document-private-items", "--generate-link-to-definition"]

[dependencies]
abscissa_core = { version = "0.7.0", default-features = false, features = ["application"] }
rustic_backend = { git = "https://github.com/rustic-rs/rustic_core.git", features = ["cli"] }
rustic_core = { git = "https://github.com/rustic-rs/rustic_core.git", features = ["cli"] }
rustic_backend = { git = "https://github.com/rustic-rs/rustic_core.git", branch = "enumset", features = ["cli"] }
rustic_core = { git = "https://github.com/rustic-rs/rustic_core.git", branch = "enumset", features = ["cli"] }

# allocators
jemallocator-global = { version = "0.3.2", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ If you want to contribute your own configuration, please
| dry-run | If true, performs a dry run without making any changes. | false | | RUSTIC_DRY_RUN |
| log-level | Logging level. Possible values: "off", "error", "warn", "info", "debug", "trace". | "info" | | RUSTIC_LOG_LEVEL |
| log-file | Path to the log file. | No log file | "/log/rustic.log" | RUSTIC_LOG_FILE |
| json | If true, returns output of the command as json. | false | | RUSTIC_JSON |
| no-progress | If true, disables progress indicators. | false | | RUSTIC_NO_PROGRESS |
| progress-interval | The interval at which progress indicators are shown. | "100ms" | "1m" | RUSTIC_PROGRESS_INTERVAL |
| use-profile | An array of profiles to use. Allows to recursely use other profiles. | Empty array | | RUSTIC_USE_PROFILE |
Expand Down Expand Up @@ -133,7 +134,6 @@ can be overwritten in the source-specifc configuration, see below.
| ignore-ctime | If true, ignore file change time (ctime). | false | |
| ignore-inode | If true, ignore file inode for the backup. | false | |
| init | If true, initialize repository if it doesn't exist, yet. | false | |
| json | If true, returns output of the command as json. | false | |
| label | Set label fot the snapshot. | Not set | |
| no-require-git | (with git-ignore:) Apply .git-ignore files even if they are not in a git repository. | false | |
| no-scan | Don't scan the backup source for its size (disables ETA). | false | |
Expand Down
2 changes: 1 addition & 1 deletion config/full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ log-file = "/path/to/rustic.log" # Default: not set
no-progress = false
progress-interval = "100ms"
dry-run = false
json = false

# Global env variables: These are set by rustic before calling a subcommand, e.g. rclone or commands
# defined in the repository options.
Expand Down Expand Up @@ -99,7 +100,6 @@ exclude-if-present = [".nobackup", "CACHEDIR.TAG"] # Default: not set
custom-ignorefile = [".rusticignore", ".backupignore"] # Default: not set
one-file-system = false
exclude-larger-than = "100MB" # Default: not set
json = false
init = false
no-scan = false
quiet = false
Expand Down
9 changes: 2 additions & 7 deletions src/commands/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ pub struct BackupCmd {
/// Don't scan the backup source for its size - this disables ETA estimation for backup.
#[clap(long)]
#[merge(strategy = merge::bool::overwrite_false)]
pub no_scan: bool,

/// Output generated snapshot in json format
#[clap(long)]
#[merge(strategy = merge::bool::overwrite_false)]
json: bool,
no_scan: bool,

/// Don't show any output
#[clap(long, conflicts_with = "json")]
Expand Down Expand Up @@ -228,7 +223,7 @@ impl BackupCmd {
.dry_run(config.global.dry_run);
let snap = repo.backup(&backup_opts, &source, opts.snap_opts.to_snapshot()?)?;

if opts.json {
if config.global.json {
let mut stdout = std::io::stdout();
serde_json::to_writer_pretty(&mut stdout, &snap)?;
} else if !opts.quiet {
Expand Down
12 changes: 6 additions & 6 deletions src/commands/forget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ pub(super) struct ForgetCmd {
#[clap(value_name = "ID")]
ids: Vec<String>,

/// Show infos in json format
#[clap(long)]
json: bool,

/// Don't show any output
#[clap(long, conflicts_with = "json")]
quiet: bool,
Expand Down Expand Up @@ -123,7 +119,7 @@ impl ForgetCmd {
ForgetGroups(vec![item])
};

if self.json {
if config.global.json {
let mut stdout = std::io::stdout();
serde_json::to_writer_pretty(&mut stdout, &groups)?;
} else if !self.quiet {
Expand All @@ -132,7 +128,11 @@ impl ForgetCmd {

let forget_snaps = groups.into_forget_ids();

match (forget_snaps.is_empty(), config.global.dry_run, self.json) {
match (
forget_snaps.is_empty(),
config.global.dry_run,
config.global.json,
) {
(true, _, false) => println!("nothing to remove"),
(false, true, false) => {
println!("would have removed the following snapshots:\n {forget_snaps:?}");
Expand Down
6 changes: 1 addition & 5 deletions src/commands/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ pub(super) struct MergeCmd {
#[clap(value_name = "ID")]
ids: Vec<String>,

/// Output generated snapshot in json format
#[clap(long)]
json: bool,

/// Remove input snapshots after merging
#[clap(long)]
delete: bool,
Expand Down Expand Up @@ -53,7 +49,7 @@ impl MergeCmd {

let snap = repo.merge_snapshots(&snapshots, &last_modified_node, snap)?;

if self.json {
if config.global.json {
let mut stdout = std::io::stdout();
serde_json::to_writer_pretty(&mut stdout, &snap)?;
}
Expand Down
8 changes: 7 additions & 1 deletion src/commands/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ impl PruneCmd {

let pruner = repo.prune_plan(&self.opts)?;

print_stats(&pruner.stats);
if config.global.json {
let mut stdout = std::io::stdout();
let debug: Vec<_> = pruner.stats.debug.0.iter().collect();
serde_json::to_writer_pretty(&mut stdout, &debug)?;
} else {
print_stats(&pruner.stats);
}

if config.global.dry_run {
repo.warm_up(pruner.repack_packs().into_iter())?;
Expand Down
6 changes: 1 addition & 5 deletions src/commands/repoinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ pub(crate) struct RepoInfoCmd {
/// Only scan index
#[clap(long)]
only_index: bool,

/// Show infos in json format
#[clap(long)]
json: bool,
}

impl Runnable for RepoInfoCmd {
Expand Down Expand Up @@ -66,7 +62,7 @@ impl RepoInfoCmd {
.transpose()?,
};

if self.json {
if config.global.json {
let mut stdout = std::io::stdout();
serde_json::to_writer_pretty(&mut stdout, &infos)?;
return Ok(());
Expand Down
6 changes: 1 addition & 5 deletions src/commands/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ pub(crate) struct SnapshotCmd {
#[arg(long)]
long: bool,

/// Show snapshots in json format
#[clap(long, conflicts_with = "long")]
json: bool,

/// Show all snapshots instead of summarizing identical follow-up snapshots
#[clap(long, conflicts_with_all = &["long", "json"])]
all: bool,
Expand All @@ -64,7 +60,7 @@ impl SnapshotCmd {
config.snapshot_filter.matches(sn)
})?;

if self.json {
if config.global.json {
let mut stdout = std::io::stdout();
serde_json::to_writer_pretty(&mut stdout, &groups)?;
return Ok(());
Expand Down
5 changes: 5 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ pub struct GlobalOptions {
#[clap(long, global = true, env = "RUSTIC_LOG_FILE", value_name = "LOGFILE")]
pub log_file: Option<PathBuf>,

/// Output in JSON format
#[clap(long, global = true, env = "RUSTIC_JSON")]
#[merge(strategy = merge::bool::overwrite_false)]
pub json: bool,

/// Settings to customize progress bars
#[clap(flatten)]
#[serde(flatten)]
Expand Down