summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2023-05-31 16:07:56 -0400
committerAndrew Cady <d@jerkface.net>2023-05-31 16:09:08 -0400
commit6bf15b49a77237a549be136b5aa29daaa69cc2f4 (patch)
treed8af4d9214fcf773f8644c2866e6a7888a61d0f7
parent817c33cb02a5c5f25b4a77e746d09e3fd6c0455b (diff)
push-btrfs-scan: remove timer and conf file for blacklisted subvolumes
-rwxr-xr-xsrc/push-btrfs-scan (renamed from src/btrfs-scan)51
1 files changed, 42 insertions, 9 deletions
diff --git a/src/btrfs-scan b/src/push-btrfs-scan
index 9213dfc..bc97d00 100755
--- a/src/btrfs-scan
+++ b/src/push-btrfs-scan
@@ -38,33 +38,66 @@ is_our_snapshot()
38 esac 38 esac
39} 39}
40 40
41filter_blacklist() 41filter_readonly()
42{
43 if btrfs subvolume show -r "$id" / | sed -Ene '/^\tFlags:.*\breadonly\b/{p;q1}' -e '$q'
44 then
45 if [ -e "$conf_name" ]
46 then
47 printf '%20s %s\n' delete "$conf_name" >&2
48 fi
49 printf '%20s %s\n' '(snapshot) lose' "$path_fixed" >&2
50 return
51 fi
52 "$@"
53}
54
55filter_snapshot_filename()
42{ 56{
43 if is_our_snapshot "$path_fixed" 57 if is_our_snapshot "$path_fixed"
44 then 58 then
45 if [ -e "$conf_name" ] 59 if [ -e "$conf_name" ]
46 then 60 then
47 printf '%20s %s\n' delete "$conf_name" >&2 61 printf '%20s %s\n' delete "$conf_name" >&2
48 printf '%20s %s\n' '(snapshot) lose' "$path_fixed" >&2
49 fi 62 fi
63 printf '%20s %s\n' '(snapshot) lose' "$path_fixed" >&2
50 return 64 return
65 fi
66 "$@"
67}
51 68
52 # Re-reading the blacklist file once per snapshot is not ideal, 69systemctl_disable_quiet()
53 # but is fine. 70{
54 elif [ "$blacklist" -a -f "$blacklist" ] 71 ! systemctl is-enabled "$@" 2>/dev/null || systemctl disable "$@"
72}
73
74timer_prefix=/etc/systemd/system/default.target.wants/push-btrfs@borges
75unset blacklist_patterns
76declare -a blacklist_patterns
77filter_blacklist()
78{
79 if [ "$blacklist" -a -f "$blacklist" ]
55 then 80 then
56 while read pattern 81 if ! [ -v blacklist_patterns ]
82 then
83 readarray -t blacklist_patterns < "$blacklist"
84 fi
85
86 for pattern in "${blacklist_patterns[@]}"
57 do 87 do
58 if [[ $path_fixed == $pattern ]] 88 if [[ $path_fixed == $pattern ]]
59 then 89 then
90 printf '%20s %s\n' '(blacklist) lose' "$path_fixed" >&2
60 if [ -e "$conf_name" ] 91 if [ -e "$conf_name" ]
61 then 92 then
62 printf '%20s %s\n' delete "$conf_name" >&2 93 printf '%20s %s\n' delete "$conf_name" >&2
94 rm "$conf_name"
63 fi 95 fi
64 printf '%20s %s\n' '(blacklist) lose' "$path_fixed" >&2 96 timer=$destination_host$(systemd-escape "$path_fixed").timer
97 systemctl_disable_quiet "$timer"
65 return 98 return
66 fi 99 fi
67 done < "$blacklist" 100 done
68 fi 101 fi
69 "$@" 102 "$@"
70} 103}
@@ -155,4 +188,4 @@ esac
155 188
156ssh root@"$destination_host" true || read -p 'Could not log in. Continue? ' 189ssh root@"$destination_host" true || read -p 'Could not log in. Continue? '
157 190
158with_subvolumes fixup_path compute_paths filter_blacklist mirror 191with_subvolumes fixup_path compute_paths filter_snapshot_filename filter_blacklist mirror