Skip to content

Commit 9865901

Browse files
authored
Merge branch 'master' into ce-typo
2 parents ae4a194 + 3e01563 commit 9865901

12 files changed

+712
-11
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
language: minimal
23
matrix:
34
include:
45
- os: osx

backup.config-example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,10 @@ GHE_NUM_SNAPSHOTS=10
4848
#
4949
# WARNING: do not enable this, only useful for debugging/development
5050
#GHE_BACKUP_FSCK=no
51+
52+
# If set to 'no', Elasticsearch audit log indices will not be backed up.
53+
# Note that they will still be backed up from MySQL. This will reduce
54+
# the time and size of the backup process but it will take longer
55+
# for the audit log entries to be searchable as they need to be reindexed
56+
# in Elasticsearch.
57+
#GHE_BACKUP_ES_AUDIT_LOGS=no

bin/ghe-backup

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ echo "Backing up Redis database ..."
184184
ghe-backup-redis > redis.rdb || failures="$failures redis"
185185

186186
echo "Backing up audit log ..."
187-
ghe-backup-es-audit-log || failures="$failures audit-log"
187+
ghe-backup-audit-log || failures="$failures audit-log"
188188

189189
echo "Backing up hookshot logs ..."
190190
ghe-backup-es-hookshot || failures="$failures hookshot"

bin/ghe-restore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ fi
301301
# Restore exported audit and hookshot logs to 2.12.9 and newer single nodes and
302302
# all releases of cluster
303303
if $CLUSTER || [ "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.12.9)" ]; then
304-
echo "Restoring Elasticsearch Audit logs ..."
305-
ghe-restore-es-audit-log "$GHE_HOSTNAME" 1>&3
304+
echo "Restoring Audit logs ..."
305+
ghe-restore-audit-log "$GHE_HOSTNAME" 1>&3
306306

307307
echo "Restoring hookshot logs ..."
308308
ghe-restore-es-hookshot "$GHE_HOSTNAME" 1>&3

script/cibuild

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ set -e
66
# place with this version at the beginning of each test and many commands have
77
# conditional logic based on the remote version. Running the suite against
88
# different major versions ensures we're covering these conditional paths.
9-
REMOTE_VERSIONS="
10-
2.14.0
11-
2.16.0
12-
"
9+
REMOTE_VERSIONS="2.14.0 2.16.0"
1310

1411
# Enable verbose logging of ssh commands
1512
export GHE_VERBOSE_SSH=true

