summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2016-04-17 03:50:49 +0200
committertv <tv@krebsco.de>2016-04-17 03:50:49 +0200
commit904d037bd704d9690b8a9a8e8338950931e3ccd1 (patch)
tree62807d267c7067fba847e698069b07a56e75028f
parente4422212d4e40189ee23ede2b404006039035bc8 (diff)
krebs.backup: allow injecting variables into dst shell
-rw-r--r--krebs/3modules/backup.nix24
1 files changed, 11 insertions, 13 deletions
diff --git a/krebs/3modules/backup.nix b/krebs/3modules/backup.nix
index d22dd3810..1cd851a4e 100644
--- a/krebs/3modules/backup.nix
+++ b/krebs/3modules/backup.nix
@@ -103,7 +103,8 @@ let
plan.method == method &&
config.krebs.build.host.name == plan.${side}.host.name;
- start = plan: pkgs.writeDash "backup.${plan.name}" ''
+ start = plan: pkgs.writeScript "backup.${plan.name}" ''
+ #! ${pkgs.bash}/bin/bash
set -efu
${getAttr plan.method {
push = ''
@@ -116,12 +117,12 @@ let
dst_path=${shell.escape plan.dst.path}
dst=$dst_user@$dst_host:$dst_path
echo "update snapshot: current; $src -> $dst" >&2
- dst_shell() {
+ dst_exec() {
exec ssh -F /dev/null \
-i "$identity" \
''${dst_port:+-p $dst_port} \
"$dst_user@$dst_host" \
- -T "$with_dst_path_lock_script"
+ -T "exec$(printf ' %q' "$@")"
}
rsh="ssh -F /dev/null -i $identity ''${dst_port:+-p $dst_port}"
local_rsync() {
@@ -142,8 +143,8 @@ let
dst_path=${shell.escape plan.dst.path}
dst=$dst_path
echo "update snapshot: current; $dst <- $src" >&2
- dst_shell() {
- eval "$with_dst_path_lock_script"
+ dst_exec() {
+ exec "$@"
}
rsh="ssh -F /dev/null -i $identity ''${src_port:+-p $src_port}"
local_rsync() {
@@ -153,13 +154,7 @@ let
remote_rsync=rsync
'';
}}
- # Note that this only works because we trust date +%s to produce output
- # that doesn't need quoting when used to generate a command string.
- # TODO relax this requirement by selectively allowing to inject variables
- # e.g.: ''${shell.quote "exec env NOW=''${shell.unquote "$NOW"} ..."}
- with_dst_path_lock_script="exec env start_date=$(date +%s) "${shell.escape
- "flock -n ${shell.escape plan.dst.path} /bin/sh"
- }
+ start_date=$(date +%s)
local_rsync >&2 \
-aAXF --delete \
--rsh="$rsh" \
@@ -167,7 +162,10 @@ let
--link-dest="$dst_path/current" \
"$src/" \
"$dst/.partial"
- dst_shell < ${toFile "backup.${plan.name}.take-snapshots" ''
+ dst_exec env \
+ start_date="$start_date" \
+ flock -n "$dst_path" \
+ /bin/sh < ${toFile "backup.${plan.name}.take-snapshots" ''
set -efu
: $start_date