Skip to content

Commit 0944827

Browse files
authored
Merge pull request #374 from github/snh/audit-size
Use primary index size to determine if an index has changed
2 parents 8e9a938 + 2f3bda5 commit 0944827

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed

share/github-backup-utils/ghe-backup-es-audit-log

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,35 @@ else
2626
es_port=9200
2727
fi
2828

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
3030
echo "Error: failed to retrieve audit log indices." 1>&2
3131
exit 1
3232
fi
3333

34+
# Exit if no indices were found
35+
[ -z "$indices" ] && exit
36+
3437
# Determine if the audit log migration has occurred or is needed.
3538
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
3639
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
3740
touch $GHE_SNAPSHOT_DIR/es-scan-complete
3841
fi
3942
fi
4043

41-
current_index="audit_log(-[0-9]+)?-$(ghe-ssh "$host" 'date +"%Y-%m"')(-[0-9]+)?"
42-
44+
IFS=$'\n'
4345
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
4855
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
5358
fi
5459
done
5560

share/github-backup-utils/ghe-backup-es-hookshot

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,34 @@ ghe_remote_version_required "$host"
2020
# Make sure root backup dir exists if this is the first run
2121
mkdir -p "$GHE_SNAPSHOT_DIR/hookshot"
2222

23-
indices=$(ghe-ssh "$host" 'curl -s "localhost:9201/_cat/indices/hookshot-logs-*"' | cut -d ' ' -f 3)
23+
if [ $GHE_VERSION_MAJOR -ge 2 ] && [ $GHE_VERSION_MINOR -ge 2 ]; then
24+
es_port=9201
25+
else
26+
es_port=9200
27+
fi
2428

25-
current_index=hookshot-logs-$(ghe-ssh "$host" 'date +"%Y-%m-%d"')
29+
if ! indices=$(ghe-ssh "$host" "curl -s \"localhost:$es_port/_cat/indices/hookshot-logs-*?h=index,pri.store.size&bytes=b\""); then
30+
echo "Error: failed to retrieve hookshot log indices." 1>&2
31+
exit 1
32+
fi
2633

34+
# Hookshot indices may not exist if no recent webhook deliveries have occured.
35+
[ -z "$indices" ] && exit
36+
37+
IFS=$'\n'
2738
for index in $indices; do
28-
if [ -f $GHE_DATA_DIR/current/hookshot/$index.gz -a -f $GHE_DATA_DIR/current/hookshot/$index.gz.complete -a $index \< $current_index ]; then
29-
# Hard link any older indices that are complete, since these won't change
30-
ln $GHE_DATA_DIR/current/hookshot/$index.gz $GHE_SNAPSHOT_DIR/hookshot/$index.gz
31-
ln $GHE_DATA_DIR/current/hookshot/$index.gz.complete $GHE_SNAPSHOT_DIR/hookshot/$index.gz.complete
39+
IFS=' '
40+
set $index
41+
index_name=$1
42+
index_size=$2
43+
44+
if [[ -f $GHE_DATA_DIR/current/hookshot/$index_name.gz && $(cat $GHE_DATA_DIR/current/hookshot/$index_name.gz.size 2>/dev/null || true) -eq $index_size ]]; then
45+
# Hard link any indices that have not changed since the last backup
46+
ln $GHE_DATA_DIR/current/hookshot/$index_name.gz $GHE_SNAPSHOT_DIR/hookshot/$index_name.gz
47+
ln $GHE_DATA_DIR/current/hookshot/$index_name.gz.size $GHE_SNAPSHOT_DIR/hookshot/$index_name.gz.size
3248
else
33-
ghe-ssh "$host" "/usr/local/share/enterprise/ghe-es-dump-json \"http://localhost:9201/$index\"" | gzip > $GHE_SNAPSHOT_DIR/hookshot/$index.gz
34-
if [ $index \< $current_index ]; then
35-
touch $GHE_SNAPSHOT_DIR/hookshot/$index.gz.complete
36-
fi
49+
ghe-ssh "$host" "/usr/local/share/enterprise/ghe-es-dump-json \"http://localhost:$es_port/$index_name\"" | gzip > $GHE_SNAPSHOT_DIR/hookshot/$index_name.gz
50+
echo $index_size > $GHE_SNAPSHOT_DIR/hookshot/$index_name.gz.size
3751
fi
3852
done
3953

test/bin/curl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# Fake curl command stub for tests.
44
set -e
55

6-
# Return empty list of indexes for ghe-backup-es-audit-log
7-
if echo "$@" | grep -q '_cat/indices/audit_log\*?h=index$'; then
6+
# Return empty list of indexes for ghe-backup-es-audit-log and ghe-backup-es-hookshot
7+
if echo "$@" | grep -q '_cat/indices/'; then
88
exit 0
99
fi
1010

0 commit comments

Comments
 (0)