]> arthur.barton.de Git - bup.git/commitdiff
Implement a import-rdiff-backup command
authorZoran Zaric <zz@zoranzaric.de>
Mon, 24 Sep 2012 22:30:11 +0000 (00:30 +0200)
committerRob Browning <rlb@defaultvalue.org>
Sat, 6 Oct 2012 21:13:19 +0000 (16:13 -0500)
Signed-off-by: Zoran Zaric <zz@zoranzaric.de>
Reviewed-by: Gabriel Filion <lelutin@gmail.com>
cmd/import-rdiff-backup-cmd.sh [new file with mode: 0755]

diff --git a/cmd/import-rdiff-backup-cmd.sh b/cmd/import-rdiff-backup-cmd.sh
new file mode 100755 (executable)
index 0000000..8285e0f
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+set -e
+
+usage() {
+    echo "Usage: bup import-rdiff-backup [-n]" \
+        "<path to rdiff-backup root> <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}" "$@"
+}
+
+snapshot_root=$1
+branch=$2
+
+[ -n "$snapshot_root" -a "$#" = 2 ] || usage
+
+if [ ! -e "$snapshot_root/." ]; then
+    echo "'$snapshot_root' isn't a directory!"
+    exit 1
+fi
+
+
+rdiff-backup --list-increments --parsable-output "$snapshot_root" |
+while read timestamp type; do
+    tmpdir=$(mktemp -d)
+
+    rdiff-backup -r $timestamp "$snapshot_root" "$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