Skip to content

Commit

Permalink
feat(config): add backend options to config
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <[email protected]>

refactor: commands now use the new backend struct from rustic_backend

Signed-off-by: simonsan <[email protected]>

refactor: change config files and implement test to parse all config files with new settings for rustic_backend

Signed-off-by: simonsan <[email protected]>

fix: typo

Signed-off-by: simonsan <[email protected]>

style: dprint fmt

Signed-off-by: simonsan <[email protected]>

testing: use result

Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan committed Jan 1, 2024
1 parent 4f8120e commit 1683847
Show file tree
Hide file tree
Showing 18 changed files with 1,084 additions and 192 deletions.
1,020 changes: 923 additions & 97 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 22 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ rustdoc-args = ["--document-private-items", "--generate-link-to-definition"]

[dependencies]
abscissa_core = { workspace = true }
rustic_backend = { workspace = true }
rustic_core = { workspace = true }

# errors
Expand All @@ -63,6 +64,7 @@ log = { workspace = true }
# serialization
serde = { workspace = true }
serde_json = { workspace = true }
serde_path_to_error = { workspace = true }
serde_with = { workspace = true }

# other dependencies
Expand All @@ -84,25 +86,33 @@ humantime = { workspace = true }
indicatif = { workspace = true }
itertools = { workspace = true }
jemallocator-global = { version = "0.3.2", optional = true }
mimalloc = { version = "0.1.39", default_features = false, optional = true }
mimalloc = { version = "0.1.39", default-features = false, optional = true }
rhai = { workspace = true }
simplelog = { workspace = true }

[dev-dependencies]
abscissa_core = { workspace = true, features = ["testing"] }
aho-corasick = { workspace = true }
dircmp = { workspace = true }
insta = { version = "1.34.0", features = ["toml"] }
once_cell = { workspace = true }
pretty_assertions = { workspace = true }
rstest = { workspace = true }
rustic_testing = { path = "crates/rustic_testing" }
tempfile = { workspace = true }
toml = { workspace = true }
toml = { workspace = true, features = ["parse", "preserve_order"] }
toml_edit = { workspace = true, features = ["serde"] }

[target.'cfg(not(windows))'.dependencies]
libc = "0.2.150"
[workspace.dependencies]
rustic_core = { version = "0.1.2", features = ["cli"] }
abscissa_core = { version = "0.7.0", default-features = false, features = ["application"] }
rustic_core = { path = "../rustic_core/crates/core", version = "0.1.2", features = ["cli"] }
rustic_backend = { path = "../rustic_core/crates/backends", version = "0.1.0", features = ["cli"] }
# rustic_core = { version = "0.1.2", features = ["cli"] }

abscissa_core = { version = "0.7.0", default-features = false, features = [
"application",
] }

# logging
log = "0.4"
Expand All @@ -116,6 +126,8 @@ anyhow = "1"
serde = { version = "1", features = ["serde_derive"] }
serde_with = { version = "3.4", features = ["base64"] }
serde_json = "1"
serde_path_to_error = "0.1.14"
toml_edit = { version = "0.21.0", features = ["serde"] }

# other dependencies
aho-corasick = "1.1.2"
Expand Down Expand Up @@ -145,7 +157,7 @@ quickcheck = "1"
quickcheck_macros = "1"
tempfile = "3.8"
pretty_assertions = "1.4"
toml = "0.8"
toml = { version = "0.8", features = ["parse", "preserve_order"] }
dircmp = "0.2"

# cargo-binstall support
Expand Down Expand Up @@ -200,6 +212,11 @@ lto = true
debug-assertions = false
codegen-units = 1

# Faster insta testing runs
[profile.dev.package]
insta = { opt-level = 3 }
similar = { opt-level = 3 }

# Allows quick RPM file generation, if "cargo-generate-rpm" is installed:
# cargo build --release; cargo generate-rpm
# will result in a file like target/generate-rpm/rustic-rs-0.6.1-1.x86_64.rpm
Expand Down
58 changes: 35 additions & 23 deletions config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,33 @@ rustic.
config file as a possible source of errors if you encounter problems. They could
possibly shadow other values that you have already set.

### Backend Options

| Attribute | Description | Default Value | Example Value | Environment Variable |
| ---------- | ------------------------------------- | ------------- | ------------- | -------------------- |
| repository | The path to the repository. Required. | Not set | "/tmp/rustic" | RUSTIC_REPOSITORY |
| repo-hot | The path to the hot repository. | Not set | | RUSTIC_REPO_HOT |

### Backend Options (Additional)

