]> arthur.barton.de Git - bup.git/blob - cmd/import-duplicity-cmd.sh
Implement an import-duplicity command
[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 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 while read dup_timestamp; do
33   timestamp=$(python -c "import time,calendar; " \
34       "print str(int(calendar.timegm(time.strptime('$dup_timestamp', " \
35       "'%Y%m%dT%H%M%SZ'))))")
36   tmpdir=$(mktemp -d)
37
38   duplicity restore -t "$dup_timestamp" "$duplicity_target_url" "$tmpdir"
39
40   tmpidx=$(mktemp -u)
41   bup index -ux -f "$tmpidx" "$tmpdir"
42   bup save --strip --date="$timestamp" -f "$tmpidx" -n "$branch" "$tmpdir"
43   rm -f "$tmpidx"
44
45   rm -rf "$tmpdir"
46 done