about summary refs log tree commit diff
path: root/yday
blob: ac3b95e297fc45877fc6a9049f2f1032157b6071 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# yday [-D DUMPDIR] [-a] [-d] [-n DAYS] FILES... - retrieve paths from the dump
#   -a  all versions
#   -d  diff against current file
#   -n  start DAYS back

: ${RDUMPFS_DUMP:=/data/dump/$HOSTNAME}

Xecho() {
  echo "$1"
}

Xdiff() {
  diff -u "$1" "$2"
}

all=false
op=Xecho
n=0

while getopts adn:D: opt; do
  case "$opt" in
    a) all=true;;
    d) op=Xdiff;;
    n) n="$OPTARG";;
    D) RDUMPFS_DUMP="$OPTARG";;
    [?]) exit;;
  esac
done
shift $((OPTIND-1))

for file; do
  ABSOLUTE=$(readlink -f "$file")
  for d in $(seq $n 1000); do
    DUMPED=$RDUMPFS_DUMP/$(date --date "$d day ago" +%Y%m%d)$ABSOLUTE
    if [ -e "$DUMPED" ]; then
      $op "$DUMPED" "$ABSOLUTE"
      $all || break
    fi
  done
done