Skip to content

Commit ed5dbb3

Browse files
committed
Merge pull request #175 from github/auditlog-backup-fix
Ask for index name when using Elasticsearch _cat API
2 parents 4b6d5f4 + fa9cbc8 commit ed5dbb3

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

bin/ghe-backup

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,11 @@ else
147147
failures="$failures redis"
148148
fi
149149

150-
echo "Backing up audit log ..."
151-
ghe-backup-es-audit-log ||
152-
failures="$failures audit-log"
150+
if [ $GHE_VERSION_MAJOR -ge 2 ]; then
151+
echo "Backing up audit log ..."
152+
ghe-backup-es-audit-log ||
153+
failures="$failures audit-log"
154+
fi
153155

154156
echo "Backing up hookshot logs ..."
155157
ghe-backup-es-hookshot ||

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,24 @@ ghe_remote_version_required "$host"
1919
# Make sure root backup dir exists if this is the first run
2020
mkdir -p "$GHE_SNAPSHOT_DIR/audit-log"
2121

22-
indices=$(ghe-ssh "$host" 'curl -s "localhost:9201/_cat/indices/audit_log*"' | cut -d ' ' -f 3)
22+
if [ $GHE_VERSION_MAJOR -ge 2 ] && [ $GHE_VERSION_MINOR -ge 2 ]; then
23+
es_port=9201
24+
else
25+
es_port=9200
26+
fi
27+
28+
if ! indices=$(ghe-ssh "$host" "curl -s \"localhost:$es_port/_cat/indices/audit_log*?h=index"\"); then
29+
echo "Error: failed to retrieve audit log indices." 1>&2
30+
exit 1
31+
fi
32+
2333
current_index=audit_log-$(ghe-ssh "$host" 'date +"%Y-%m"')
2434

2535
for index in $indices; do
2636
if [ -f $GHE_DATA_DIR/current/audit-log/$index.gz -a $index \< $current_index ]; then
2737
# Hard link any older indices since they are read only and won't change
2838
ln $GHE_DATA_DIR/current/audit-log/$index.gz $GHE_SNAPSHOT_DIR/audit-log/$index.gz
2939
else
30-
ghe-ssh "$host" "/usr/local/share/enterprise/ghe-es-dump-json 'http://localhost:9201/$index'" | gzip > $GHE_SNAPSHOT_DIR/audit-log/$index.gz
40+
ghe-ssh "$host" "/usr/local/share/enterprise/ghe-es-dump-json \"http://localhost:$es_port/$index\"" | gzip > $GHE_SNAPSHOT_DIR/audit-log/$index.gz
3141
fi
3242
done

test/bin/curl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
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
8+
exit 0
9+
fi
10+
611
# Write args to stdout
712
echo "$@"
813

0 commit comments

Comments
 (0)