Skip to main content

btrfs_cli/
restore.rs

1use crate::{Format, Runnable};
2use anyhow::Result;
3use clap::Parser;
4use std::path::PathBuf;
5
6/// Try to restore files from a damaged filesystem (unmounted).
7///
8/// Attempt to recover files from a damaged or inaccessible btrfs filesystem
9/// by scanning the raw filesystem structures. This command works on unmounted
10/// devices and can recover files even when the filesystem cannot be mounted
11/// normally. Recovery options allow selective restoration of files, metadata,
12/// and extended attributes. Requires CAP_SYS_ADMIN.
13#[derive(Parser, Debug)]
14pub struct RestoreCommand {
15    /// Block device containing the damaged filesystem
16    device: PathBuf,
17
18    /// Destination path for recovered files (not needed with --list-roots)
19    path: Option<PathBuf>,
20
21    /// Dry run (only list files that would be recovered)
22    #[clap(short = 'D', long = "dry-run")]
23    dry_run: bool,
24
25    /// Ignore errors
26    #[clap(short = 'i', long)]
27    ignore_errors: bool,
28
29    /// Overwrite existing files
30    #[clap(short = 'o', long)]
31    overwrite: bool,
32
33    /// Restore owner, mode and times
34    #[clap(short = 'm', long)]
35    metadata: bool,
36
37    /// Restore symbolic links
38    #[clap(short = 'S', long)]
39    symlink: bool,
40
41    /// Get snapshots
42    #[clap(short = 's', long)]
43    snapshots: bool,
44
45    /// Restore extended attributes
46    #[clap(short = 'x', long)]
47    xattr: bool,
48
49    /// Restore only filenames matching regex
50    #[clap(long)]
51    path_regex: Option<String>,
52
53    /// Ignore case (used with --path-regex)
54    #[clap(short = 'c')]
55    ignore_case: bool,
56
57    /// Find dir
58    #[clap(short = 'd')]
59    find_dir: bool,
60
61    /// List tree roots
62    #[clap(short = 'l', long)]
63    list_roots: bool,
64
65    /// Filesystem location (bytenr)
66    #[clap(short = 'f')]
67    fs_location: Option<u64>,
68
69    /// Root objectid
70    #[clap(short = 'r', long)]
71    root: Option<u64>,
72
73    /// Tree location (bytenr)
74    #[clap(short = 't')]
75    tree_location: Option<u64>,
76
77    /// Super mirror index
78    #[clap(short = 'u', long = "super")]
79    super_mirror: Option<u64>,
80}
81
82impl Runnable for RestoreCommand {
83    fn run(&self, _format: Format, _dry_run: bool) -> Result<()> {
84        todo!("implement restore")
85    }
86}