运行后btrfs scrub
可以检测到损坏的文件。为了确定不可纠正的文件,我们可以尝试读取磁盘上的每个文件:
sudo find / -type f -exec cp -v {} /dev/null \; 2> corrupted-files.txt
该命令的输出满足需要。然而,需要几个小时才能完成。
Arch Linux wiki 建议使用以下命令来确定损坏的文件:
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
因此整体工具获取损坏的文件.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 )