| Attribute | Description | Default Value | Example Value |
| ------------------- | ---------------------------------------------------------------------- | ------------- | ------------------------------ |
| post-create-command | Command to execute after creating a snapshot in the **local backend**. | Not set | "par2create -qq -n1 -r5 %file" |
| post-delete-command | Command to execute after deleting a snapshot in the **local backend**. | Not set | "sh -c \"rm -f %file*.par2\"" |

### Repository Options

| Attribute | Description | Default Value | Example Value | Environment Variable |
| ---------------- | ---------------------------------------------------------- | ------------------------ | ---------------------- | ----------------------- |
| cache-dir | Path to the cache directory. | ~/.cache/rustic/$REPO_ID | ~/.cache/my_own_cache/ | RUSTIC_CACHE_DIR |
| no-cache | If true, disables caching. | false | | RUSTIC_NO_CACHE |
| repository | The path to the repository. Required. | Not set | "/tmp/rustic" | RUSTIC_REPOSITORY |
| repo-hot | The path to the hot repository. | Not set | | RUSTIC_REPO_HOT |
| password | The password for the repository. | Not set | "mySecretPassword" | RUSTIC_PASSWORD |
| password-file | Path to a file containing the password for the repository. | Not set | | RUSTIC_PASSWORD_FILE |
| password-command | Command to retrieve the password for the repository. | Not set | | RUSTIC_PASSWORD_COMMAND |
| warm-up | If true, warms up the repository by file access. | false | | |
| warm-up-command | Command to warm up the repository. | Not set | | |
| warm-up-wait | The wait time for warming up the repository. | Not set | | |

### Repository Options (Additional)

| Attribute | Description | Default Value | Example Value |
| ------------------- | ------------------------------------------------------------------ | ------------- | ------------------------------ |
| post-create-command | Command to execute after creating a snapshot in the local backend. | Not set | "par2create -qq -n1 -r5 %file" |
| post-delete-command | Command to execute after deleting a snapshot in the local backend. | Not set | "sh -c \"rm -f %file*.par2\"" |

### Snapshot-Filter Options

| Attribute | Description | Default Value | Example Value |
Expand Down Expand Up @@ -160,17 +165,24 @@ source-individual section.
**Note**: Copy-targets are simply repositories with the same defaults as within
the repository section.

| Attribute | Description | Default Value | Example Value |
| ------------------- | ---------------------------------------------------------------------- | ------------------------ | ---------------------- |
| cache-dir | Path to the cache directory for the target repository. | ~/.cache/rustic/$REPO_ID | ~/.cache/my_own_cache/ |
| no-cache | If true, disables caching for the target repository. | false | |
| password | The password for the target repository. | Not set | |
| password-file | Path to a file containing the password for the target repository. | Not set | |
| password-command | Command to retrieve the password for the target repository. | Not set | |
| post-create-command | Command to execute after creating a snapshot in the target repository. | Not set | |
| post-delete-command | Command to execute after deleting a snapshot in the target repository. | Not set | |
| repository | The path or URL to the target repository. | Not set | |
| repo-hot | The path or URL to the hot target repository. | Not set | |
| warm-up | If true, warms up the target repository by file access. | Not set | |
| warm-up-command | Command to warm up the target repository. | Not set | |
| warm-up-wait | The wait time for warming up the target repository. | Not set | |
#### Copy Target Backends

| Attribute | Description | Default Value | Example Value |
| ------------------- | ---------------------------------------------------------------------- | ------------- | ------------------------------ |
| repository | The path or URL to the target repository. | Not set | |
| repo-hot | The path or URL to the hot target repository. | Not set | |
| post-create-command | Command to execute after creating a snapshot in the **local backend**. | Not set | "par2create -qq -n1 -r5 %file" |
| post-delete-command | Command to execute after deleting a snapshot in the **local backend**. | Not set | "sh -c \"rm -f %file*.par2\"" |

#### Copy Target Options

| Attribute | Description | Default Value | Example Value |
| ---------------- | ----------------------------------------------------------------- | ------------------------ | ---------------------- |
| cache-dir | Path to the cache directory for the target repository. | ~/.cache/rustic/$REPO_ID | ~/.cache/my_own_cache/ |
| no-cache | If true, disables caching for the target repository. | false | |
| password | The password for the target repository. | Not set | |
| password-file | Path to a file containing the password for the target repository. | Not set | |
| password-command | Command to retrieve the password for the target repository. | Not set | |
| warm-up | If true, warms up the target repository by file access. | Not set | |
| warm-up-command | Command to warm up the target repository. | Not set | |
| warm-up-wait | The wait time for warming up the target repository. | Not set | |
21 changes: 15 additions & 6 deletions config/copy_example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@
# See "rustic copy --help" for options how to select or filter snapshots to copy.

