X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cmd%2Fimport-rsnapshot-cmd.sh;h=91f711e19e10f817d83a38f1eb2fc990ebe23f36;hb=053869284db064aa21b2249981ec6affa489e296;hp=98b87c55643500af22f28081e8d8aa5efdeba701;hpb=b73884466c802aea6d87baf205d7facf04158804;p=bup.git diff --git a/cmd/import-rsnapshot-cmd.sh b/cmd/import-rsnapshot-cmd.sh index 98b87c5..91f711e 100755 --- a/cmd/import-rsnapshot-cmd.sh +++ b/cmd/import-rsnapshot-cmd.sh @@ -1,57 +1,59 @@ #!/bin/sh -# bup-import-rsnapshot.sh - # Does an import of a rsnapshot archive. +cmd_dir="$(cd "$(dirname "$0")" && pwd)" || exit $? + usage() { echo "Usage: bup import-rsnapshot [-n]" \ " []" - echo "-n,--dry-rung: don't do anything just print out what would be done" - exit -1 + echo "-n,--dry-run: just print what would be done" + exit 1 } -if [ "$1" == "-n" ] || [ "$1" == "--dry-run" ]; then - bup () { echo "bup $@"; } - shift 1 -fi +DRY_RUN= +while [ "$1" = "-n" -o "$1" = "--dry-run" ]; do + DRY_RUN=echo + shift +done -[ "$#" -eq 1 ] || [ "$#" -eq 2 ] || usage +bup() +{ + $DRY_RUN "$cmd_dir/bup" "$@" +} -if [ ! -e "$1/." ]; then - echo "$1 isn't a directory!" - exit -1 +SNAPSHOT_ROOT=$1 +TARGET=$2 + +[ -n "$SNAPSHOT_ROOT" -a "$#" -le 2 ] || usage + +if [ ! -e "$SNAPSHOT_ROOT/." ]; then + echo "'$SNAPSHOT_ROOT' 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 +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