diff options
author | Andrew Cady <d@jerkface.net> | 2023-05-21 20:39:58 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2023-05-21 20:39:58 -0400 |
commit | 264a3f9f300844ba8e33cdefb890a2794e4bca7d (patch) | |
tree | 9124d79013b3b9f06ced9767da3660dc85fa33cd | |
parent | 32d0a60024f0549f85250f565f126a6ffa39c11b (diff) |
do not use local head file
simply use a different head snapshot for each remote
if there aren't many remotes, it is a premature optimization
-rwxr-xr-x | go.sh | 33 |
1 files changed, 8 insertions, 25 deletions
@@ -38,14 +38,6 @@ get_age() | |||
38 | echo $((now - then)) | 38 | echo $((now - then)) |
39 | } | 39 | } |
40 | 40 | ||
41 | remove_old_link() | ||
42 | { | ||
43 | if [ -L "$1" ] && [ "$(get_age "$1")" -gt "$2" ] | ||
44 | then | ||
45 | rm -- "$1" | ||
46 | fi | ||
47 | } | ||
48 | |||
49 | set -e | 41 | set -e |
50 | check_dependencies | 42 | check_dependencies |
51 | check_user_is_root | 43 | check_user_is_root |
@@ -76,34 +68,25 @@ dst=${config[destination]} | |||
76 | remote_head=${config[head]} | 68 | remote_head=${config[head]} |
77 | 69 | ||
78 | is_subvolume "$src" | 70 | is_subvolume "$src" |
79 | local_head_link=${src%/}/.snapshot~HEAD | ||
80 | 71 | ||
81 | remove_old_link "$local_head_link" "$MAX_AGE_SECONDS" | 72 | if [ "$(get_age "$remote_head")" -le "$MAX_AGE_SECONDS" ] |
82 | |||
83 | if [ -e "$local_head_link" ] | ||
84 | then | 73 | then |
85 | local_head=$(realpath -e "$local_head_link") | 74 | echo "Up-to-date." >&2 |
75 | exit | ||
86 | else | 76 | else |
87 | new_snapshot=${src%/}/.snapshot~$(date -Ins) | 77 | new_snapshot=${src%/}/.snapshot~$(date -Ins) |
88 | btrfs subvolume snapshot -r -- "$src" "$new_snapshot" | 78 | btrfs subvolume snapshot -r -- "$src" "$new_snapshot" |
89 | # We don't need to create this link at all. | ||
90 | ln -rs -T "$new_snapshot" "$local_head_link" | ||
91 | local_head=$new_snapshot | ||
92 | fi | 79 | fi |
93 | 80 | ||
94 | is_subvolume "$local_head" | 81 | btrfs send ${remote_head:+ -p "$remote_head"} -- "$new_snapshot" | pv | btrfs receive -- "$dst" |
82 | jq --arg h "$new_snapshot" '. | .head=$h' <"$config_file" >"$config_file_temp" | ||
83 | mv -T -- "$config_file_temp" "$config_file" | ||
95 | 84 | ||
96 | if [ "${local_head##*/}" = "${remote_head##*/}" ] | 85 | if [ "$remote_head" ] |
97 | then | 86 | then |
98 | echo "Up-to-date." >&2 | 87 | btrfs subvolume delete "$remote_head" |
99 | exit | ||
100 | fi | 88 | fi |
101 | 89 | ||
102 | btrfs send ${remote_head:+ -p "$remote_head"} -- "$local_head" | pv | btrfs receive -- "$dst" | ||
103 | jq --arg h "$local_head" '. | .head=$h' <"$config_file" >"$config_file_temp" | ||
104 | # TODO: btrfs subvolume delete "$remote_head" but first check for other config files! | ||
105 | mv -T -- "$config_file_temp" "$config_file" | ||
106 | |||
107 | ### OK, basic idea: | 90 | ### OK, basic idea: |
108 | # | 91 | # |
109 | ## the system has a list of source subvolumes | 92 | ## the system has a list of source subvolumes |