]> arthur.barton.de Git - bup.git/commitdiff
Implement an import-duplicity command
authorZoran Zaric <zz@zoranzaric.de>
Mon, 24 Sep 2012 23:13:29 +0000 (01:13 +0200)
committerRob Browning <rlb@defaultvalue.org>
Mon, 9 Mar 2015 01:55:14 +0000 (20:55 -0500)
Signed-off-by: Zoran Zaric <zz@zoranzaric.de>
[rlb@defaultvalue.org: adjust commit message]

Makefile
cmd/import-duplicity-cmd.sh [new file with mode: 0755]

index 18b128fcc765593047b466bd940d410a2f03eb98..c15adfb9b5968f5178daff2d1b247418a7062eea 100644 (file)
--- 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 (executable)
index 0000000..6d4b0ef
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+set -e
+
+usage() {
+    echo "Usage: bup import-duplicity [-n]" \
+        "<duplicity target url> <backup name>"
+    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