Skip to content

Commit

Permalink
use backend and repository flattened under repository
Browse files Browse the repository at this point in the history
  • Loading branch information
aawsome committed Jan 15, 2024
1 parent 9096ee1 commit c3d74a6
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 52 deletions.
5 changes: 1 addition & 4 deletions config/copy_example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
# If the config file is named "copy_example.toml", run "rustic -P copy_example copy" to copy all snapshots.
# See "rustic copy --help" for options how to select or filter snapshots to copy.

# [backend] specifies the backend for a repository
[backend]
repository = "/tmp/repo"

# [repository] specifies the options for a repository
[repository]
repository = "/tmp/repo"
password = "test"

[copy]
Expand Down
20 changes: 9 additions & 11 deletions config/full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,11 @@ dry-run = false
# This is only an example how to set an rclone env variable. Default: No variables are defined.
RCLONE_XXX = "true"

# Backend options: These options define which backend to use.
[backend]
repository = "/repo/rustic" # Must be set
repo-hot = "/my/hot/repo" # Default: not set

# Additional backend options - depending on backend. These can be only set in the config file.
[backend.options]
post-create-command = "par2create -qq -n1 -r5 %file" # Only local backend; Default: not set
post-delete-command = "sh -c \"rm -f %file*.par2\"" # Only local backend; Default: not set
retry = "default" # Only rest/rclone backend; Allowed values: "false"/"off", "default" or number of retries
timeout = "10min" # Only rest/rclone backend

# Repository options: These options define which repository settings and passwords to use.
[repository]
repository = "/repo/rustic" # Must be set
repo-hot = "/my/hot/repo" # Default: not set
# Optional, but one of the three password options must be set
# either on CLI, in the config file or in environment variables
password = "mySecretPassword"
Expand All @@ -47,6 +38,13 @@ warm-up = false
warm-up-command = "warmup.sh %id" # Default: not set
warm-up-wait = "10min" # Default: not set

# Additional backend options - depending on backend. These can be only set in the config file.
[repository.options]
post-create-command = "par2create -qq -n1 -r5 %file" # Only local backend; Default: not set
post-delete-command = "sh -c \"rm -f %file*.par2\"" # Only local backend; Default: not set
retry = "default" # Only rest/rclone backend; Allowed values: "false"/"off", "default" or number of retries
timeout = "10min" # Only rest/rclone backend

# Snapshot-filter options: These options apply to all commands that use snapshot filters
[snapshot-filter]
filter-host = ["host2", "host2"] # Default: no host filter
Expand Down
5 changes: 1 addition & 4 deletions config/local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
# backup usage: "rustic -P local backup
# cleanup: "rustic -P local forget --prune

# Backend options: These options define which backend to use.
[backend]
repository = "/backup/rustic"

# Repository options: These options define which repository settings and passwords to use.
[repository]
repository = "/backup/rustic"
password-file = "/root/key-rustic"
no-cache = true # no cache needed for local repository

Expand Down
4 changes: 1 addition & 3 deletions config/ovh-hot-cold.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
# backup usage: "rustic -P ovh-hot-cold backup
# cleanup: "rustic -P ovh-hot-cold forget --prune

[backend]
[repository]
repository = "rclone:ovh:backup-home"
repo-hot = "rclone:ovh:backup-home-hot"

[repository]
password-file = "/root/key-rustic-ovh"
cache-dir = "/var/lib/cache/rustic" # explicitly specify cache dir for remote repository
warm-up = true # cold storage needs warm-up, just trying to access a file is sufficient to start the warm-up
Expand Down
9 changes: 3 additions & 6 deletions config/par2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
# error correction files using par2create to a local repository.
# The commands can use the variable %file, %type and %id which are replaced by the filename, the
# file type and the file id before calling the command.
[backend]
[repository]
repository = "/tmp/repo"
password = "test"

[backend.options]
[repository.options]
# after saving a file in the repo, this command is called
post-create-command = "par2create -qq -n1 -r5 %file"

# after removing a file from the repo, this command is called.
# Note that we want to use a "*" in the rm command, hence we have to call sh to resolve the wildcard!
post-delete-command = "sh -c \"rm -f %file*.par2\""

# Repository options: These options define which repository settings and passwords to use.
[repository]
password = "test"
5 changes: 1 addition & 4 deletions config/rustic.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
log-level = "debug"
log-file = "/log/rustic.log"

# Backend options: These options define which backend to use.
[backend]
repository = "/tmp/rustic"

