Journalctl을 통해 BTRFS에서 손상된 파일의 전체 경로를 찾는 방법은 무엇입니까?

Journalctl을 통해 BTRFS에서 손상된 파일의 전체 경로를 찾는 방법은 무엇입니까?

btrfs scrub손상된 파일은 실행 후 감지될 수 있습니다. 수정할 수 없는 파일을 식별하기 위해 디스크의 모든 파일을 읽어볼 수 있습니다.

sudo find / -type f -exec cp -v {} /dev/null \; 2> corrupted-files.txt

이 명령의 출력은 사용자의 요구 사항을 충족합니다. 그러나 완료하는 데 몇 시간이 걸립니다.

Arch Linux 위키에서는 손상된 파일을 식별하기 위해 다음 명령을 사용할 것을 권장합니다.

sudo journalctl --output cat | grep 'BTRFS .* i/o error' | sort | uniq 

결과가 빨리 나옵니다. 그러나 파일 경로는 하위 볼륨 경로에 상대적이므로 백업에서 파일을 복구하는 데 유용합니다.

BTRFS warning (device dm-2): i/o error at logical 69945753600 on dev /dev/mapper/zeytin-root, sector 142920640, root 636, inode 172280, offset 238682112, length 4096, links 1 (path: home/aea/couchdb/couchdb/data/shards/60000000-7fffffff/client2.1533443496.couch)
BTRFS warning (device dm-2): i/o error at logical 70045958144 on dev /dev/mapper/zeytin-root, sector 143116352, root 422, inode 172296, offset 307662848, length 4096, links 1 (path: home/aea/couchdb/couchdb/data/shards/e0000000-ffffffff/client2.1533443496.couch)
BTRFS warning (device dm-2): i/o error at logical 70045958144 on dev /dev/mapper/zeytin-root, sector 143116352, root 636, inode 172296, offset 307662848, length 4096, links 1 (path: home/aea/couchdb/couchdb/data/shards/e0000000-ffffffff/client2.1533443496.couch)
BTRFS warning (device dm-2): i/o error at logical 70138376192 on dev /dev/mapper/zeytin-root, sector 143296856, root 423, inode 100548, offset 688631808, length 4096, links 1 (path: var/log/auth.log)
BTRFS warning (device dm-2): i/o error at logical 70138425344 on dev /dev/mapper/zeytin-root, sector 143296952, root 423, inode 100548, offset 688644096, length 4096, links 1 (path: var/log/auth.log)
BTRFS warning (device dm-2): i/o error at logical 70138441728 on dev /dev/mapper/zeytin-root, sector 143296984, root 423, inode 100548, offset 688648192, length 4096, links 1 (path: var/log/auth.log)
BTRFS warning (device dm-2): i/o error at logical 70138449920 on dev /dev/mapper/zeytin-root, sector 143297000, root 419, inode 818783, offset 95145984, length 4096, links 1 (path: var/log/daemon.log)
BTRFS warning (device dm-2): i/o error at logical 70138564608 on dev /dev/mapper/zeytin-root, sector 143297224, root 419, inode 818783, offset 95154176, length 4096, links 1 (path: var/log/daemon.log)
BTRFS warning (device dm-2): i/o error at logical 70138884096 on dev /dev/mapper/zeytin-root, sector 143297848, root 419, inode 818783, offset 95174656, length 4096, links 1 (path: var/log/daemon.log)

sector XXXXXXX, root XXX, inode XXXXXXX, offset XXXXXXXX값으로 하위 볼륨 경로를 결정하는 방법이 있습니까 ?

답변1

여기의 값 root XXX은 하위 볼륨의 루트 ID입니다. 따라서 해당 하위 볼륨에 대한 경로는 다음과 같은 방법으로 결정될 수 있습니다.

sudo btrfs sub list / | awk '$2 == 419 {print $9}'
var/lib/lxc/foo/rootfs

내부 조인을 수행하는 데 유용한 스크립트는 다음과 같습니다.

#!/bin/bash

sub_list=/tmp/subvolume-list-of-root.txt

sudo btrfs sub list / > $sub_list

