Skip to content

Commit 5ff76a9

Browse files
authored
Merge pull request #343 from github/snh/audit-211
Support 2.11 audit log index naming for cluster backups and restores
2 parents e4e9fef + a537d73 commit 5ff76a9

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ if echo 'set -o pipefail; ! test -e /data/user/common/es-scan-complete && test -
3838
fi
3939
fi
4040

41-
current_index=audit_log-$(ghe-ssh "$host" 'date +"%Y-%m"')
41+
current_index="audit_log(-[0-9]+)?-$(ghe-ssh "$host" 'date +"%Y-%m"')(-[0-9]+)?"
4242

4343
for index in $indices; do
44-
if [ -f $GHE_DATA_DIR/current/audit-log/$index.gz -a -f $GHE_DATA_DIR/current/audit-log/$index.gz.complete -a $index \< $current_index ]; then
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
4545
# Hard link any older indices that are complete, since these won't change
4646
ln $GHE_DATA_DIR/current/audit-log/$index.gz $GHE_SNAPSHOT_DIR/audit-log/$index.gz
4747
ln $GHE_DATA_DIR/current/audit-log/$index.gz.complete $GHE_SNAPSHOT_DIR/audit-log/$index.gz.complete
4848
else
4949
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
50+
if [[ ! $index =~ $current_index ]]; then
5151
touch $GHE_SNAPSHOT_DIR/audit-log/$index.gz.complete
5252
fi
5353
fi

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ GHE_HOSTNAME="$1"
1919
# Perform a host-check and establish GHE_REMOTE_XXX variables.
2020
ghe_remote_version_required "$GHE_HOSTNAME"
2121

22-
last_index=$(ghe-ssh "$GHE_HOSTNAME" 'curl -s "localhost:9201/_cat/indices/audit_log*"' | cut -d ' ' -f 3 | sort | tail -2 | head -1)
23-
2422
indices=$(ls -1 $GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT/audit-log/*.gz 2>/dev/null | xargs -I{} -n1 basename {} .gz)
2523

24+
last_month="audit_log(-[0-9]+)?-$(ghe-ssh "$GHE_HOSTNAME" 'date -d "1 month ago" +"%Y-%m"')(-[0-9]+)?"
25+
current_month="audit_log(-[0-9]+)?-$(ghe-ssh "$GHE_HOSTNAME" 'date +"%Y-%m"')(-[0-9]+)?"
26+
2627
for index in $indices; do
27-
if [ -z "$last_index" ] || ! [ $index \< $last_index ]; then
28+
if ! ghe-ssh "$GHE_HOSTNAME" "curl -f -s -XGET http://localhost:9201/$index" || [[ $index =~ $last_month ]] || [[ $index =~ $current_month ]]; then
2829
ghe_verbose "* Restoring $index"
2930
gzip -dc $GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT/audit-log/$index.gz | ghe-ssh "$GHE_HOSTNAME" "/usr/local/share/enterprise/ghe-es-load-json 'http://localhost:9201/$index'" 1>&3
3031
fi

0 commit comments

Comments
 (0)