### Webdav Command Examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of how to use the 'rustic webdav' command to start a WebDAV server. ```bash # Start WebDAV server rustic webdav # Bind to specific address rustic webdav --bind 0.0.0.0:8080 # With HTTPS rustic webdav --bind 0.0.0.0:8443 --tls ``` -------------------------------- ### run_before Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-config.md Example of running the before hook. ```rust config.global.hooks.run_before()?; ``` -------------------------------- ### Shell Completions Examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples for generating shell completions for various shells (bash, zsh) and how to install them. ```bash # Generate bash completions rustic completions bash # Install bash completions rustic completions bash > /etc/bash_completion.d/rustic # Generate for zsh rustic completions zsh > /usr/share/zsh/site-functions/_rustic ``` -------------------------------- ### Display Implementation Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-config.md Example of displaying the configuration. ```rust let config = RusticConfig::default(); println!("Current config:\n{}", config); ``` -------------------------------- ### open Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md Example usage of opening a repository and listing snapshots. ```rust let repo = Repo::open(&config.repository)?; let snapshots = repo.list_snapshots()?; ``` -------------------------------- ### run_open Method Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md Example of using `run_open` to get the count of snapshots. ```rust let snapshot_count = config.repository.run_open(|repo| { Ok(repo.list_snapshots()?.len()) })?; ``` -------------------------------- ### Install from source Source: https://github.com/rustic-rs/rustic/blob/main/README.md Installs the latest development version of rustic from its Git repository. ```bash cargo install --git https://github.com/rustic-rs/rustic.git rustic-rs ``` -------------------------------- ### Init Command Examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of how to use the 'rustic init' command to initialize a new backup repository. ```bash # Initialize local repository rustic init --repository /backups/myrepo --password mysecurepass # Initialize with environment variables export RUSTIC_REPO=/backups/myrepo export RUSTIC_PASSWORD=mysecurepass rustic init # Initialize cloud repository rustic init --repository sftp://backup.example.com/repo ``` -------------------------------- ### Mount Command Examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of how to use the 'rustic mount' command to mount a repository. ```bash # Mount repository rustic mount /mnt/backup # Mount with access for other users rustic mount /mnt/backup --allow-other ``` -------------------------------- ### table_right_from Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-helpers.md Illustrates creating a table with right-aligned columns starting from a specified index using table_right_from. ```rust use rustic::helpers::table_right_from; // First 2 columns left-aligned, rest right-aligned let mut t = table_right_from( vec!["Name", "Type", "Size", "Count"], 2 // Start right-align from "Size" ); t.add_row(vec!["file1.txt", "Text", "1.2 MB", "500"]); t.add_row(vec!["archive.tar", "Archive", "250 MB", "10000"]); println!("{}", t); ``` -------------------------------- ### Hooks Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/configuration.md Example of how to configure hooks in the TOML configuration file. ```toml [global.hooks] run-before = "echo 'Starting backup...'" run-after = "echo 'Backup completed successfully'" run-failed = "echo 'Backup failed!'" ``` -------------------------------- ### Install with Scoop on Windows Source: https://github.com/rustic-rs/rustic/blob/main/README.md Installs the rustic tool using Scoop on Windows. ```bash scoop install rustic ``` -------------------------------- ### Open Documentation Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Example for opening the project documentation in a web browser using the 'rustic docs' command. ```bash # Open documentation rustic docs ``` -------------------------------- ### Show Configuration Examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples for displaying the loaded configuration, both in standard format and JSON format, using the 'rustic show-config' command. ```bash # Display loaded config rustic show-config # Show in JSON rustic show-config --json ``` -------------------------------- ### Self-Update Examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples for updating the Rustic tool to the latest stable release, including an option to check for updates without installing. ```bash # Update to latest version rustic self-update # Check for updates without installing rustic self-update --check-only ``` -------------------------------- ### Install from crates.io Source: https://github.com/rustic-rs/rustic/blob/main/README.md Installs the latest stable version of rustic-rs from crates.io. ```bash cargo install --locked rustic-rs ``` -------------------------------- ### Bash Command Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/README.md Example of a Bash command for backing up data. ```bash rustic backup /data ``` -------------------------------- ### merge_profile Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-config.md Example of merging configuration profiles. ```rust let mut config = RusticConfig::default(); let mut logs = Vec::new(); // Load main profile config.merge_profile("rustic", &mut logs, Level::Info)?; // Load host-specific overrides config.merge_profile("myhost", &mut logs, Level::Warn)?; // Print merge logs for (level, msg) in logs { log::log!(level, "{}", msg); } ``` -------------------------------- ### Simple Repository Access Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md Example of accessing a repository and listing snapshots. ```rust use rustic::repository::AllRepositoryOptions; fn list_snapshots(repo_opts: &AllRepositoryOptions) -> Result<()> { repo_opts.run_open(|repo| { let snapshots = repo.list_snapshots()?; for snap in snapshots { println!("{} - {} files", snap.id, snap.paths.len()); } Ok(()) }) } ``` -------------------------------- ### Repoinfo Command Examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of how to use the 'rustic repoinfo' command to display repository information. ```bash # Show repo information rustic repoinfo # Show in JSON rustic repoinfo --json ``` -------------------------------- ### LoggingOptions::start_logger Method Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-config.md Example showing how to initialize the logger with specific LoggingOptions and dry_run setting. ```rust let options = LoggingOptions { log_level: Level::Debug, log_file: Some(PathBuf::from("rustic.log")), ..Default::default() }; options.start_logger(false)?; log::info!("Logger is now active"); log::debug!("This will be logged"); ``` -------------------------------- ### run Method Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md Example of executing a closure with an open repository to list snapshots. ```rust let result = config.repository.run(|repo| { let snapshots = repo.list_snapshots()?; Ok(snapshots.len()) })?; println!("Total snapshots: {}", result); ``` -------------------------------- ### Install with cargo-binstall Source: https://github.com/rustic-rs/rustic/blob/main/README.md Installs the rustic-rs crate using cargo-binstall. ```bash cargo binstall rustic-rs ``` -------------------------------- ### Profile-Based Configuration Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-config.md Example of loading Rustic configuration using profiles. ```rust let mut config = RusticConfig::default(); let mut logs = Vec::new(); // Load base configuration config.merge_profile("base", &mut logs, Level::Info)?; // Override with host-specific config config.merge_profile("myhost", &mut logs, Level::Warn)?; // Apply for (level, msg) in logs { log::log!(level, "{}", msg); } ``` -------------------------------- ### run_open_or_init_with Example Usage Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md Example demonstrating the use of run_open_or_init_with to ensure a repository exists before performing operations. ```rust config.repository.run_open_or_init_with(|repo| { // Repository is guaranteed to exist after this point let snap = repo.backup_snapshot(source)?; Ok(snap.id) })?; ``` -------------------------------- ### Snapshot Filter Examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/configuration.md Command-line examples demonstrating how to filter snapshots by hostname, label, tags, date, and size, including combining multiple filters. ```Bash # By hostname rustic snapshots --hostname myhost # By label rustic snapshots --label daily # By tags (all must match) rustic snapshots --tags production --tags backup # By date rustic snapshots --after 2024-01-01 --before 2024-02-01 # By size rustic snapshots --larger 100MB --smaller 1GB # Combine filters rustic snapshots --hostname myhost --label production --after 2024-01-01 ``` -------------------------------- ### Repository with Progress Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md Example of performing a backup with progress indication. ```rust fn backup_with_progress( config: &RusticConfig, source: &str, ) -> Result { config.repository.run_with_progress(|repo, progress| { let pb = progress.add(ProgressBar::new_spinner()); pb.set_message("Creating snapshot..."); let snapshot = repo.backup_snapshot(source)?; pb.finish_with_message("Done!"); Ok(snapshot) }) } ``` -------------------------------- ### SnapshotFilter.post_process Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-filtering.md Example usage of the post_process method. ```rust let mut filter = SnapshotFilter { jq: Some("select(.time > \"2024-01-01\")".to_string()), ..Default::default() }; let all_snapshots = repo.list_snapshots()?; let processed = filter.post_process(all_snapshots); ``` -------------------------------- ### BeforeDate Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-filtering.md Example usage of BeforeDate. ```rust let filter = SnapshotFilter { before: Some(BeforeDate( DateTime::parse_from_rfc3339("2024-02-01T00:00:00Z")? .with_timezone(&Utc) )), ..Default::default() }; ``` -------------------------------- ### load_toml Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-config.md Example of loading configuration from a TOML string. ```rust let toml_content = r#"# [global] dry-run = false log-level = "info" [repository] repository = "/backups/myrepo" #"#; let config = RusticConfig::load_toml(toml_content.to_string())?; assert_eq!(config.global.dry_run, false); ``` -------------------------------- ### Basic Configuration Usage Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-config.md Example of loading and using basic Rustic configuration from TOML. ```rust use rustic::RusticConfig; // Load from TOML let toml = r#"# [global] dry-run = false log-level = "info" [repository] repository = "/backups/repo" password = "secret" #"#; let config = RusticConfig::load_toml(toml.to_string())?; // Use configuration if config.global.dry_run { println!("Dry run mode enabled"); } ``` -------------------------------- ### with_env Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-config.md Example of setting environment variables for hooks. ```rust let env = vec![ ("RUSTIC_REPO".to_string(), "/backups/repo".to_string()), ("RUSTIC_SNAPSHOT".to_string(), "abc123".to_string()), ]; let hooks = config.global.hooks.with_env(&env); ``` -------------------------------- ### run_after Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-config.md Example of running the after hook after successful command execution. ```rust match command_result { Ok(_) => config.global.hooks.run_after()?, Err(_) => config.global.hooks.run_failed()?, } ``` -------------------------------- ### Backend Options Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/configuration.md Example of OpenDAL backend-specific options in the TOML configuration file. ```toml [repository.be] # Generic backend options options = { "key" = "value" } # Hot storage (recent snapshots) options-hot = { "key" = "value" } ``` -------------------------------- ### ProgressOptions::multi_progress Method Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-config.md Example demonstrating how to create an indicatif MultiProgress handle with ProgressOptions. ```rust let options = ProgressOptions { no_progress: false, progress_interval: Duration::from_millis(500), }; let mp = options.multi_progress(); let pb = mp.add(ProgressBar::new(100)); // Progress bar will update approximately every 500ms for i in 0..100 { pb.inc(1); std::thread::sleep(Duration::from_millis(10)); } ``` -------------------------------- ### Configuration Profiles Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/configuration.md Example TOML snippet showing how to specify multiple configuration files to be loaded using the profile system. ```toml # In config file [global] use-profiles = ["base", "local"] ``` -------------------------------- ### TOML Configuration Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/README.md Example of TOML configuration for Rustic. ```toml [global] dry-run = false ``` -------------------------------- ### Version Information Examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples for displaying version information, including a verbose output option, using the 'rustic version' command. ```bash # Show version rustic version # Show verbose version info rustic version --verbose ``` -------------------------------- ### Complete Example Configuration File Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/configuration.md A comprehensive example of a Rustic configuration file, demonstrating various sections like global options, logging, hooks, environment variables, repository settings, backup sources, retention policies, copy configurations, snapshot filtering, mount options, and WebDAV server settings. ```toml # Global options [global] group-by = "host" dry-run = false show-time-offset = false # Logging [global.logging-options] log-level = "info" log-file = "/var/log/rustic.log" # Hooks [global.hooks] run-before = "echo 'Starting backup at $(date)'" run-after = "echo 'Backup completed successfully'" run-failed = "echo 'Backup failed!'" # Environment variables [global.env] TMPDIR = "/var/tmp" # Repository configuration [repository] repository = "/mnt/backup-store" password = "${BACKUP_PASSWORD}" # Environment variable (with profile-substitute-env) no-cache = false cache-dir = "/var/cache/rustic" # Backup configuration [backup] no-scan = false stdin-filename = "backup.tar" [[backup.sources]] name = "system" path = "/" excludes = [ "/dev", "/proc", "/sys", "/tmp", "/var/tmp", "/**/.cache", "/**/.git", ] [[backup.sources]] name = "home" path = "/home" excludes = ["**/.cache", "**/.config/chromium/Default/Cache"] # Retention policy [forget] keep-last = 10 keep-daily = 30 keep-weekly = 52 keep-monthly = 12 keep-yearly = 7 # Copy to secondary repository [copy] copy-to = "s3://secondary-backup/repo" # Snapshot filtering [snapshot-filter] hostname = "myhost" # Mount configuration (if using mount command) [mount] mount-point = "/mnt/rustic" allow-other = false # WebDAV server (if using webdav command) [webdav] bind = "127.0.0.1:8000" tls = false ``` -------------------------------- ### Key Command Examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of how to use the 'rustic key' command for managing encryption keys. ```bash # List keys rustic key list # Add new key rustic key add # Change password rustic key change-password # Remove key rustic key remove key_id ``` -------------------------------- ### Repository Not Found Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/errors.md Example of handling a 'Repository Not Found' error. ```bash rustic snapshots --repository /nonexistent/path # Error: No such file or directory (os error 2) ``` -------------------------------- ### SnapshotFilter.matches Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-filtering.md Example usage of the matches method. ```rust let filter = SnapshotFilter { hostname: vec!["myhost".to_string()], label: vec!["daily".to_string()], ..Default::default() }; for snapshot in repo.list_snapshots()? { if filter.matches(&snapshot) { println!("Matched: {}", snapshot.id); } } ``` -------------------------------- ### List command examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of using the 'list' command to list repository contents by file type. ```bash # List all pack files rustic list packs ``` ```bash # List snapshots rustic list snaps ``` ```bash # List all types rustic list all --json ``` -------------------------------- ### Config Command Examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of how to use the 'rustic config' command to change repository configuration. ```bash # Change compression algorithm rustic config compression=zstd # Update multiple settings rustic config version=2 chunker-polynomial=0x3b6e20c27e88c6c9 ``` -------------------------------- ### Cold Storage Options Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/configuration.md Example configuration for cold storage. ```TOML options-cold = { "key" = "value" } ``` -------------------------------- ### repository Method Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md Example of creating a repository handle without opening it. ```rust let repo = config.repository.repository()?; ``` -------------------------------- ### Copy Command Examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of how to use the 'rustic copy' command to copy snapshots. ```bash # Copy all snapshots rustic copy --copy-to /backup/other-repo # Copy specific snapshots rustic copy abc123 def456 --copy-to sftp://backup.example.com/repo # Copy filtered snapshots (uses snapshot-filter options) rustic copy --hostname myhost --copy-to /other-repo ``` -------------------------------- ### Authentication Failed Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/errors.md Example of handling an 'Authentication Failed' error. ```bash export RUSTIC_PASSWORD=wrongpass rustic snapshots # Error: authentication failed ``` -------------------------------- ### Find command examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of using the 'find' command to search for patterns in snapshots. ```bash # Find all .log files rustic find "*.log" ``` ```bash # Find by name pattern rustic find "*backup*" ``` ```bash # Case-insensitive search rustic find "*.LOG" ``` -------------------------------- ### BackendOptions S3 Configuration Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md TOML example for configuring S3 backend options. ```toml [repository.be] options = { region = "us-east-1", bucket = "backup-bucket", } ``` -------------------------------- ### Hook Usage in Command Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-config.md Example demonstrating how to use hooks within a command execution context. ```rust use rustic::config::Hooks; fn run_backup(config: &RusticConfig) -> Result<()> { // Prepare environment let env = vec![ ("RUSTIC_REPO".to_string(), config.repository.repository.clone().unwrap_or_default()), ]; let hooks = config.global.hooks.with_context("backup").with_env(&env); // Use hooks hooks.use_with(|| { // Perform actual backup perform_backup(&config) }) } ``` -------------------------------- ### run_finally Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-config.md Example of running the finally hook, which always executes. ```rust let result = (|| { // ... perform operation ... Ok(()) })(); config.global.hooks.run_finally()?; result ``` -------------------------------- ### Rewrite Command Examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of how to use the 'rustic rewrite' command to rewrite snapshots. ```bash # Rewrite all snapshots rustic rewrite # Rewrite with new label rustic rewrite --set-label production ``` -------------------------------- ### run_with_progress Method Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md Example of using `run_with_progress` to process snapshots with progress bars. ```rust config.repository.run_with_progress(|repo, progress| { for snapshot in repo.list_snapshots()? { let pb = progress.add(ProgressBar::new(100)); // Process snapshot with progress bar pb.finish(); } Ok(()) })?; ``` -------------------------------- ### run Method Error Handling Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md Example demonstrating error handling with the `run` method. ```rust use anyhow::Context; config.repository.run(|repo| { repo.list_snapshots() .context("Failed to list snapshots") }) .context("Repository operation failed")?; ``` -------------------------------- ### Repo::open_with Example Usage Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md Example demonstrating how to use Repo::open_with to open a repository and list snapshots. ```rust let repo = Repo::open_with(&config.repository, Some("mypassword"))?; let snapshots = repo.list_snapshots()?; ``` -------------------------------- ### Configuration Profiles Example (Host-specific) Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/configuration.md Example TOML snippet for a host-specific configuration file, demonstrating the use of the profile system to load common and host-specific settings. ```toml In myhost.toml: ```toml [global] use-profiles = ["base", "myhost"] ``` ``` -------------------------------- ### Tag Management Examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples demonstrating how to add, remove, and set tags for snapshots using the 'rustic tag' command. ```bash # Add tag to snapshot rustic tag abc123 --add production # Remove tag rustic tag abc123 --remove staging # Set specific tags rustic tag abc123 --set production --set daily ``` -------------------------------- ### run_failed Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-config.md Example of running the failed hook after command failure. ```rust if let Err(e) = command_result { config.global.hooks.run_failed()?; return Err(e); } ``` -------------------------------- ### Diff command examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of using the 'diff' command to compare two snapshots or paths. ```bash # Compare two snapshots rustic diff abc123 def456 ``` ```bash # Compare specific path rustic diff abc123 def456 /home ``` ```bash # Show in JSON rustic diff abc123 def456 --json ``` -------------------------------- ### List Snapshots Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/README.md Examples of listing snapshots with different options. ```bash rustic snapshots rustic snapshots --long rustic snapshots --group-by path ``` -------------------------------- ### Environment Variables Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/configuration.md Example of how to set environment variables for subcommands in the TOML configuration file. ```toml [global.env] RUST_LOG = "info" TMPDIR = "/custom/tmp" ``` -------------------------------- ### get_grouped_snapshots Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md Example usage of getting snapshots grouped by a custom criterion. ```rust use rustic_core::SnapshotGroupCriterion; let snapshots = get_grouped_snapshots( &repo, &config.snapshot_filter, SnapshotGroupCriterion::Label, )?; // Snapshots now grouped by label ``` -------------------------------- ### Ls command examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of using the 'ls' command to list file contents of a snapshot. ```bash # List snapshot contents rustic ls 5ed5b58e ``` ```bash # List specific path in snapshot rustic ls 5ed5b58e /etc ``` ```bash # Detailed listing rustic ls 5ed5b58e --long ``` ```bash # JSON output rustic ls 5ed5b58e --json ``` -------------------------------- ### Copy Options Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/configuration.md Configure snapshot copying between repositories. ```toml [copy] copy-to = "s3://backup-bucket/copy-repo" ``` -------------------------------- ### Unknown Configuration Keys Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/errors.md Example of a configuration error when an unknown configuration key is used. ```toml [global] unknown_option = true ``` -------------------------------- ### Dump command examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of using the 'dump' command to extract file contents from a snapshot to stdout. ```bash # Extract file to stdout rustic dump 5ed5b58e /var/log/syslog ``` ```bash # Extract and pipe to other tools rustic dump 5ed5b58e /etc/passwd | grep root ``` -------------------------------- ### get_global_grouped_snapshots Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md Example usage of getting snapshots grouped by a global criterion. ```rust let snapshots = get_global_grouped_snapshots(&repo, &config.snapshot_filter)?; for group in snapshots { println!("Group:"); for snap in group { println!(" - {}", snap.id); } } ``` -------------------------------- ### SnapshotFilter Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-filtering.md Example of creating a SnapshotFilter with SizeRange for specific size constraints. ```rust use rustic::filtering::SizeRange; // Snapshots between 100MB and 1GB let filter = SnapshotFilter { larger: Some(SizeRange { min: Some(100_000_000), max: None, }), smaller: Some(SizeRange { min: None, max: Some(1_000_000_000), }), ..Default::default() }; ``` -------------------------------- ### Cat command examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of using the 'cat' command to display raw file or blob data from a repository. ```bash # Display blob contents rustic cat blob abc123def456 ``` ```bash # Display tree metadata rustic cat tree tree_id ``` ```bash # Display snapshot JSON rustic cat snapshot snap_id ``` -------------------------------- ### LoggingOptions::config Method Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-config.md Example demonstrating how to create a log4rs configuration from LoggingOptions. ```rust let options = LoggingOptions { log_level: Level::Info, log_file: Some(PathBuf::from("/var/log/rustic.log")), ..Default::default() }; let config = options.config(); ``` -------------------------------- ### use_with Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-config.md Example of using the use_with method to run an operation between hooks. ```rust let result = config.global.hooks.use_with(|| { perform_backup() })?; ``` -------------------------------- ### bytes_size_to_string Usage Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-helpers.md Examples demonstrating the usage of `bytes_size_to_string` with different byte values. ```rust use rustic::helpers::bytes_size_to_string; println!("{}", bytes_size_to_string(512)); // "512 B" println!("{}", bytes_size_to_string(1_500_000)); // "1.43 MB" println!("{}", bytes_size_to_string(2_684_354_560)); // "2.5 GB" println!("{}", bytes_size_to_string(1_099_511_627_776)); // "1 TB" ``` -------------------------------- ### Inverse Operation Example using bytesize crate Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-helpers.md An example showing how to parse human-readable sizes back into bytes using the `bytesize` crate. ```rust use bytesize::ByteSize; let size = "10 MB".parse::()?; println!("{}", size.0); // 10485760 (bytes) ``` -------------------------------- ### JQ Filter Example (Size) Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-filtering.md Example of using jq to filter snapshots by size. ```bash # Filter by size rustic snapshots --jq 'select(.summary.total_size > 1073741824)' ``` -------------------------------- ### Hooks::with_context Method Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-config.md Example showing how to add context to hook commands using the with_context method. ```rust let hooks = config.global.hooks.with_context("backup"); hooks.run_before()?; ``` -------------------------------- ### BackendOptions Environment Variable Override Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md Bash examples for overriding backend options using environment variables. ```bash export RUSTIC_REPO_OPT_REGION=us-east-1 export RUSTIC_REPO_OPT_BUCKET=backup-bucket export RUSTIC_REPO_OPTHOT_ACCESS_KEY=hot_key export RUSTIC_REPO_OPTCOLD_ACCESS_KEY=cold_key ``` -------------------------------- ### JQ Filter Example (Hostname) Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-filtering.md Example of using jq to filter snapshots by hostname. ```bash # Filter by hostname rustic snapshots --jq 'select(.hostname == "myhost")' ``` -------------------------------- ### Prune command examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of using the 'prune' command to remove unused data and repack repository files. ```bash # Standard pruning rustic prune ``` ```bash # Prune without progress output rustic prune --progress false ``` ```bash # Only repack, don't delete rustic prune --prune-packs false ``` -------------------------------- ### JQ Filter Example (Date) Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-filtering.md Example of using jq to filter snapshots by date. ```bash # Filter by date rustic snapshots --jq 'select(.time > "2024-01-01T00:00:00Z")' ``` -------------------------------- ### run_indexed Example Usage Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md Example demonstrating how to use the run_indexed function to perform operations on an indexed repository. ```rust config.repository.run_indexed(|repo| { // Can now do indexed operations repo.check_repository()?; Ok(()) })?; ``` -------------------------------- ### Create Backup Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/README.md Examples of creating backups, including auto-initialization and faster modes. ```bash rustic backup /path/to/data rustic backup --init /path/to/data # Auto-initialize rustic backup --no-scan /path/to/data # Faster, no ETA ``` -------------------------------- ### AfterDate Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-filtering.md Example usage of AfterDate. ```rust use chrono::DateTime; use rustic::filtering::AfterDate; let filter = SnapshotFilter { after: Some(AfterDate( DateTime::parse_from_rfc3339("2024-01-01T00:00:00Z")? .with_timezone(&Utc) )), ..Default::default() }; ``` -------------------------------- ### Install with Homebrew on macOS Source: https://github.com/rustic-rs/rustic/blob/main/README.md Installs the rustic tool using Homebrew on macOS. ```bash brew install rustic ``` -------------------------------- ### Prometheus Configuration Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/overview.md Configuration example for enabling Prometheus metrics export. ```toml [global] prometheus = true prometheus-user = "user" prometheus-pass = "pass" ``` -------------------------------- ### get_filtered_snapshots Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md Example usage of filtering snapshots. ```rust use rustic::filtering::SnapshotFilter; let filter = SnapshotFilter { hostname: vec!["myhost".to_string()], after: Some(AfterDate(yesterday)), ..Default::default() }; let snapshots = get_filtered_snapshots(&repo, &filter)?; ``` -------------------------------- ### Backup Command: Source Not Found Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/errors.md Example error output when the source path for the backup command is not found. ```bash rustic backup /nonexistent/path # Error: No such file or directory (os error 2) ``` -------------------------------- ### get_snapshots_from_ids Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-repository.md Example usage of retrieving snapshots by their IDs. ```rust let ids = vec!["abc123", "def456"]; let snapshots = get_snapshots_from_ids(&repo, &ids)?; for snap in snapshots { println!("Snapshot {}: {} files", snap.id, snap.paths.len()); } ``` -------------------------------- ### Merge Snapshots Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Example of merging multiple snapshots into a single snapshot with an optional label using the 'rustic merge' command. ```bash # Merge snapshots rustic merge abc123 def456 --label merged ``` -------------------------------- ### Index Corruption Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/errors.md Example of handling an 'Index Corruption' error. ```bash rustic check # Error: index inconsistency detected ``` -------------------------------- ### Basic Repository Access Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/overview.md Example of basic repository access in Rust. ```rust use rustic::repository::AllRepositoryOptions; let repo = config.repository.repository()?; // repo not yet opened ``` -------------------------------- ### Reference Backup Sources in Command Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/configuration.md Command-line examples showing how to reference defined backup sources by name in the backup command. ```Bash rustic backup --name home rustic backup --name home --name database ``` -------------------------------- ### Repository Locked Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/errors.md Example demonstrating a scenario where a repository might be locked. ```bash # Process 1 rustic backup /data & # Process 2 (while process 1 is running) rustic check ``` -------------------------------- ### table Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-helpers.md Shows how to create a default ASCII markdown-style table using the table function. ```rust use rustic::helpers::table; let mut t = table(); t.add_row(vec!["Col1", "Col2", "Col3"]); t.add_row(vec!["Value1", "Value2", "Value3"]); println!("{}", t); ``` -------------------------------- ### Rust Code Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/README.md Example of Rust code for Rustic configuration. ```rust let config = RusticConfig::default(); ``` -------------------------------- ### Creating Summary Tables for Snapshots Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-helpers.md Example of using `table_with_titles` and `bytes_size_to_string` to display snapshot information. ```rust use rustic::helpers::table_with_titles; fn show_snapshots_table(snapshots: &[SnapshotFile]) { let mut t = table_with_titles(vec![ "ID", "Date", "Hostname", "Files", "Size", ]); for snap in snapshots { t.add_row(vec![ &snap.id.to_string()[..8], &snap.time.to_string(), &snap.hostname, &snap.summary.files.to_string(), &bytes_size_to_string(snap.summary.total_size), ]); } println!("{}", t); } ``` -------------------------------- ### JQ Filter Example (Complex) Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-filtering.md Example of complex filtering using jq. ```bash # Complex filtering rustic snapshots --jq 'select(.hostname == "prod" and (.tags | contains(["daily"])))' ``` -------------------------------- ### Forget command examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of using the 'forget' command for snapshot retention policies. ```bash # Keep last 10 snapshots rustic forget --keep-last 10 ``` ```bash # Keep daily backups for 30 days, weekly for a year rustic forget --keep-daily 30 --keep-weekly 52 ``` ```bash # Remove specific snapshots rustic forget abc123 def456 ``` ```bash # Complex retention policy rustic forget --keep-last 5 --keep-hourly 24 --keep-daily 7 --keep-weekly 4 --keep-monthly 12 ``` -------------------------------- ### Rhai Runtime Error Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/errors.md Example of a runtime error in a Rhai filter script. ```bash rustic snapshots --function "unknown_var == 'value'" # Error: RhaiEval - variable 'unknown_var' not found ``` -------------------------------- ### Rhai Parse Error Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/errors.md Example of a syntax error in a Rhai filter expression. ```bash rustic snapshots --function "snapshot.hostname == 'host" # Error: RhaiParse - unclosed bracket ``` -------------------------------- ### Storage Backend Configuration Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/overview.md Configuration example for specifying a repository location using OpenDAL. ```toml [repository] repository = "s3://bucket/path" [repository.be] options = { "region" = "us-east-1" } ``` -------------------------------- ### Formatting Statistics for Backup Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-helpers.md Example of using `table_right_from` and `bytes_size_to_string` to display backup statistics. ```rust use rustic::helpers::{table_right_from, bytes_size_to_string}; fn show_stats(stats: &BackupStatistics) { let mut t = table_right_from( vec!["Metric", "Value"], 1 ); t.add_row(vec!["Files processed", &stats.files.to_string()]); t.add_row(vec!["Directories", &stats.dirs.to_string()]); t.add_row(vec!["Data processed", &bytes_size_to_string(stats.bytes)]); t.add_row(vec!["Data stored", &bytes_size_to_string(stats.bytes_stored)]); println!("{}", t); } ``` -------------------------------- ### Type Mismatch Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/errors.md Example of a configuration error due to a type mismatch for a configuration option. ```toml [global.progress_options] progress_interval = "not a duration" # Should be like "500ms" ``` -------------------------------- ### Logging Configuration Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/overview.md Configuration example for setting log levels and file output. ```toml [global.logging-options] log-level = "info" log-file = "/var/log/rustic.log" log-level-dryrun = "debug" ``` -------------------------------- ### Repository Configuration Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/README.md Example of repository configuration, including path and backend options, in TOML format. ```toml [repository] repository = "/backups/repo" password = "${BACKUP_PASSWORD}" [repository.be] options = { "region" = "us-east-1" } ``` -------------------------------- ### Building Complex Tables for Repository Info Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-helpers.md Example of using `table_with_titles` and `bytes_size_to_string` to display repository information. ```rust use rustic::helpers::table_with_titles; use comfy_table::Cell; fn show_repository_info(repo: &Repository) -> Result<()> { let mut t = table_with_titles(vec!["Property", "Value"]); let info = repo.get_info()?; t.add_row(vec![ "Repository", &format!("{:?}", info.repo_url), ]); t.add_row(vec![ "Version", &info.version.to_string(), ]); t.add_row(vec![ "Total Size", &bytes_size_to_string(info.total_size), ]); t.add_row(vec![ "Snapshots", &info.snapshot_count.to_string(), ]); println!("{}", t); Ok(()) } ``` -------------------------------- ### Repair Command Examples Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/commands.md Examples of how to use the 'rustic repair' command to repair snapshots or the repository index. ```bash # Repair snapshots rustic repair # Rebuild index rustic repair --rebuild-index ``` -------------------------------- ### Invalid TOML Syntax Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/errors.md Example of a TOML configuration error due to missing an equals sign. ```toml # config error: missing equals [global] dry_run true # Should be: dry_run = true ``` -------------------------------- ### Rust Type Signature Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/README.md Example of a Rust function type signature with generics and bounds. ```rust pub fn run(&self, f: F) -> Result where F: FnOnce(OpenRepo) -> Result, ``` -------------------------------- ### Building Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/README.md Commands to build the project and check the version. ```bash cargo build --release ./target/release/rustic --version ``` -------------------------------- ### Network Storage: Connection Failed Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/errors.md Example error output when a connection to a remote storage backend fails. ```bash rustic backup /data --repository s3://bucket/repo # Error: Failed to connect to S3: connection refused ``` -------------------------------- ### bold_cell Example Source: https://github.com/rustic-rs/rustic/blob/main/_autodocs/api-reference-helpers.md Demonstrates how to create a table cell with bold styling using the bold_cell function. ```rust use rustic::helpers::bold_cell; use comfy_table::Table; let mut table = Table::new(); table.add_row(vec![ bold_cell("Snapshot ID"), bold_cell("Date"), bold_cell("Files"), ]); table.add_row(vec![ "abc123...", "2024-01-15", "1000", ]); ```