diff options
-rwxr-xr-x | src/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 | ||
41 | filter_blacklist() | 41 | filter_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 | |||
55 | filter_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, | 69 | systemctl_disable_quiet() |
53 | # but is fine. | 70 | { |
54 | elif [ "$blacklist" -a -f "$blacklist" ] | 71 | ! systemctl is-enabled "$@" 2>/dev/null || systemctl disable "$@" |
72 | } | ||
73 | |||
74 | timer_prefix=/etc/systemd/system/default.target.wants/push-btrfs@borges | ||
75 | unset blacklist_patterns | ||
76 | declare -a blacklist_patterns | ||
77 | filter_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 | ||
156 | ssh root@"$destination_host" true || read -p 'Could not log in. Continue? ' | 189 | ssh root@"$destination_host" true || read -p 'Could not log in. Continue? ' |
157 | 190 | ||
158 | with_subvolumes fixup_path compute_paths filter_blacklist mirror | 191 | with_subvolumes fixup_path compute_paths filter_snapshot_filename filter_blacklist mirror |