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=4ae422adbc66ea42efa0373c5253fde9b9c06fe8;hpb=35f02614c206d9b2241272fa64b05348c55f0cf0;p=bup.git diff --git a/cmd/import-rsnapshot-cmd.sh b/cmd/import-rsnapshot-cmd.sh index 4ae422a..91f711e 100755 --- a/cmd/import-rsnapshot-cmd.sh +++ b/cmd/import-rsnapshot-cmd.sh @@ -1,72 +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" -o "$1" = "--dry-run" ]; then - bup() - { - echo bup "$@" >&2 - } - shift 1 -elif [ -n "$BUP_MAIN_EXE" ]; then - bup() - { - "$BUP_MAIN_EXE" "$@" - } -else - bup() - { - bup "$@" - } -fi - -[ "$#" -eq 1 ] || [ "$#" -eq 2 ] || usage - -if [ ! -e "$1/." ]; then - echo "$1 isn't a directory!" - exit -1 -fi +DRY_RUN= +while [ "$1" = "-n" -o "$1" = "--dry-run" ]; do + DRY_RUN=echo + shift +done -TARGET= -[ "$#" -eq 2 ] && TARGET="$2" +bup() +{ + $DRY_RUN "$cmd_dir/bup" "$@" +} +SNAPSHOT_ROOT=$1 +TARGET=$2 -ABSPATH=`readlink -f "$1"` +[ -n "$SNAPSHOT_ROOT" -a "$#" -le 2 ] || usage -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 [ ! -e "$SNAPSHOT_ROOT/." ]; then + echo "'$SNAPSHOT_ROOT' isn't a directory!" + exit 1 +fi - if [ "$TARGET" = "" ] || [ "$TARGET" = "$BRANCH" ]; then - bup index -ux \ - -f $TMPIDX \ - $BRANCH_PATH/ - bup save \ - --strip \ - --date=$DATE \ - -f $TMPIDX \ - -n $BRANCH \ - $BRANCH_PATH/ - if [ -e "$TMPIDX" ]; then - rm "$TMPIDX" - fi - 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 -