From 453384b60b628f97074c74940e88570aa8eab811 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 17 Apr 2016 03:51:55 +0200 Subject: krebs.backup: inject dst_path into dst shell --- krebs/3modules/backup.nix | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'krebs/3modules/backup.nix') diff --git a/krebs/3modules/backup.nix b/krebs/3modules/backup.nix index 1cd851a4..1e926429 100644 --- a/krebs/3modules/backup.nix +++ b/krebs/3modules/backup.nix @@ -163,41 +163,40 @@ let "$src/" \ "$dst/.partial" dst_exec env \ + dst_path="$dst_path" \ start_date="$start_date" \ flock -n "$dst_path" \ /bin/sh < ${toFile "backup.${plan.name}.take-snapshots" '' set -efu - : $start_date + : $dst_path $start_date - dst=${shell.escape plan.dst.path} - - mv "$dst/current" "$dst/.previous" - mv "$dst/.partial" "$dst/current" - rm -fR "$dst/.previous" + mv "$dst_path/current" "$dst_path/.previous" + mv "$dst_path/.partial" "$dst_path/current" + rm -fR "$dst_path/.previous" echo >&2 snapshot() {( : $ns $format $retain name=$(date --date="@$start_date" +"$format") - if ! test -e "$dst/$ns/$name"; then + if ! test -e "$dst_path/$ns/$name"; then echo >&2 "create snapshot: $ns/$name" - mkdir -m 0700 -p "$dst/$ns" + mkdir -m 0700 -p "$dst_path/$ns" rsync >&2 \ -aAXF --delete \ - --link-dest="$dst/current" \ - "$dst/current/" \ - "$dst/$ns/.partial.$name" - mv "$dst/$ns/.partial.$name" "$dst/$ns/$name" + --link-dest="$dst_path/current" \ + "$dst_path/current/" \ + "$dst_path/$ns/.partial.$name" + mv "$dst_path/$ns/.partial.$name" "$dst_path/$ns/$name" echo >&2 fi case $retain in ([0-9]*) delete_from=$(($retain + 1)) - ls -r "$dst/$ns" \ + ls -r "$dst_path/$ns" \ | sed -n "$delete_from,\$p" \ | while read old_name; do echo >&2 "delete snapshot: $ns/$old_name" - rm -fR "$dst/$ns/$old_name" + rm -fR "$dst_path/$ns/$old_name" done ;; (ALL) -- cgit v1.2.3