# [repository] specified the source repository
[repository]
[backend]
repository = "/tmp/repo"

# [repository] specified the source repository
[repository]
password = "test"

# you can specify multiple targets
[[copy.targets]]
repository = "/tmp/repo2"
[[copy]]
[[copy.options]]
password = "test"
no-cache = true

[[copy.targets]]
repository = "rclone:ovh:backup"
repo-hot = "clone:ovh:backup-hot"
[[copy.backend]]
repository = "/tmp/repo2"

[[copy]]
[[copy.options]]
password-file = "/root/key-rustic-ovh"
cache-dir = "/var/lib/cache/rustic" # explicitly specify cache dir for remote repository

[[copy.backend]]
repository = "rclone|ovh:backup"
repo-hot = "rclone|ovh:backup-hot"
33 changes: 20 additions & 13 deletions config/full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@ dry-run = false
# This is only an example how to set an rclone env variable. Default: No variables are defined.
RCLONE_XXX = "true"

# Repository options: These options define which backend to use and which password to use.
[repository]
# Backend options: These options define which backend to use and which password 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]
# one of the three password options must be set
password = "mySecretPassword"
password-file = "/my/password.txt"
Expand All @@ -36,13 +46,6 @@ warm-up = false
warm-up-command = "warmup.sh %id" # Default: not set
warm-up-wait = "10min" # Default: not set

# Additional repository 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 Expand Up @@ -150,9 +153,8 @@ keep-within-yearly = "10 years"

# Multiple targets are available for the copy command. Each specify a repository with exactly identical options as in
# the [repository] section.
[[copy.targets]]
repository = "/repo/rustic" # Must be set
repo-hot = "/my/hot/repo" # Default: not set
[[copy]]
[[copy.options]]
# one of the three password options must be set
password = "mySecretPassword"
password-file = "/my/password.txt"
Expand All @@ -164,6 +166,11 @@ warm-up = false
warm-up-command = "warmup.sh %id" # Default: not set
warm-up-wait = "10min" # Default: not set

[[copy.targets]]
[[copy.backend]]
repository = "/repo/rustic" # Must be set
repo-hot = "/my/hot/repo" # Default: not set

[[copy]]
[[copy.backend]]
repository = "/repo/rustic2" # Must be set
# ...
4 changes: 3 additions & 1 deletion config/local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# backup usage: "rustic -P local backup
# cleanup: "rustic -P local forget --prune
#
[repository]
[backend]
repository = "/backup/rustic"

[repository]
password-file = "/root/key-rustic"
no-cache = true # no cache needed for local repository

Expand Down
4 changes: 3 additions & 1 deletion config/ovh-hot-cold.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
# backup usage: "rustic -P ovh-hot-cold backup
# cleanup: "rustic -P ovh-hot-cold forget --prune
#
[repository]
[backend]
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
8 changes: 5 additions & 3 deletions config/par2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
# 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.
[repository]
[backend]
repository = "/tmp/repo"
password = "test"

[repository.options]
[backend.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]
password = "test"
4 changes: 3 additions & 1 deletion config/rustic.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
log-level = "debug"
log-file = "/log/rustic.log"

[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
4 changes: 3 additions & 1 deletion config/simple.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[repository]
[backend]
repository = "/tmp/repo"

[repository]
password = "test"
5 changes: 4 additions & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ impl Configurable<RusticConfig> for EntryPoint {
/// [`RepositoryErrorKind::FromSplitError`]: crate::error::RepositoryErrorKind::FromSplitError
fn open_repository(config: &Arc<RusticConfig>) -> Result<Repository<ProgressOptions, OpenStatus>> {
let po = config.global.progress_options;
let repo = Repository::new_with_progress(&config.repository, po)?;

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

let repo = Repository::new_with_progress(&config.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
5 changes: 3 additions & 2 deletions src/commands/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +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 po = config.global.progress_options;
let repo = Repository::new_with_progress(&config.repository, po)?;
let repo = Repository::new_with_progress(&config.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 Expand Up @@ -224,7 +225,7 @@ impl BackupCmd {
.ignore_save_opts(opts.ignore_save_opts)
.ignore_filter_opts(opts.ignore_filter_opts)
.dry_run(config.global.dry_run);
let snap = repo.backup(&backup_opts, source.clone(), opts.snap_opts.to_snapshot()?)?;
let snap = repo.backup(&backup_opts, &source, opts.snap_opts.to_snapshot()?)?;

if opts.json {
let mut stdout = std::io::stdout();
Expand Down
Loading

0 comments on commit 1683847

Please sign in to comment.