如何识别系统上不再需要的快照?

如何识别系统上不再需要的快照?

操作系统:Ubuntu 20.04

以下是snap list新安装的 Ubuntu 20.04 的输出:

$ snap list
Name                             Version             Rev   Tracking         Publisher   Notes
core18                           20200311            1705  latest/stable    canonical✓  base
gnome-3-34-1804                  0+git.2c86692       27    latest/stable/…  canonical✓  -
gtk-common-themes                0.1-36-gc75f853     1506  latest/stable/…  canonical✓  -
snap-store                       3.36.0-74-ga164ec9  433   latest/stable/…  canonical✓  -
snapd                            2.44.3              7264  latest/stable    canonical✓  snapd
$

这是我安装各种快照(并删除一些)后看到的:

$ snap list
Name                             Version                     Rev   Tracking         Publisher   Notes
core                             16-2.44.3                   9066  latest/stable    canonical✔  core
core18 •                         20200427                    1754  latest/stable    canonical✔  base
firefox *                        77.0b2-1                    358   latest/beta      mozilla✔    -
gnome-3-28-1804                  3.28.0-16-g27c9498.27c9498  116   latest/stable    canonical✔  -
gnome-3-34-1804 •                0+git.2c86692               27    latest/stable/…  canonical✔  -
gnome-system-monitor *           3.32.0-27-g32ed970e06       135   latest/stable    canonical✔  -
gtk-common-themes •              0.1-36-gc75f853             1506  latest/stable/…  canonical✔  -
kanagram *                       20.04.0                     51    latest/stable    kde✔        -
kcolorchooser *                  20.04.0                     57    latest/stable    kde✔        -
kde-frameworks-5                 5.47.0                      27    latest/stable    kde✔        -
kde-frameworks-5-core18          5.61.0                      32    latest/stable    kde✔        -
kde-frameworks-5-qt-5-14-core18  5.68.0                      4     latest/stable    kde✔        -
kolourpaint *                    20.04.0                     56    latest/stable    kde✔        -
ksnip *                          1.7.0                       46    latest/edge      dporobic    -
okular *                         20.04.0                     98    latest/stable    kde✔        -
snap-store •                     3.36.0-74-ga164ec9          433   latest/stable/…  canonical✔  -
snapd •                          2.44.3                      7264  latest/stable    canonical✔  snapd
$

为了便于讨论,我们称之为

  • 五个原始快照(名称旁边标有)“系统快照”
  • 我的快照明知已安装(*名称旁边标有)“主要快照”
  • 另一个是“支持按扣”
    • 侏儒-3-28-1804
    • kde-框架-5
    • kde-框架-5-core18
    • kde-框架-5-qt-5-14-core18

鉴于系统存储了一个快照和至少两个修订版本,并且一些支持快照可能有几百 MB(ls -lh /var/lib/snapd/snaps),如果主快照已被删除,那么了解可以删除哪些辅助快照是很有价值。

但是,如何将支持快照“映射”到主要快照呢?

就我而言,我可以运行snap connections okularintuit,它kde-frameworks-5-qt-5-14-core18是作为 的结果而安装的sudo snap install okular

snap connections …只有在相关 snap 仍安装的情况下才有效。我安装了,但后来删除了,,,,,和的falkon稳定版本。featherpadkcalckonversationpalapeliksnip

/var/log/dpkg.log是否有与安装和删除类似或的快照相关的日志文件/var/log/apt/history.log

如果不是,那么如何才能知道是否仍然需要“支持”快照?


这里有一个相关但尚未解答的问题是:如何列出手动安装的快照并删除不再需要的自动安装的快照?

答案1

检查snap.yaml所有已安装的 snap 包的文件可以帮助我们了解需要哪些“支持”的 snap 包:

例子:

