diff options
author | Andrew Cady <d@jerkface.net> | 2023-05-24 11:35:12 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2023-05-24 11:35:12 -0400 |
commit | a002492cc53c77e0435e957f86aa546f4ce2d1b0 (patch) | |
tree | c6f3bab842222f33f4ca1c6ab9eefe57b60011c6 | |
parent | cf930327a1b78f3168aae700d7867af77fad5905 (diff) |
rename
-rwxr-xr-x | retention.bash | 71 | ||||
-rwxr-xr-x | src/retain-snapshots (renamed from retain-snapshots) | 0 |
2 files changed, 0 insertions, 71 deletions
diff --git a/retention.bash b/retention.bash deleted file mode 100755 index 149bc7a..0000000 --- a/retention.bash +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | datetime_regexp='[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]' | ||
4 | |||
5 | main() | ||
6 | { | ||
7 | [ $# = 1 ] || exit | ||
8 | case "$1" in | ||
9 | /*) ;; | ||
10 | *) exit 1 ;; | ||
11 | esac | ||
12 | |||
13 | find "$1" -maxdepth 1 -type d -name '.snapshot~'"$datetime_regexp" | sort -n | retain | ||
14 | } | ||
15 | |||
16 | is_readonly_subvolume() | ||
17 | { | ||
18 | return 0 | ||
19 | btrfs subvolume show -- "$1" | egrep -q '^ Flags:.*\breadonly\b' | ||
20 | } | ||
21 | |||
22 | retain() | ||
23 | { | ||
24 | _year= _month= _day= _hour= _minute= _second= _nanosecond= | ||
25 | now=$(date +%s) | ||
26 | while read line | ||
27 | do | ||
28 | dateline=${line#*/.snapshot~} | ||
29 | before=$(date -d "$dateline" +%s) | ||
30 | age=$((now - before)) | ||
31 | |||
32 | IFS='~-T:,' read year month day hour minute second nanosecond <<< "$dateline" | ||
33 | |||
34 | keep= | ||
35 | if [ "$year" != "$_year" ] | ||
36 | then | ||
37 | keep="$year -> $line" | ||
38 | elif [ "$month" != "$_month" ] && [ "$age" -lt $((365 * 24 * 60 * 60)) ] | ||
39 | then | ||
40 | keep="$year-$month -> $line" | ||
41 | elif [ "$day" != "$_day" ] && [ "$age" -lt $((7 * 24 * 60 * 60)) ] | ||
42 | then | ||
43 | keep="$year-$month-$day -> $line" | ||
44 | elif [ "$hour" != "$_hour" ] && [ "$age" -lt $((24 * 60 * 60)) ] | ||
45 | then | ||
46 | keep="$year-$month-${day}T$hour -> $line" | ||
47 | elif [ "$minute" != "$_minute" ] && [ "$age" -lt $((60 * 60)) ] | ||
48 | then | ||
49 | keep="$year-$month-${day}T$hour:$minute -> $line" | ||
50 | elif [ "$age" -lt 60 ] | ||
51 | then | ||
52 | keep="recent -> $line" | ||
53 | fi | ||
54 | |||
55 | if [ "$keep" ] | ||
56 | then | ||
57 | echo "$keep" >&2 | ||
58 | else | ||
59 | btrfs subvolume delete "$line" | ||
60 | fi | ||
61 | |||
62 | _year=$year | ||
63 | _month=$month | ||
64 | _day=$day | ||
65 | _hour=$hour | ||
66 | _minute=$minute | ||
67 | _second=$second | ||
68 | done | ||
69 | } | ||
70 | |||
71 | main "$@" | ||
diff --git a/retain-snapshots b/src/retain-snapshots index 86f0120..86f0120 100755 --- a/retain-snapshots +++ b/src/retain-snapshots | |||