while read a; do
    root_id=$(echo $a | awk '{print $16}' | sed -r 's/,//')
    rel_path=$(echo $a | sed -r 's/.*path:\s(.+)\)/\1/g')
    subvol_path=$(cat $sub_list | awk '$2 == '"$root_id"' {print $9}')
    [[ -z $subvol_path ]] && subvol_path="????"
    echo "/$subvol_path/$rel_path"
done < <( cat << HELLO
BTRFS warning (device dm-2): i/o error at logical 69945753600 on dev /dev/mapper/zeytin-root, sector 142920640, root 636, inode 172280, offset 238682112, length 4096, links 1 (path: home/aea/couchdb/couchdb/data/shards/60000000-7fffffff/client2.1533443496.couch)
BTRFS warning (device dm-2): i/o error at logical 70045958144 on dev /dev/mapper/zeytin-root, sector 143116352, root 422, inode 172296, offset 307662848, length 4096, links 1 (path: home/aea/couchdb/couchdb/data/shards/e0000000-ffffffff/client2.1533443496.couch)
BTRFS warning (device dm-2): i/o error at logical 70045958144 on dev /dev/mapper/zeytin-root, sector 143116352, root 636, inode 172296, offset 307662848, length 4096, links 1 (path: home/aea/couchdb/couchdb/data/shards/e0000000-ffffffff/client2.1533443496.couch)
BTRFS warning (device dm-2): i/o error at logical 70138376192 on dev /dev/mapper/zeytin-root, sector 143296856, root 423, inode 100548, offset 688631808, length 4096, links 1 (path: var/log/auth.log)
BTRFS warning (device dm-2): i/o error at logical 70138425344 on dev /dev/mapper/zeytin-root, sector 143296952, root 423, inode 100548, offset 688644096, length 4096, links 1 (path: var/log/auth.log)
BTRFS warning (device dm-2): i/o error at logical 70138441728 on dev /dev/mapper/zeytin-root, sector 143296984, root 423, inode 100548, offset 688648192, length 4096, links 1 (path: var/log/auth.log)
BTRFS warning (device dm-2): i/o error at logical 70138449920 on dev /dev/mapper/zeytin-root, sector 143297000, root 419, inode 818783, offset 95145984, length 4096, links 1 (path: var/log/daemon.log)
BTRFS warning (device dm-2): i/o error at logical 70138564608 on dev /dev/mapper/zeytin-root, sector 143297224, root 419, inode 818783, offset 95154176, length 4096, links 1 (path: var/log/daemon.log)
BTRFS warning (device dm-2): i/o error at logical 70138884096 on dev /dev/mapper/zeytin-root, sector 143297848, root 419, inode 818783, offset 95174656, length 4096, links 1 (path: var/log/daemon.log)
HELLO
)

산출:

./test.sh 

/????/home/aea/couchdb/couchdb/data/shards/60000000-7fffffff/client2.1533443496.couch
/var/lib/lxc/foo-couch2/rootfs/home/aea/couchdb/couchdb/data/shards/e0000000-ffffffff/client2.1533443496.couch
/????/home/aea/couchdb/couchdb/data/shards/e0000000-ffffffff/client2.1533443496.couch
/var/lib/lxc/foo-git/rootfs/var/log/auth.log
/var/lib/lxc/foo-git/rootfs/var/log/auth.log
/var/lib/lxc/foo-git/rootfs/var/log/auth.log
/var/lib/lxc/foo1/rootfs.bak/var/log/daemon.log
/var/lib/lxc/foo1/rootfs.bak/var/log/daemon.log
/var/lib/lxc/foo1/rootfs.bak/var/log/daemon.log

따라서 전반적인 도구는손상된 file.sh 받기이 되다:

#!/bin/bash

sub_list=/tmp/subvolume-list-of-root.txt

sudo btrfs sub list / > $sub_list

while read a; do
    root_id=$(echo $a | awk '{print $16}' | sed -r 's/,//')
    rel_path=$(echo $a | sed -r 's/.*path:\s(.+)\)/\1/g')
    subvol_path=$(cat $sub_list | awk '$2 == '"$root_id"' {print $9}')
    [[ -z $subvol_path ]] && subvol_path="????"
    echo "/$subvol_path/$rel_path"
done < <( sudo journalctl --output cat | grep 'BTRFS .* i/o error' | sort | uniq )

관련 정보