script/release

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ def bump_version(new_version, min_version = nil, path = 'share/github-backup-uti
209209
content = File.read('test/testlib.sh')
210210
new_content = content.gsub(/GHE_TEST_REMOTE_VERSION:=[0-9]\.[0-9]+\.0/,"GHE_TEST_REMOTE_VERSION:=#{new_version}")
211211
File.open('test/testlib.sh', 'w') {|file| file.puts new_content }
212+
213+
content = File.read('script/cibuild')
214+
new_content = content.gsub(/^REMOTE_VERSIONS=.*$/, "REMOTE_VERSIONS=\"#{min_version} #{new_version}\"")
215+
File.open('script/cibuild', 'w') {|file| file.puts new_content }
212216
end
213217
end
214218

@@ -217,7 +221,7 @@ def push_release_branch(version)
217221
raise "Creating release branch failed:\n\n#{out}"
218222
end
219223

220-
unless (out = `git commit --quiet -m 'Bump version: #{version} [ci skip]' debian/changelog share/github-backup-utils/version bin/ghe-host-check test/testlib.sh`)
224+
unless (out = `git commit --quiet -m 'Bump version: #{version} [ci skip]' debian/changelog share/github-backup-utils/version bin/ghe-host-check test/testlib.sh script/cibuild`)
221225
raise "Error committing changelog and version:\n\n#{out}"
222226
end
223227

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: ghe-backup-audit-log
3+
#/ Take a backup of audit logs.
4+
#/
5+
#/ Note: This command typically isn't called directly. It's invoked by
6+
#/ ghe-backup.
7+
set -e
8+
9+
base_path="$( dirname "${BASH_SOURCE[0]}" )"
10+
# Bring in the backup configuration
11+
# shellcheck source=share/github-backup-utils/ghe-backup-config
12+
. "${base_path}/ghe-backup-config"
13+
14+
# Setup GHE_REMOTE_XXX variables, host and make sure work dir is created
15+
setup(){
16+
# Perform a host-check and establish GHE_REMOTE_XXX variables.
17+
ghe_remote_version_required "$host"
18+
19+
# Set up remote host and root elastic backup directory based on config
20+
host="$GHE_HOSTNAME"
21+
22+
# Make sure root backup dir exists if this is the first run
23+
mkdir -p "$GHE_SNAPSHOT_DIR/audit-log"
24+
}
25+
26+
# Check whether the MySQL backup should be enabled
27+
# by checking if the audit-log-import directory exists,
28+
# this makes it backwards-compatible with old snapshots
29+
mysql_backup_enabled(){
30+
ghe-ssh "$host" test -d "$GHE_REMOTE_DATA_USER_DIR/common/audit-log-import"
31+
}
32+
33+
# Check whether the MySQL import is complete by checking if
34+
# /data/user/common/audit-log-import/complete exists
35+
is_import_complete(){
36+
ghe-ssh "$host" test -e "$GHE_REMOTE_DATA_USER_DIR/common/audit-log-import/complete"
37+
}
38+
39+
# Check whether the MySQL import is disabled by verifying if
40+
# /data/user/common/audit-log-import/skip exists
41+
is_import_disabled(){
42+
ghe-ssh "$host" test -e "$GHE_REMOTE_DATA_USER_DIR/common/audit-log-import/skip"
43+
}
44+
45+
# Check whether the instance ships an audit log reconciler, if it doesn't
46+
# we can't dump audit_entries data, only the schema
47+
is_reconciler_available(){
48+
ghe-ssh "$GHE_HOSTNAME" -- "test -e /usr/local/share/enterprise/ghe-auditlog-repair"
49+
}
50+
51+
# Check whether we only need to back up the audit_entries schema and
52+
# ignore the actual data.
53+
#
54+
# This is the case when:
55+
# - The import to MySQL is not complete
56+
# - The import is disabled
57+
# - The reconciler tool is not available
58+
skip_mysql_entries(){
59+
if ! is_import_complete; then
60+
ghe_verbose "audit log import is not complete"
61+
return
62+
fi
63+
64+
if is_import_disabled; then
65+
ghe_verbose "audit log import is disabled"
66+
return
67+
fi
68+
69+
if ! is_reconciler_available; then
70+
ghe_verbose "audit log reconciler is not available"
71+
return
72+
fi
73+
74+
return 1
75+
}
76+
77+
# If the import to MySQL is complete, add a flag in the snapshot to indicate so.
78+
# And also use `ghe-backup-mysql-audit-log` to dump the audit entries.
79+
backup_mysql(){
80+
if skip_mysql_entries; then
81+
ghe_verbose "only backing up audit log table schema"
82+
"${base_path}/ghe-backup-mysql-audit-log" --schema-only
83+
return
84+
fi
85+
86+
"${base_path}/ghe-backup-mysql-audit-log"
87+
touch "$GHE_SNAPSHOT_DIR/audit-log/mysql-import-complete"
88+
}
89+
90+
# Audit log indices in Elasticsearch are backed up when:
91+
#
92+
# - Import is not complete
93+
# - Import is disabled
94+
# - Reconciler is not available
95+
# - GHE_BACKUP_ES_AUDIT_LOGS is not set to 'no'
96+
es_backup_enabled(){
97+
if skip_mysql_entries; then
98+
return
99+
fi
100+
101+
[ -z "$GHE_BACKUP_ES_AUDIT_LOGS" ] || [ "$GHE_BACKUP_ES_AUDIT_LOGS" != "no" ]
102+
}
103+
104+
# Use ghe-backup-es-audit-log to back up Elasticsearch indices
105+
backup_es(){
106+
"${base_path}/ghe-backup-es-audit-log"
107+
}
108+
109+
backup(){
110+
if mysql_backup_enabled; then
111+
ghe_verbose "MySQL audit logs backup is enabled"
112+
backup_mysql
113+
else
114+
ghe_verbose "MySQL audit logs backup is disabled"
115+
fi
116+
117+
if es_backup_enabled; then
118+
ghe_verbose "Elasticsearch audit logs backup is enabled"
119+
backup_es
120+
else
121+
ghe_verbose "Elasticsearch audit logs backup is disabled"
122+
fi
123+
}
124+
125+
main(){
126+
bm_start "$(basename "$0")"
127+
setup
128+
backup
129+
bm_end "$(basename "$0")"
130+
}
131+
132+
main

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ fi
2727
# Make sure root backup dir exists if this is the first run
2828
mkdir -p "$GHE_SNAPSHOT_DIR/elasticsearch"
2929

30+
# Create exclude file
31+
exclude_file="$(mktemp)"
32+
echo elasticsearch.yml >"$exclude_file"
33+
34+
# Exclude audit log indices when configuration says so and import to MySQL is complete
35+
# as those indices will be rebuilt from MySQL during a restore
36+
if [ "$GHE_BACKUP_ES_AUDIT_LOGS" = "no" ] && ghe-ssh "$host" test -e "/data/user/common/audit-log-import/complete"; then
37+
ghe_verbose "* Excluding Audit Log indices"
38+
ghe-ssh "$host" curl -s 'http://localhost:9201/_cat/indices/audit_log?h=uuid' >>$exclude_file 2>&3
39+
fi
40+
3041
# Verify that the /data/elasticsearch directory exists.
3142
if ! ghe-ssh "$host" -- "[ -d '$GHE_REMOTE_DATA_USER_DIR/elasticsearch' ]"; then
3243
ghe_verbose "* The '$GHE_REMOTE_DATA_USER_DIR/elasticsearch' directory doesn't exist."
@@ -47,15 +58,16 @@ ghe-rsync -avz \
4758
-e "ghe-ssh -p $(ssh_port_part "$host")" \
4859
--rsync-path="sudo -u elasticsearch rsync" \
4960
$link_dest \
50-
--exclude='elasticsearch.yml' \
61+
--exclude-from="$exclude_file" \
5162
"$(ssh_host_part "$host"):$GHE_REMOTE_DATA_USER_DIR/elasticsearch/" \
5263
"$GHE_SNAPSHOT_DIR/elasticsearch" 1>&3
5364

54-
# Set up a trap to re-enable flushing on exit
65+
# Set up a trap to re-enable flushing on exit and remove temp file
5566
cleanup () {
5667
ghe_verbose "* Enabling ES index flushing ..."
5768
echo '{"index":{"translog.disable_flush":false}}' |
5869
ghe-ssh "$host" -- curl -s -XPUT "localhost:9200/_settings" -d @- >/dev/null
70+
ghe-ssh "$host" rm -rf "$exclude_file"
5971
}
6072
trap 'cleanup' EXIT
6173
trap 'exit $?' INT # ^C always terminate
@@ -72,7 +84,7 @@ ghe-rsync -avz \
7284
-e "ghe-ssh -p $(ssh_port_part "$host")" \
7385
--rsync-path="sudo -u elasticsearch rsync" \
7486
$link_dest \
75-
--exclude='elasticsearch.yml' \
87+
--exclude-from="$exclude_file" \
7688
"$(ssh_host_part "$host"):$GHE_REMOTE_DATA_USER_DIR/elasticsearch/" \
7789
"$GHE_SNAPSHOT_DIR/elasticsearch" 1>&3
7890

0 commit comments

Comments
 (0)