summaryrefslogtreecommitdiffstats
path: root/auth/auth-cass/cass_init/restore.sh
blob: 0bf0ea65bf1c4145c6e347d5590c463852949906 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# echo -n "Password:"
# read  -s PWD
# echo
echo `date`
ENV=DOCKER

CQLSH="${CQLSH:=/usr/bin/cqlsh} -k authz"

cd dats
if [ "$*" = "" ]; then
  DATA=""
  for Tdat in `ls *.dat`; do
    if [ -s "${Tdat}" ]; then
      DATA="$DATA ${Tdat%.dat}"
    fi
  done
else
  DATA="$*"
fi
cd -

echo "You are about to REPLACE the data in the $ENV DB for the following tables:"
echo "$DATA"
echo -n 'If you are VERY sure, type "YES": '
read YES

if [ ! "$YES" = "YES" ]; then
  echo 'Exiting ...'
  exit
fi

UPLOAD=""
for T in $DATA; do
  if [ -s "dats/${T}.dat" ]; then
    echo $T
    case "$T" in
      # 2.1.14 still has NULL problems for COPY.  Fixed in 2.1.15+
      "approval"|"artifact"|"cred"|"ns"|"x509"|"role"|"notified")
        $CQLSH -e  "truncate $T"
        UPLOAD="$UPLOAD "$T
        ;;
      "history")
        $CQLSH -e "truncate $T"
        DO_HISTORY=true
        ;;
      *)
        $CQLSH -e  "truncate $T; COPY authz.${T} FROM 'dats/${T}.dat' WITH DELIMITER='|'"
        ;;
    esac
  fi
done

if [ ! "$UPLOAD" = "" ]; then
  cd dats
  java -Dcadi_prop_files=../authBatch.props -DCASS_ENV=$ENV -jar ../aaf-auth-batch-*-full.jar Upload $UPLOAD 2>&1 logs/stdout
  cd -
fi

if [ "$DO_HISTORY" = "true" ]; then
  $CQLSH -e  "COPY authz.history FROM 'dats/history.dat' WITH DELIMITER='|'"
fi
echo `date`