19

OpenSUSE (among other distributions) uses snapper to take snapshots of btrfs partitions. Some people think the default snapshot intervals take up too much space too quickly, but whether or not you believe that, there are times when you want to clear space on your filesystem and often find that the btrfs snapshots are taking a significant amount of space. Or, in other cases you may want to clear the filesystem of all excess data before moving it to/from a VM or changing the storage medium or something along those lines.

But, I can't seem to find a command to quickly wipe all of the snapshots snapper has taken, either via snapper or another tool. How would I do this?

5 Answers 5

30

The command in recent versions of snapper is (I don't remember when it was introduced, but the version in e.g., openSUSE 13.2 supports this):

snapper delete number1-number2

So to delete all snapshots (assuming you have no more than 100000 of them) you'd do:

snapper delete 1-100000

Obviously this only deletes snapshots on the default root config, so for a different config it would be:

snapper -c configname delete number1-number2
4
  • I'm now getting an error: Snapshot '100000' not found. Jan 30, 2018 at 17:07
  • 1
    ty, ty, ty. noting, the range operator didn't work, i had to manually delete all 20 snapshots.
    – Paul Vixie
    Jul 28, 2018 at 15:26
  • @PavelŠimerda Look at my answer for a solution to this issue.
    – emk2203
    Apr 17 at 11:06
  • @PaulVixie Look at my answer for a solution to this issue.
    – emk2203
    Apr 17 at 11:06
6

You can use a for loop to delete all snapshots within a range (run as root).

# for i in `seq 1 999`; do snapper delete $i; done

This will hit some invalid entries (when the number doesn't correspond to a snapshot ID), which will result in a harmless error log.

To determine the range (lower and upper limit) of snapshot IDs, so that the loop won't run unnecessarily long, use:

snapper list

I found this solution along with a discussion about how to reduce the snapper interval and retention settings.

0

Oneliner:

sudo snapper -c root delete $(sudo snapper -c root list --columns number | tail +4)
  • sudo snapper -c root list --columns number — list snapshot numbers
  • tail +4 — skip 2 header lines and snapshot with number 0 which is not snapshot it's subvolume
  • sudo snapper -c root delete — delete one or more snapshots. this command takes an unlimited number of arguments
0

In my use case, and probably in some others, the snapshot numbers are not consecutive all the time, a typical output of sudo snapper --no-headers --csvout --config root list --columns number might look like this:

0
4503
4796
5174
5581
5796
5803
5804
5805
5806
5807
5808
5821
5822
5823
5824
5838
5839
5840
5841
5842
5843
5844

I want to keep only the snapshot #0 (current).

The option to remove headers was introduced to snapper in Feb 2023 and isn't in any version lower or equal v0.5.6, if you have the older version, append | tail -n +3 to each snapper command with output for the same effect.

For deletion of these snapshots, a simple bash one-liner does the trick:

for i in $(sudo snapper --no-headers --csvout --config root list --columns number); do sudo snapper -c root delete $i; done

This gets all snapshots removed except for the first. For getting rid of all snapshots from all configs, define the configs in an array and iterate through it as well:

snpcfgs=( $(sudo snapper --no-headers --csvout list-configs --columns config) ); for snpcfg in ${snpcfgs[@]}; do for i in $(sudo snapper --no-headers --csvout -c $snpcfg list --columns number); do sudo snapper -c $snpcfg delete $i; done; done

This takes care of all Snapper snapshots.

-1

If you're working on an older version of snapper like on Debian jessie, you can use bash-expansion:

snapper delete {1..999}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .