]> arthur.barton.de Git - bup.git/blobdiff - cmd/import-rsnapshot-cmd.sh
Move pwd grp functions to pwdgrp module; require binary fields
[bup.git] / cmd / import-rsnapshot-cmd.sh
index 760fd00ec048ef22f8c03c37801cdda59da5a580..6ab398419a32b66d53a5e09c6e10b0b778cbf519 100755 (executable)
@@ -5,7 +5,7 @@ usage() {
     echo "Usage: bup import-rsnapshot [-n]" \
         "<path to snapshot_root> [<backuptarget>]"
     echo "-n,--dry-run: just print what would be done"
-    exit -1
+    exit 1
 }
 
 DRY_RUN=
@@ -30,31 +30,28 @@ if [ ! -e "$SNAPSHOT_ROOT/." ]; then
 fi
 
 
-ABSPATH=$(readlink -f "$SNAPSHOT_ROOT")
-
-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 [ -z "$TARGET" -o "$TARGET" = "$BRANCH" ]; then
-                    bup index -ux \
-                        -f "$TMPIDX" \
-                        "$BRANCH_PATH/"
-                    bup save \
-                        --strip \
-                        --date=$DATE \
-                        -f "$TMPIDX" \
-                        -n $BRANCH \
-                        "$BRANCH_PATH/"
-
-                    rm -f "$TMPIDX"
-                fi
-            fi
-        done
-    fi
+cd "$SNAPSHOT_ROOT" || exit 2
+
+for SNAPSHOT in *; do
+    [ -e "$SNAPSHOT/." ] || continue
+    echo "snapshot='$SNAPSHOT'" >&2
+    for BRANCH_PATH in "$SNAPSHOT/"*; do
+        BRANCH=$(basename "$BRANCH_PATH") || exit $?
+        [ -e "$BRANCH_PATH/." ] || continue
+        [ -z "$TARGET" -o "$TARGET" = "$BRANCH" ] || continue
+        
+        echo "snapshot='$SNAPSHOT' branch='$BRANCH'" >&2
+
+        # Get the snapshot's ctime
+        DATE=$(perl -e '@a=stat($ARGV[0]) or die "$ARGV[0]: $!";
+                        print $a[10];' "$BRANCH_PATH")
+       [ -n "$DATE" ] || exit 3
+
+        TMPIDX=bupindex.$BRANCH.tmp
+        bup index -ux -f "$TMPIDX" "$BRANCH_PATH/" || exit $?
+        bup save --strip --date="$DATE" \
+            -f "$TMPIDX" -n "$BRANCH" \
+            "$BRANCH_PATH/" || exit $?
+        rm "$TMPIDX" || exit $?
+    done
 done