]> arthur.barton.de Git - bup.git/blob - cmd/import-rsnapshot-cmd.sh
Adds import-rsnapshot command.
[bup.git] / cmd / import-rsnapshot-cmd.sh
1 #!/bin/sh
2 # bup-import-rsnapshot.sh
3
4 # Does an import of a rsnapshot archive.
5
6 usage() {
7     echo "Usage: bup import-rsnapshot [-n]" \
8         "<path to snapshot_root> [<backuptarget>]"
9     echo "-n,--dry-rung: don't do anything just print out what would be done"
10     exit -1
11 }
12
13 if [ "$1" == "-n" ] || [ "$1" == "--dry-run" ]; then
14     bup () { echo "bup $@"; }
15     shift 1
16 fi
17
18 [ "$#" -eq 1 ] || [ "$#" -eq 2 ] || usage
19
20 if [ ! -e "$1/." ]; then
21     echo "$1 isn't a directory!"
22     exit -1
23 fi
24
25 TARGET=
26 [ "$#" -eq 2 ] && TARGET="$2"
27
28
29 ABSPATH=`readlink -f "$1"`
30
31 for SNAPSHOT in "$ABSPATH/"*; do
32     if [ -e "$SNAPSHOT/." ]; then
33         for BRANCH_PATH in "$SNAPSHOT/"*; do
34             if [ -e "$BRANCH_PATH/." ]; then
35                 # Get the snapshot's ctime
36                 DATE=`stat -c %Z "$BRANCH_PATH"`
37                 BRANCH=`basename "$BRANCH_PATH"`
38                 TMPIDX="/tmp/$BRANCH"
39
40                 if [ "$TARGET" == "" ] || [ "$TARGET" == "$BRANCH" ]; then
41                     bup index -ux \
42                         $BRANCH_PATH/
43                     bup save \
44                         --strip \
45                         --date=$DATE \
46                         -n $BRANCH \
47                         $BRANCH_PATH/
48
49                     if [ -e "$TMPIDX" ]; then
50                         rm "$TMPIDX"
51                     fi
52                 fi
53             fi
54         done
55     fi
56 done
57