From efb14816126b5bade4724d9890c53a09a2c955ef Mon Sep 17 00:00:00 2001 From: Zoran Zaric Date: Tue, 25 Sep 2012 01:13:29 +0200 Subject: [PATCH] Implement an import-duplicity command Signed-off-by: Zoran Zaric [rlb@defaultvalue.org: adjust commit message] --- Makefile | 1 + cmd/import-duplicity-cmd.sh | 46 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100755 cmd/import-duplicity-cmd.sh diff --git a/Makefile b/Makefile index 18b128f..c15adfb 100644 --- a/Makefile +++ b/Makefile @@ -112,6 +112,7 @@ cmdline_tests := \ t/test-save-creates-no-unrefs.sh \ t/test-save-restore-excludes.sh \ t/test-save-strip-graft.sh \ + t/test-import-duplicity.sh \ t/test-import-rdiff-backup.sh \ t/test-xdev.sh \ t/test.sh diff --git a/cmd/import-duplicity-cmd.sh b/cmd/import-duplicity-cmd.sh new file mode 100755 index 0000000..6d4b0ef --- /dev/null +++ b/cmd/import-duplicity-cmd.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +set -e + +usage() { + echo "Usage: bup import-duplicity [-n]" \ + " " + echo "-n,--dry-run: just print what would be done" + exit -1 +} + +dry_run= +while [ "$1" = "-n" -o "$1" = "--dry-run" ]; do + dry_run=echo + shift +done + +bup() +{ + $dry_run "${BUP_MAIN_EXE:=bup}" "$@" +} + +duplicity_target_url=$1 +branch=$2 + +[ -n "$duplicity_target_url" -a "$#" = 2 ] || usage + +duplicity collection-status --log-fd=3 \ + "$duplicity_target_url" 3>&1 1>/dev/null 2>/dev/null | +grep "[[:digit:]][[:digit:]]T" | +cut -d" " -f 3 | +while read dup_timestamp; do + timestamp=$(python -c "import time,calendar; " \ + "print str(int(calendar.timegm(time.strptime('$dup_timestamp', " \ + "'%Y%m%dT%H%M%SZ'))))") + tmpdir=$(mktemp -d) + + duplicity restore -t "$dup_timestamp" "$duplicity_target_url" "$tmpdir" + + tmpidx=$(mktemp -u) + bup index -ux -f "$tmpidx" "$tmpdir" + bup save --strip --date="$timestamp" -f "$tmpidx" -n "$branch" "$tmpdir" + rm -f "$tmpidx" + + rm -rf "$tmpdir" +done -- 2.39.2