summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2023-05-21 20:39:58 -0400
committerAndrew Cady <d@jerkface.net>2023-05-21 20:39:58 -0400
commit264a3f9f300844ba8e33cdefb890a2794e4bca7d (patch)
tree9124d79013b3b9f06ced9767da3660dc85fa33cd
parent32d0a60024f0549f85250f565f126a6ffa39c11b (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-xgo.sh33
1 files changed, 8 insertions, 25 deletions
diff --git a/go.sh b/go.sh
index 65aa592..7487dfa 100755
--- a/go.sh
+++ b/go.sh
@@ -38,14 +38,6 @@ get_age()
38 echo $((now - then)) 38 echo $((now - then))
39} 39}
40 40
41remove_old_link()
42{
43 if [ -L "$1" ] && [ "$(get_age "$1")" -gt "$2" ]
44 then
45 rm -- "$1"
46 fi
47}
48
49set -e 41set -e
50check_dependencies 42check_dependencies
51check_user_is_root 43check_user_is_root
@@ -76,34 +68,25 @@ dst=${config[destination]}
76remote_head=${config[head]} 68remote_head=${config[head]}
77 69
78is_subvolume "$src" 70is_subvolume "$src"
79local_head_link=${src%/}/.snapshot~HEAD
80 71
81remove_old_link "$local_head_link" "$MAX_AGE_SECONDS" 72if [ "$(get_age "$remote_head")" -le "$MAX_AGE_SECONDS" ]
82
83if [ -e "$local_head_link" ]
84then 73then
85 local_head=$(realpath -e "$local_head_link") 74 echo "Up-to-date." >&2
75 exit
86else 76else
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
92fi 79fi
93 80
94is_subvolume "$local_head" 81btrfs send ${remote_head:+ -p "$remote_head"} -- "$new_snapshot" | pv | btrfs receive -- "$dst"
82jq --arg h "$new_snapshot" '. | .head=$h' <"$config_file" >"$config_file_temp"
83mv -T -- "$config_file_temp" "$config_file"
95 84
96if [ "${local_head##*/}" = "${remote_head##*/}" ] 85if [ "$remote_head" ]
97then 86then
98 echo "Up-to-date." >&2 87 btrfs subvolume delete "$remote_head"
99 exit
100fi 88fi
101 89
102btrfs send ${remote_head:+ -p "$remote_head"} -- "$local_head" | pv | btrfs receive -- "$dst"
103jq --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!
105mv -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