"Fossies" - the Fresh Open Source Software Archive

Member "bup-0.30/cmd/import-rsnapshot-cmd.sh" (28 Sep 2019, 1386 Bytes) of package /linux/privat/bup-0.30.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 # Does an import of a rsnapshot archive.
    3 
    4 usage() {
    5     echo "Usage: bup import-rsnapshot [-n]" \
    6         "<path to snapshot_root> [<backuptarget>]"
    7     echo "-n,--dry-run: just print what would be done"
    8     exit 1
    9 }
   10 
   11 DRY_RUN=
   12 while [ "$1" = "-n" -o "$1" = "--dry-run" ]; do
   13     DRY_RUN=echo
   14     shift
   15 done
   16 
   17 bup()
   18 {
   19     $DRY_RUN "${BUP_MAIN_EXE:=bup}" "$@"
   20 }
   21 
   22 SNAPSHOT_ROOT=$1
   23 TARGET=$2
   24 
   25 [ -n "$SNAPSHOT_ROOT" -a "$#" -le 2 ] || usage
   26 
   27 if [ ! -e "$SNAPSHOT_ROOT/." ]; then
   28     echo "'$SNAPSHOT_ROOT' isn't a directory!"
   29     exit 1
   30 fi
   31 
   32 
   33 cd "$SNAPSHOT_ROOT" || exit 2
   34 
   35 for SNAPSHOT in *; do
   36     [ -e "$SNAPSHOT/." ] || continue
   37     echo "snapshot='$SNAPSHOT'" >&2
   38     for BRANCH_PATH in "$SNAPSHOT/"*; do
   39         BRANCH=$(basename "$BRANCH_PATH") || exit $?
   40         [ -e "$BRANCH_PATH/." ] || continue
   41         [ -z "$TARGET" -o "$TARGET" = "$BRANCH" ] || continue
   42         
   43         echo "snapshot='$SNAPSHOT' branch='$BRANCH'" >&2
   44 
   45         # Get the snapshot's ctime
   46         DATE=$(perl -e '@a=stat($ARGV[0]) or die "$ARGV[0]: $!";
   47                         print $a[10];' "$BRANCH_PATH")
   48     [ -n "$DATE" ] || exit 3
   49 
   50         TMPIDX=bupindex.$BRANCH.tmp
   51         bup index -ux -f "$TMPIDX" "$BRANCH_PATH/" || exit $?
   52         bup save --strip --date="$DATE" \
   53             -f "$TMPIDX" -n "$BRANCH" \
   54             "$BRANCH_PATH/" || exit $?
   55         rm "$TMPIDX" || exit $?
   56     done
   57 done