]> arthur.barton.de Git - bup.git/blob - cmd/import-duplicity-cmd.sh
Make import-duplicity's output more verbose
[bup.git] / cmd / import-duplicity-cmd.sh
1 #!/bin/sh
2
3 set -e
4
5 usage() {
6     echo "Usage: bup import-duplicity [-n]" \
7         "<duplicity target url> <backup name>"
8     echo "-n,--dry-run: just print what would be done"
9     exit -1
10 }
11
12 dry_run=
13 while [ "$1" = "-n" -o "$1" = "--dry-run" ]; do
14     dry_run=echo
15     shift
16 done
17
18 bup()
19 {
20     $dry_run "${BUP_MAIN_EXE:=bup}" "$@"
21 }
22
23 duplicity_target_url=$1
24 branch=$2
25
26 [ -n "$duplicity_target_url" -a "$#" = 2 ] || usage
27
28 dup_timestamps=$(duplicity collection-status --log-fd=3 \
29                  "$duplicity_target_url" 3>&1 1>/dev/null 2>/dev/null |
30                  grep "[[:digit:]][[:digit:]]T" |
31                  cut -d" " -f 3)
32 backups_count=$(echo "$dup_timestamp" | wc -l)
33 counter=1
34 echo "$dup_timestamps" |
35 while read dup_timestamp; do
36   timestamp=$(python -c "import time,calendar; " \
37       "print str(int(calendar.timegm(time.strptime('$dup_timestamp', " \
38       "'%Y%m%dT%H%M%SZ'))))")
39   echo "Importing backup from $(date --date=@$timestamp +%c) " \
40       "($counter / $backups_count)" 1>&2
41   echo 1>&2
42
43   tmpdir=$(mktemp -d)
44
45   echo "Restoring from rdiff-backup..." 1>&2
46   duplicity restore -t "$dup_timestamp" "$duplicity_target_url" "$tmpdir"
47   echo 1>&2
48
49   echo "Importing into bup..." 1>&2
50   tmpidx=$(mktemp -u)
51   bup index -ux -f "$tmpidx" "$tmpdir"
52   bup save --strip --date="$timestamp" -f "$tmpidx" -n "$branch" "$tmpdir"
53   rm -f "$tmpidx"
54
55   rm -rf "$tmpdir"
56   counter=$((counter+1))
57   echo 1>&2
58   echo 1>&2
59 done