diff options
author | Andrew Cady <d@jerkface.net> | 2023-05-21 21:14:55 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2023-05-21 21:14:55 -0400 |
commit | 021338e619b2cb6a07dc07a600c95c08e8c2de29 (patch) | |
tree | 8eacef86fdf62e1e20fa99ab071b1b3b1b25ae2e | |
parent | 264a3f9f300844ba8e33cdefb890a2794e4bca7d (diff) |
use "ssh localhost" to access local system; support ssh to other systems
-rwxr-xr-x | go.sh | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -38,6 +38,11 @@ get_age() | |||
38 | echo $((now - then)) | 38 | echo $((now - then)) |
39 | } | 39 | } |
40 | 40 | ||
41 | btrfs_receive() | ||
42 | { | ||
43 | ssh -- "${1%%:*}" btrfs receive -- "${1#*:}" | ||
44 | } | ||
45 | |||
41 | set -e | 46 | set -e |
42 | check_dependencies | 47 | check_dependencies |
43 | check_user_is_root | 48 | check_user_is_root |
@@ -67,6 +72,12 @@ src=${config[source]} | |||
67 | dst=${config[destination]} | 72 | dst=${config[destination]} |
68 | remote_head=${config[head]} | 73 | remote_head=${config[head]} |
69 | 74 | ||
75 | case "$dst" in | ||
76 | *:/*) ;; | ||
77 | /*) dst=localhost:$dst ;; | ||
78 | *) die "Invalid destination: $dst" ;; | ||
79 | esac | ||
80 | |||
70 | is_subvolume "$src" | 81 | is_subvolume "$src" |
71 | 82 | ||
72 | if [ "$(get_age "$remote_head")" -le "$MAX_AGE_SECONDS" ] | 83 | if [ "$(get_age "$remote_head")" -le "$MAX_AGE_SECONDS" ] |
@@ -78,7 +89,7 @@ else | |||
78 | btrfs subvolume snapshot -r -- "$src" "$new_snapshot" | 89 | btrfs subvolume snapshot -r -- "$src" "$new_snapshot" |
79 | fi | 90 | fi |
80 | 91 | ||
81 | btrfs send ${remote_head:+ -p "$remote_head"} -- "$new_snapshot" | pv | btrfs receive -- "$dst" | 92 | 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" | 93 | jq --arg h "$new_snapshot" '. | .head=$h' <"$config_file" >"$config_file_temp" |
83 | mv -T -- "$config_file_temp" "$config_file" | 94 | mv -T -- "$config_file_temp" "$config_file" |
84 | 95 | ||