{
    "content": [
        {
            "type": "text",
            "text": "# btrfs-restore(8) (man)\n\n## TLDR\n\n> Try to salvage files from a damaged btrfs filesystem.\n\n- Restore all files from a btrfs filesystem to a given directory:\n  `sudo btrfs {{rest|restore}} {{path/to/btrfs_device}} {{path/to/target_directory}}`\n- List (don't write) files to be restored from a btrfs filesystem:\n  `sudo btrfs {{rest|restore}} {{-D|--dry-run}} {{path/to/btrfs_device}} {{path/to/target_directory}}`\n- Restore files matching a given `regex` ([c]ase-insensitive) files to be restored from a btrfs filesystem (all parent directories of target file(s) must match as well):\n  `sudo btrfs {{rest|restore}} --path-regex {{regex}} -c {{path/to/btrfs_device}} {{path/to/target_directory}}`\n- Restore files from a btrfs filesystem using a specific root [t]ree `bytenr` (see `btrfs-find-root`):\n  `sudo btrfs {{rest|restore}} -t {{bytenr}} {{path/to/btrfs_device}} {{path/to/target_directory}}`\n- Restore files from a btrfs filesystem (along with metadata, extended attributes, and Symlinks), overwriting files in the target:\n  `sudo btrfs {{rest|restore}} {{-m|--metadata}} {{-x|--xattr}} {{-S|--symlinks}} {{-o|--overwrite}} {{path/to/btrfs_device}} {{path/to/target_directory}}`\n\n*Source: tldr-pages*\n\n---\n\n**Summary:** btrfs-restore - try to restore files from a damaged btrfs filesystem image\n\n**Synopsis:** btrfs restore [options] <device> <path> | -l <device>\n\n## Flags\n\n| Flag | Long | Arg | Description |\n|------|------|-----|-------------|\n| -d | — | — | find directory -l|--list-roots list subvolume tree roots, can be used as argument for -r -D|--dry-run dry run (only list |\n| -c | — | — | ignore case (--path-regex only) -v|--verbose (deprecated) alias for global -v option |\n\n## See Also\n\n- mkfs.btrfs(8)\n- btrfs-rescue(8)\n- btrfs-check(8)\n- BTRFS-RESTORE(8)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (2 lines)\n- **DESCRIPTION** (20 lines)\n- **OPTIONS** (30 lines) — 3 subsections\n  - -d (16 lines)\n  - -c (5 lines)\n  - Global options (3 lines)\n- **EXIT STATUS** (3 lines)\n- **AVAILABILITY** (3 lines)\n- **SEE ALSO** (5 lines)\n\n## Full Content\n\n### NAME\n\nbtrfs-restore - try to restore files from a damaged btrfs filesystem image\n\n### SYNOPSIS\n\nbtrfs restore [options] <device> <path> | -l <device>\n\n### DESCRIPTION\n\nbtrfs restore is used to try to salvage files from a damaged filesystem and restore them into\n<path> or just list the subvolume tree roots. The filesystem image is not modified.\n\nIf the filesystem is damaged and cannot be repaired by the other tools (btrfs-check(8) or\nbtrfs-rescue(8)), btrfs restore could be used to retrieve file data, as far as the metadata\nare readable. The checks done by restore are less strict and the process is usually able to\nget far enough to retrieve data from the whole filesystem. This comes at a cost that some\ndata might be incomplete or from older versions if they’re available.\n\nThere are several options to attempt restoration of various file metadata type. You can try a\ndry run first to see how well the process goes and use further options to extend the set of\nrestored metadata.\n\nFor images with damaged tree structures, there are several options to point the process to\nsome spare copy.\n\nNote\nIt is recommended to read the following btrfs wiki page if your data is not salvaged with\ndefault option: https://btrfs.wiki.kernel.org/index.php/Restore\n\n### OPTIONS\n\n-s|--snapshots\nget also snapshots that are skipped by default\n\n-x|--xattr\nget extended attributes\n\n-m|--metadata\nrestore owner, mode and times for files and directories\n\n-S|--symlinks\nrestore symbolic links as well as normal files\n\n-i|--ignore-errors\nignore errors during restoration and continue\n\n-o|--overwrite\noverwrite directories/files in <path>, eg. for repeated runs\n\n-t <bytenr>\nuse <bytenr> to read the root tree\n\n-f <bytenr>\nonly restore files that are under specified subvolume root pointed by <bytenr>\n\n-u|--super <mirror>\nuse given superblock mirror identified by <mirror>, it can be 0,1 or 2\n\n-r|--root <rootid>\nonly restore files that are under a specified subvolume whose objectid is <rootid>\n\n#### -d\n\nfind directory\n\n-l|--list-roots\nlist subvolume tree roots, can be used as argument for -r\n\n-D|--dry-run\ndry run (only list files that would be recovered)\n\n--path-regex <regex>\nrestore only filenames matching a regular expression (regex(7)) with a mandatory format\n\n^/(|home(|/username(|/Desktop(|/.*))))$\n\nThe format is not very comfortable and restores all files in the directories in the whole\npath, so this is not useful for restoring single file in a deep hierarchy.\n\n#### -c\n\nignore case (--path-regex only)\n\n-v|--verbose\n(deprecated) alias for global -v option\n\n#### Global options\n\n-v|--verbose\nbe verbose and print what is being restored\n\n### EXIT STATUS\n\nbtrfs restore returns a zero exit status if it succeeds. Non zero is returned in case of\nfailure.\n\n### AVAILABILITY\n\nbtrfs is part of btrfs-progs. Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for\nfurther details.\n\n### SEE ALSO\n\nmkfs.btrfs(8), btrfs-rescue(8), btrfs-check(8)\n\n\n\nBtrfs v5.16.2                                02/16/2022                             BTRFS-RESTORE(8)\n\n"
        }
    ],
    "structuredContent": {
        "command": "btrfs-restore",
        "section": "8",
        "mode": "man",
        "summary": "btrfs-restore - try to restore files from a damaged btrfs filesystem image",
        "synopsis": "btrfs restore [options] <device> <path> | -l <device>",
        "tldr_summary": "Try to salvage files from a damaged btrfs filesystem.",
        "tldr_examples": [
            {
                "description": "Restore all files from a btrfs filesystem to a given directory",
                "command": "sudo btrfs {{rest|restore}} {{path/to/btrfs_device}} {{path/to/target_directory}}"
            },
            {
                "description": "List (don't write) files to be restored from a btrfs filesystem",
                "command": "sudo btrfs {{rest|restore}} {{-D|--dry-run}} {{path/to/btrfs_device}} {{path/to/target_directory}}"
            },
            {
                "description": "Restore files matching a given `regex` ([c]ase-insensitive) files to be restored from a btrfs filesystem (all parent directories of target file(s) must match as well)",
                "command": "sudo btrfs {{rest|restore}} --path-regex {{regex}} -c {{path/to/btrfs_device}} {{path/to/target_directory}}"
            },
            {
                "description": "Restore files from a btrfs filesystem using a specific root [t]ree `bytenr` (see `btrfs-find-root`)",
                "command": "sudo btrfs {{rest|restore}} -t {{bytenr}} {{path/to/btrfs_device}} {{path/to/target_directory}}"
            },
            {
                "description": "Restore files from a btrfs filesystem (along with metadata, extended attributes, and Symlinks), overwriting files in the target",
                "command": "sudo btrfs {{rest|restore}} {{-m|--metadata}} {{-x|--xattr}} {{-S|--symlinks}} {{-o|--overwrite}} {{path/to/btrfs_device}} {{path/to/target_directory}}"
            }
        ],
        "tldr_source": "official",
        "flags": [
            {
                "flag": "-d",
                "long": null,
                "arg": null,
                "description": "find directory -l|--list-roots list subvolume tree roots, can be used as argument for -r -D|--dry-run dry run (only list files that would be recovered) --path-regex <regex> restore only filenames matching a regular expression (regex(7)) with a mandatory format ^/(|home(|/username(|/Desktop(|/.*))))$ The format is not very comfortable and restores all files in the directories in the whole path, so this is not useful for restoring single file in a deep hierarchy."
            },
            {
                "flag": "-c",
                "long": null,
                "arg": null,
                "description": "ignore case (--path-regex only) -v|--verbose (deprecated) alias for global -v option"
            }
        ],
        "examples": [],
        "see_also": [
            {
                "name": "mkfs.btrfs",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/mkfs.btrfs/8/json"
            },
            {
                "name": "btrfs-rescue",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/btrfs-rescue/8/json"
            },
            {
                "name": "btrfs-check",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/btrfs-check/8/json"
            },
            {
                "name": "BTRFS-RESTORE",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/BTRFS-RESTORE/8/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 20,
                "subsections": []
            },
            {
                "name": "OPTIONS",
                "lines": 30,
                "subsections": [
                    {
                        "name": "-d",
                        "lines": 16,
                        "flag": "-d"
                    },
                    {
                        "name": "-c",
                        "lines": 5,
                        "flag": "-c"
                    },
                    {
                        "name": "Global options",
                        "lines": 3
                    }
                ]
            },
            {
                "name": "EXIT STATUS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "AVAILABILITY",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ]
    }
}