~$ grep "default-provider:" /snap/*/*/meta/snap.yaml
/snap/snap-store/415/meta/snap.yaml:    default-provider: gnome-3-28-1804
/snap/snap-store/415/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/snap-store/415/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/snap-store/415/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/snap-store/current/meta/snap.yaml:    default-provider: gnome-3-28-1804
/snap/snap-store/current/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/snap-store/current/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/snap-store/current/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/wire/132/meta/snap.yaml:    default-provider: gnome-3-28-1804
/snap/wire/132/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/wire/132/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/wire/132/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/wire/current/meta/snap.yaml:    default-provider: gnome-3-28-1804
/snap/wire/current/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/wire/current/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/wire/current/meta/snap.yaml:    default-provider: gtk-common-themes
~$ grep "base:" /snap/*/*/meta/snap.yaml
/snap/gnome-3-28-1804/116/meta/snap.yaml:base: core18
/snap/gnome-3-28-1804/current/meta/snap.yaml:base: core18
/snap/gtk-common-themes/1506/meta/snap.yaml:base: core18
/snap/gtk-common-themes/current/meta/snap.yaml:base: core18
/snap/snap-store/415/meta/snap.yaml:base: core18
/snap/snap-store/current/meta/snap.yaml:base: core18
/snap/wire/132/meta/snap.yaml:base: core18
/snap/wire/current/meta/snap.yaml:base: core18

如果已安装的 snap 没有出现在输出的右侧,则表示没有其他 snap 依赖它,并且可以删除此 snap。当然,您手动安装的 snap 不会出现在输出的右侧,通常没有其他 snap 依赖它们,这些是您想要保留的 snap。


snap.yaml如果我们仅检查 snap 文件的当前活动修订版本,我们可以使输出更短一些:

grep "default-provider:" /snap/*/current/meta/snap.yaml
grep "base:" /snap/*/current/meta/snap.yaml

安装第一个 snap 包后,会立即安装一个名为 的 snap 包snapdsnapd上述命令提供的列表中未引用该 snap 包。根据https://snapcraft.io/snapd需要此 snap 来安装、配置、刷新和删除 snap 包。只要您安装了任何 snap,就无法删除此 snap:

~$ snap remove snapd
error: cannot remove "snapd": snap "snapd" is not removable: remove all other snaps first

答案2

snap connections

显示哪个 snap 正在使用哪个或针对一个应用程序,例如:

$  snap connections snap-store
Schnittstelle             Plug                                      Slot                             Notizen
appstream-metadata        snap-store:appstream-metadata             :appstream-metadata              -
content[gnome-3-38-2004]  snap-store:gnome-3-38-2004                gnome-3-38-2004:gnome-3-38-2004  -
content[gtk-3-themes]     snap-store:gtk-3-themes                   gtk-common-themes:gtk-3-themes   -
content[icon-themes]      snap-store:icon-themes                    gtk-common-themes:icon-themes    -
content[sound-themes]     snap-store:sound-themes                   gtk-common-themes:sound-themes   -
dbus                      -                                         snap-store:packagekit-svc        -
dbus                      -                                         snap-store:snap-store            -
desktop                   snap-store:desktop                        :desktop                         -
desktop-legacy            snap-store:desktop-legacy                 :desktop-legacy                  -
fwupd                     snap-store:fwupd                          :fwupd                           -
gsettings                 snap-store:gsettings                      :gsettings                       -
network                   snap-store:network                        :network                         -
network-manager           snap-store:network-manager                -                                -
network-status            snap-store:network-status                 :network-status                  -
opengl                    snap-store:opengl                         :opengl                          -
packagekit-control        snap-store:packagekit-control             :packagekit-control              -
password-manager-service  snap-store:password-manager-service       :password-manager-service        -
personal-files            snap-store:dot-snap-auth-json             -                                -
snapd-control             snap-store:snapd-control                  :snapd-control                   -
system-files              snap-store:hostfs-usr-share-applications  :system-files                    -
system-observe            snap-store:system-observe                 :system-observe                  -
upower-observe            snap-store:upower-observe                 :upower-observe                  -
wayland                   snap-store:wayland                        :wayland                         -
x11                       snap-store:x11                            :x11                             -

答案3

从其他答案改进的这两个命令可能会有所帮助:

snap list --all | awk '/-/{print $1}'

grep "default-provider:\|base:" /snap/*/current/meta/snap.yaml | awk '{print $NF}'

这些列出了非核心和非基本 snap,并列出了当前使用的 snap。可以使用脚本或一行代码来比较两者,但手动安装的 snap(如 Chromium)仍然会出现,而且我找不到像使用 Apt 那样排除它们的方法。snap list --help没有这些信息。也许另一个文件有。

相关内容