# Repository options: These options define which backend to use and which password to use.
[repository]
repository = "/tmp/rustic"
password = "mySecretPassword"

# snapshot-filter options: These options apply to all commands that use snapshot filters
Expand Down
5 changes: 1 addition & 4 deletions config/simple.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Backend options: These options define which backend to use.
[backend]
repository = "/tmp/repo"

# Repository options: These options define which repository settings and passwords to use.
[repository]
repository = "/tmp/repo"
password = "test"
4 changes: 2 additions & 2 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ impl Configurable<RusticConfig> for EntryPoint {
fn open_repository(config: &Arc<RusticConfig>) -> Result<Repository<ProgressOptions, OpenStatus>> {
let po = config.global.progress_options;

let backends = config.backend.to_backends()?;
let backends = config.repository.backend.to_backends()?;

let repo = Repository::new_with_progress(&config.repository, backends, po)?;
let repo = Repository::new_with_progress(&config.repository.repository, backends, po)?;
match repo.password()? {
// if password is given, directly return the result of find_key_in_backend and don't retry
Some(pass) => {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ impl Runnable for BackupCmd {
impl BackupCmd {
fn inner_run(&self) -> Result<()> {
let config = RUSTIC_APP.config();
let backends = config.backend.to_backends()?;
let backends = config.repository.backend.to_backends()?;

let po = config.global.progress_options;
let repo = Repository::new_with_progress(&config.repository, backends, po)?;
let repo = Repository::new_with_progress(&config.repository.repository, backends, po)?;
// Initialize repository if --init is set and it is not yet initialized
let repo = if self.init && repo.config_id()?.is_none() {
if config.global.dry_run {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ fn copy_to_target<P: ProgressBars, I: IndexedFull>(
&mut |level, message| log!(level, "{}", message),
Level::Warn,
)?;
let backends = target_opts.backend.to_backends()?;
let backends = target_opts.repository.backend.to_backends()?;
Repository::new_with_progress(
&target_opts.repository,
&target_opts.repository.repository,
backends,
config.global.progress_options,
)?
Expand Down
4 changes: 2 additions & 2 deletions src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ impl Runnable for InitCmd {
impl InitCmd {
fn inner_run(&self) -> Result<()> {
let config = RUSTIC_APP.config();
let backends = config.backend.to_backends()?;
let backends = config.repository.backend.to_backends()?;

let po = config.global.progress_options;
let repo = Repository::new_with_progress(&config.repository, backends, po)?;
let repo = Repository::new_with_progress(&config.repository.repository, backends, po)?;

// Note: This is again checked in repo.init_with_password(), however we want to inform
// users before they are prompted to enter a password
Expand Down
5 changes: 3 additions & 2 deletions src/commands/repoinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ impl RepoInfoCmd {
fn inner_run(&self) -> Result<()> {
let config = RUSTIC_APP.config();

let backends = config.backend.to_backends()?;
let backends = config.repository.backend.to_backends()?;

let infos = Infos {
files: (!self.only_index)
.then(|| {
let po = config.global.progress_options;
let repo = Repository::new_with_progress(&config.repository, backends, po)?;
let repo =
Repository::new_with_progress(&config.repository.repository, backends, po)?;
repo.infos_files()
})
.transpose()?,
Expand Down
21 changes: 15 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@ pub struct RusticConfig {
#[clap(flatten, next_help_heading = "Global options")]
pub global: GlobalOptions,

#[clap(flatten, next_help_heading = "Backend options")]
pub backend: BackendOptions,

/// Repository options
#[clap(flatten, next_help_heading = "Repository options")]
pub repository: RepositoryOptions,
#[clap(flatten)]
pub repository: Repository,

/// Snapshot filter options
#[clap(flatten, next_help_heading = "Snapshot filter options")]
Expand All @@ -65,6 +61,19 @@ pub struct RusticConfig {
pub forget: ForgetOptions,
}

#[derive(Clone, Default, Debug, Parser, Deserialize, Merge)]
#[serde(default, rename_all = "kebab-case")]
pub struct Repository {
#[clap(flatten, next_help_heading = "Backend options")]
#[serde(flatten)]
pub backend: BackendOptions,

/// Repository options
#[clap(flatten, next_help_heading = "Repository options")]
#[serde(flatten)]
pub repository: RepositoryOptions,
}

impl RusticConfig {
/// Merge a profile into the current config by reading the corresponding config file.
/// Also recursively merge all profiles given within this config file.
Expand Down

0 comments on commit c3d74a6

Please sign in to comment.