如何删除 btrfs 子卷以他们的名义

如何删除 btrfs 子卷以他们的名义

我有一堆 btrfs 快照,如下所示:

20:17:37 [root@galaxy /]$ btrfs subvolume list -a / |grep apt
ID 271 gen 348 top level 5 path <FS_TREE>/@apt-snapshot-2013-04-17_21:44:30
ID 272 gen 352 top level 5 path <FS_TREE>/@apt-snapshot-2013-04-17_21:46:25
ID 273 gen 361 top level 5 path <FS_TREE>/@apt-snapshot-2013-04-17_21:51:13
... # lots more

我想摆脱他们。所以我尝试了

20:21:31 [root@galaxy ~]$ btrfs subvolume delete '/<FS_TREE>/@apt-snapshot-2013-04-17_21:44:30'
ERROR: error accessing '/<FS_TREE>/@apt-snapshot-2013-04-17_21:44:30'
20:21:36 [root@galaxy ~]$ btrfs subvolume delete '<FS_TREE>/@apt-snapshot-2013-04-17_21:44:30'
ERROR: error accessing '<FS_TREE>/@apt-snapshot-2013-04-17_21:44:30'
20:21:43 [root@galaxy ~]$ btrfs subvolume delete '/@apt-snapshot-2013-04-17_21:44:30'
ERROR: error accessing '/@apt-snapshot-2013-04-17_21:44:30'
20:21:47 [root@galaxy ~]$ btrfs subvolume delete '@apt-snapshot-2013-04-17_21:44:30'
ERROR: error accessing '@apt-snapshot-2013-04-17_21:44:30'

删除这些快照的正确语法是什么?

答案1

我可以通过首先安装整个 btrfs 卷(而不是@子卷)然后从那里开始工作来删除这些快照:

# mount /dev/mapper/whatever /mnt -o subvol=/
# ls /mnt
@
@apt-snapshot-2013-04-17_21:44:30
...

所以此时,所有子卷(包括时髦的apt-snapshot子卷)在 中都是可见的/mnt,因此我们可以删除它们:

# btrfs subvol delete /mnt/@apt-snapshot-2013-04-17_21:44:30
# umount /mnt

答案2

最简单的方法是使用内置apt-btrfs-snapshot命令:

与普通快照删除不同,删除快照不需要挂载文件系统。

首先,apt-btrfs-snapshot使用以下命令列出可用的快照:

sudo apt-btrfs-snapshot list

以下是该命令的输出示例:

@apt-snapshot-old-root-2015-10-19_20:20:10
@apt-snapshot-2015-10-28_19:00:46
@apt-snapshot-2015-10-28_19:09:14
@apt-snapshot-2015-10-29_04:40:07
@apt-snapshot-2015-10-29_06:35:57
@apt-snapshot-2015-10-29_07:03:39
@apt-snapshot-2015-10-30_03:49:05
@apt-snapshot-2015-10-30_17:53:59

要删除快照@apt-snapshot-2015-10-30_17:53:59,请运行:

sudo apt-btrfs-snapshot delete @apt-snapshot-2015-10-30_17:53:59

您还可以按日期删除多个快照。这是删除命令的示例全部超过 0 天的快照。

sudo apt-btrfs-snapshot delete-older-than 0d   

以下是该命令的输出示例:

Delete subvolume (no-commit): '/tmp/apt-btrfs-snapshot-mp-odfe0o4g/@apt-snapshot-old-root-2015-10-19_20:20:10'
ERROR: cannot delete '/tmp/apt-btrfs-snapshot-mp-odfe0o4g/@apt-snapshot-old-root-2015-10-19_20:20:10' - Directory not empty
Delete subvolume (no-commit): '/tmp/apt-btrfs-snapshot-mp-b2zv18qr/@apt-snapshot-2015-10-28_19:00:46'
Delete subvolume (no-commit): '/tmp/apt-btrfs-snapshot-mp-zjglvefe/@apt-snapshot-2015-10-28_19:09:14'
Delete subvolume (no-commit): '/tmp/apt-btrfs-snapshot-mp-lj3v74qa/@apt-snapshot-2015-10-29_04:40:07'
Delete subvolume (no-commit): '/tmp/apt-btrfs-snapshot-mp-vztc82zr/@apt-snapshot-2015-10-29_06:35:57'
Delete subvolume (no-commit): '/tmp/apt-btrfs-snapshot-mp-q0ou8e24/@apt-snapshot-2015-10-29_07:03:39'
Delete subvolume (no-commit): '/tmp/apt-btrfs-snapshot-mp-dw8eq0vv/@apt-snapshot-2015-10-30_03:49:05'
Delete subvolume (no-commit): '/tmp/apt-btrfs-snapshot-mp-vgo2yuf2/@apt-snapshot-2015-10-30_17:53:59'

如您所见,可用快照已被删除。然而,最旧的快照“old-root”并未被删除,即使它早于 0 天,仍然可以用于回滚。

运行以下命令以获得完整的功能列表:

apt-btrfs-snapshot --help

相关内容