summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2023-06-05 17:08:28 -0400
committerAndrew Cady <d@jerkface.net>2023-06-05 17:08:35 -0400
commita31a32263d2c11afa07b93501d5066a53a9ca17c (patch)
tree3f300e47cc6ddcca41dedb1b376d4afe29895ec5
parent329db17935912541b98e6f8bbcb2a0bb162cc190 (diff)
squash groups of our snapshots into globs in list-all-subvolumes output
-rwxr-xr-xlist-all-subvolumes36
1 files changed, 33 insertions, 3 deletions
diff --git a/list-all-subvolumes b/list-all-subvolumes
index 89ffc15..7bc44d2 100755
--- a/list-all-subvolumes
+++ b/list-all-subvolumes
@@ -1,6 +1,5 @@
1#!/bin/bash 1#!/bin/bash
2set -e -o pipefail 2set -e -o pipefail
3btrfs_subvolume_list_args=('-sr')
4btrfs_subvolume_list_args=('-a' "$@") 3btrfs_subvolume_list_args=('-a' "$@")
5 4
6list_all_subvolumes() 5list_all_subvolumes()
@@ -15,7 +14,15 @@ list_all_subvolumes()
15 set -x 14 set -x
16 mountpoint -q "$d" || mount -o ro,subvol=/ "$dev" "$d" || return 15 mountpoint -q "$d" || mount -o ro,subvol=/ "$dev" "$d" || return
17 btrfs subvolume list "$@" "$d" 16 btrfs subvolume list "$@" "$d"
18 ) || return 17 ) | extract_subvolume_path "${d##*/}" || return
18 done
19}
20
21extract_subvolume_path()
22{
23 while read _ id _ gen _ _ toplevel _ path
24 do
25 printf '%s/%s\n' "$1" "${path#<FS_TREE>/}"
19 done 26 done
20} 27}
21 28
@@ -27,4 +34,27 @@ list_btrfs()
27 done | sort -u 34 done | sort -u
28} 35}
29 36
30list_all_subvolumes "${btrfs_subvolume_list_args[@]}" 37datetime_glob_a=.snapshot~[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9],[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9]:[0-9][0-9]
38
39datetime_glob_b=*_mirror.[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]_[0-9][0-9]:[0-9][0-9]:[0-9][0-9],[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9]:[0-9][0-9]
40
41squash_snapshots()
42{
43 while read line
44 do
45 if [[ $line == */$datetime_glob_a ]] || [[ $line == $datetime_glob_b ]]
46 then
47 echo "${line%.*}.*"
48 else
49 echo "$line"
50 fi
51 done | sort -u
52}
53
54#SQUASH_SNAPSHOTS=y
55if [ "$SQUASH_SNAPSHOTS" ]
56then
57 list_all_subvolumes "${btrfs_subvolume_list_args[@]}" | sort -u | squash_snapshots
58else
59 list_all_subvolumes "${btrfs_subvolume_list_args[@]}"
60fi