|
26 | 26 | es_port=9200
|
27 | 27 | fi
|
28 | 28 |
|
29 |
| -if ! indices=$(ghe-ssh "$host" "curl -s \"localhost:$es_port/_cat/indices/audit_log*?h=index"\"); then |
| 29 | +if ! indices=$(ghe-ssh "$host" "curl -s \"localhost:$es_port/_cat/indices/audit_log*?h=index,pri.store.size&bytes=b\""); then |
30 | 30 | echo "Error: failed to retrieve audit log indices." 1>&2
|
31 | 31 | exit 1
|
32 | 32 | fi
|
33 | 33 |
|
| 34 | +# Exit if no indices were found |
| 35 | +[ -z "$indices" ] && exit |
| 36 | + |
34 | 37 | # Determine if the audit log migration has occurred or is needed.
|
35 | 38 | if echo 'set -o pipefail; ! test -e /data/user/common/es-scan-complete && test -f /usr/local/share/enterprise/run-audit-log-transitions.sh' | ghe-ssh "$host" /bin/bash; then
|
36 | 39 | if echo 'set -o pipefail; echo n | /usr/local/share/enterprise/run-audit-log-transitions.sh > /dev/null 2>&1 && touch /data/user/common/es-scan-complete' | ghe-ssh "$host" /bin/bash; then
|
37 | 40 | touch $GHE_SNAPSHOT_DIR/es-scan-complete
|
38 | 41 | fi
|
39 | 42 | fi
|
40 | 43 |
|
41 |
| -current_index="audit_log(-[0-9]+)?-$(ghe-ssh "$host" 'date +"%Y-%m"')(-[0-9]+)?" |
42 |
| - |
| 44 | +IFS=$'\n' |
43 | 45 | for index in $indices; do
|
44 |
| - if [[ -f $GHE_DATA_DIR/current/audit-log/$index.gz && -f $GHE_DATA_DIR/current/audit-log/$index.gz.complete && ! $index =~ $current_index ]]; then |
45 |
| - # Hard link any older indices that are complete, since these won't change |
46 |
| - ln $GHE_DATA_DIR/current/audit-log/$index.gz $GHE_SNAPSHOT_DIR/audit-log/$index.gz |
47 |
| - ln $GHE_DATA_DIR/current/audit-log/$index.gz.complete $GHE_SNAPSHOT_DIR/audit-log/$index.gz.complete |
| 46 | + IFS=' ' |
| 47 | + set $index |
| 48 | + index_name=$1 |
| 49 | + index_size=$2 |
| 50 | + |
| 51 | + if [[ -f $GHE_DATA_DIR/current/audit-log/$index_name.gz && $(cat $GHE_DATA_DIR/current/audit-log/$index_name.gz.size 2>/dev/null || true) -eq $index_size ]]; then |
| 52 | + # Hard link any indices that have not changed since the last backup |
| 53 | + ln $GHE_DATA_DIR/current/audit-log/$index_name.gz $GHE_SNAPSHOT_DIR/audit-log/$index_name.gz |
| 54 | + ln $GHE_DATA_DIR/current/audit-log/$index_name.gz.size $GHE_SNAPSHOT_DIR/audit-log/$index_name.gz.size |
48 | 55 | else
|
49 |
| - ghe-ssh "$host" "/usr/local/share/enterprise/ghe-es-dump-json \"http://localhost:$es_port/$index\"" | gzip > $GHE_SNAPSHOT_DIR/audit-log/$index.gz |
50 |
| - if [[ ! $index =~ $current_index ]]; then |
51 |
| - touch $GHE_SNAPSHOT_DIR/audit-log/$index.gz.complete |
52 |
| - fi |
| 56 | + ghe-ssh "$host" "/usr/local/share/enterprise/ghe-es-dump-json \"http://localhost:$es_port/$index_name\"" | gzip > $GHE_SNAPSHOT_DIR/audit-log/$index_name.gz |
| 57 | + echo $index_size > $GHE_SNAPSHOT_DIR/audit-log/$index_name.gz.size |
53 | 58 | fi
|
54 | 59 | done
|
55 | 60 |
|
|
0 commit comments