仅保留最新版本的快照并删除其他版本以释放空间

仅保留最新版本的快照并删除其他版本以释放空间

我可以仅保留以下快照的最新版本并删除其他快照以释放空间吗?我正在使用 Ubuntu 18.04.5 LTS。谢谢

wakatana@ubuntu:~$ snap list
Name                  Version                     Rev   Tracking         Publisher   Notes
core                  16-2.46.1                   9993  latest/stable    canonical✓  core
core18                20200724                    1885  latest/stable    canonical✓  base
gnome-3-26-1604       3.26.0.20200529             100   latest/stable/…  canonical✓  -
gnome-3-28-1804       3.28.0-17-gde3d74c.de3d74c  128   latest/stable    canonical✓  -
gnome-3-34-1804       0+git.3556cb3               60    latest/stable    canonical✓  -
gnome-characters      v3.34.0+git9.eeab5f2        570   latest/stable/…  canonical✓  -
gnome-logs            3.34.0                      100   latest/stable/…  canonical✓  -
gnome-system-monitor  3.36.0-12-g35f88a56d7       148   latest/stable/…  canonical✓  -
gtk-common-themes     0.1-36-gc75f853             1506  latest/stable/…  canonical✓  -

wakatana@ubuntu:~$ du -hcs /var/lib/snapd/snaps/* | sort -h
4.0K    /var/lib/snapd/snaps/partial
276K    /var/lib/snapd/snaps/gnome-characters_550.snap
276K    /var/lib/snapd/snaps/gnome-characters_570.snap
956K    /var/lib/snapd/snaps/gnome-logs_100.snap
956K    /var/lib/snapd/snaps/gnome-logs_93.snap
2.2M    /var/lib/snapd/snaps/gnome-system-monitor_145.snap
2.2M    /var/lib/snapd/snaps/gnome-system-monitor_148.snap
55M     /var/lib/snapd/snaps/core18_1880.snap
55M     /var/lib/snapd/snaps/gtk-common-themes_1502.snap
56M     /var/lib/snapd/snaps/core18_1885.snap
63M     /var/lib/snapd/snaps/gtk-common-themes_1506.snap
97M     /var/lib/snapd/snaps/core_9804.snap
98M     /var/lib/snapd/snaps/core_9993.snap
141M    /var/lib/snapd/snaps/gnome-3-26-1604_100.snap
141M    /var/lib/snapd/snaps/gnome-3-26-1604_98.snap
161M    /var/lib/snapd/snaps/gnome-3-28-1804_116.snap
162M    /var/lib/snapd/snaps/gnome-3-28-1804_128.snap
218M    /var/lib/snapd/snaps/gnome-3-34-1804_60.snap
256M    /var/lib/snapd/snaps/gnome-3-34-1804_36.snap
1.5G    total

答案1

解决方案1 ​​-

$ snap set system refresh.retain=N

其中 N 不能小于 2。
参考 - https://forum.snapcraft.io/t/configure-number-of-old-revisions-to-keep/2337/7

解决方案2-

以下脚本删除所有禁用的快照。
升级到新版本后,旧版本将被禁用。

#!/bin/bash
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
set -eu

LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
    while read snapname revision; do
        snap remove "$snapname" --revision="$revision"
    done

参考 -https://www.linuxuprising.com/2019/04/how-to-remove-old-snap-versions-to-free.html

相关内容