]> arthur.barton.de Git - bup.git/commitdiff
Adds import-rsnapshot command.
authorZoran Zaric <zz@zoranzaric.de>
Mon, 6 Dec 2010 12:00:05 +0000 (13:00 +0100)
committerAvery Pennarun <apenwarr@gmail.com>
Mon, 3 Jan 2011 04:57:11 +0000 (20:57 -0800)
Signed-off-by: Zoran Zaric <zz@zoranzaric.de>
cmd/import-rsnapshot-cmd.sh [new file with mode: 0755]

diff --git a/cmd/import-rsnapshot-cmd.sh b/cmd/import-rsnapshot-cmd.sh
new file mode 100755 (executable)
index 0000000..98b87c5
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/sh
+# bup-import-rsnapshot.sh
+
+# Does an import of a rsnapshot archive.
+
+usage() {
+    echo "Usage: bup import-rsnapshot [-n]" \
+        "<path to snapshot_root> [<backuptarget>]"
+    echo "-n,--dry-rung: don't do anything just print out what would be done"
+    exit -1
+}
+
+if [ "$1" == "-n" ] || [ "$1" == "--dry-run" ]; then
+    bup () { echo "bup $@"; }
+    shift 1
+fi
+
+[ "$#" -eq 1 ] || [ "$#" -eq 2 ] || usage
+
+if [ ! -e "$1/." ]; then
+    echo "$1 isn't a directory!"
+    exit -1
+fi
+
+TARGET=
+[ "$#" -eq 2 ] && TARGET="$2"
+
+
+ABSPATH=`readlink -f "$1"`
+
+for SNAPSHOT in "$ABSPATH/"*; do
+    if [ -e "$SNAPSHOT/." ]; then
+        for BRANCH_PATH in "$SNAPSHOT/"*; do
+            if [ -e "$BRANCH_PATH/." ]; then
+                # Get the snapshot's ctime
+                DATE=`stat -c %Z "$BRANCH_PATH"`
+                BRANCH=`basename "$BRANCH_PATH"`
+                TMPIDX="/tmp/$BRANCH"
+
+                if [ "$TARGET" == "" ] || [ "$TARGET" == "$BRANCH" ]; then
+                    bup index -ux \
+                        $BRANCH_PATH/
+                    bup save \
+                        --strip \
+                        --date=$DATE \
+                        -n $BRANCH \
+                        $BRANCH_PATH/
+
+                    if [ -e "$TMPIDX" ]; then
+                        rm "$TMPIDX"
+                    fi
+                fi
+            fi
+        done
+    fi
+done
+