Skip to content

Commit f639ab7

Browse files
committed
Merge branch 'master' of github.com:github/backup-utils
2 parents 3d29477 + 65c23c1 commit f639ab7

File tree

7 files changed

+32
-57
lines changed

7 files changed

+32
-57
lines changed

backup.config-example

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,3 @@ 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

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@ 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-
4130
# Verify that the /data/elasticsearch directory exists.
4231
if ! ghe-ssh "$host" -- "[ -d '$GHE_REMOTE_DATA_USER_DIR/elasticsearch' ]"; then
4332
ghe_verbose "* The '$GHE_REMOTE_DATA_USER_DIR/elasticsearch' directory doesn't exist."
@@ -58,7 +47,6 @@ ghe-rsync -avz \
5847
-e "ghe-ssh -p $(ssh_port_part "$host")" \
5948
--rsync-path="sudo -u elasticsearch rsync" \
6049
$link_dest \
61-
--exclude-from="$exclude_file" \
6250
"$(ssh_host_part "$host"):$GHE_REMOTE_DATA_USER_DIR/elasticsearch/" \
6351
"$GHE_SNAPSHOT_DIR/elasticsearch" 1>&3
6452

@@ -67,7 +55,6 @@ cleanup () {
6755
ghe_verbose "* Enabling ES index flushing ..."
6856
echo '{"index":{"translog.disable_flush":false}}' |
6957
ghe-ssh "$host" -- curl -s -XPUT "localhost:9200/_settings" -d @- >/dev/null
70-
rm -rf "$exclude_file"
7158
}
7259
trap 'cleanup' EXIT
7360
trap 'exit $?' INT # ^C always terminate
@@ -84,7 +71,6 @@ ghe-rsync -avz \
8471
-e "ghe-ssh -p $(ssh_port_part "$host")" \
8572
--rsync-path="sudo -u elasticsearch rsync" \
8673
$link_dest \
87-
--exclude-from="$exclude_file" \
8874
"$(ssh_host_part "$host"):$GHE_REMOTE_DATA_USER_DIR/elasticsearch/" \
8975
"$GHE_SNAPSHOT_DIR/elasticsearch" 1>&3
9076

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#/
55
#/ Note: This command typically isn't called directly. It's invoked by
66
#/ ghe-backup.
7-
set -ex
7+
set -e
88

99
# Bring in the backup configuration
1010
base_path="$( dirname "${BASH_SOURCE[0]}" )"
@@ -34,30 +34,46 @@ mysql_dump_available(){
3434
ls -A "$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT"/audit-log-mysql/20*.gz >/dev/null 2>&1
3535
}
3636

37+
# Check whether the snapshot contains the audit log table schema
38+
mysql_table_schema_available(){
39+
ls -A "$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT"/audit-log-mysql/schema.gz >/dev/null 2>&1
40+
}
41+
3742
# Check whether the remote host is running a version where the MySQL backend
3843
# is supported, i.e: < 2.19
3944
is_mysql_supported(){
40-
[ "$(version $GHE_REMOTE_VERSION)" -lt "$(version 2.19.0)" ]
45+
[ "$(version "$GHE_REMOTE_VERSION")" -lt "$(version 2.19.0)" ]
4146
}
4247

48+
# Helper function to set remote flags in `/data/user/common/audit-log-import`
49+
# if it's supported, i.e: directory exists.
4350
set_remote_flag(){
4451
local flag=$1
4552
local msg=$2
4653

47-
ghe_verbose "$2"
48-
ghe-ssh "$GHE_HOSTNAME" -- "sudo touch $GHE_REMOTE_ROOT_DIR/data/user/common/audit-log-import/$flag" 1>&3 2>&3
54+
local dir="/data/user/common/audit-log-import"
55+
56+
if ! ghe-ssh "$GHE_HOSTNAME" -- "sudo test -d $GHE_REMOTE_ROOT_DIR/$dir" 1>&3 2>&3; then
57+
ghe_verbose "Remote version doesn't support audit log import, skipping '$msg'"
58+
return
59+
fi
60+
61+
ghe_verbose "$msg"
62+
ghe-ssh "$GHE_HOSTNAME" -- "sudo touch $GHE_REMOTE_ROOT_DIR/$dir/$flag" 1>&3 2>&3
4963

5064
if $CLUSTER; then
51-
if ! ghe-ssh "$GHE_HOSTNAME" -- "ghe-cluster-each -- sudo touch /data/user/common/audit-log-import/$flag" 1>&3 2>&3; then
65+
if ! ghe-ssh "$GHE_HOSTNAME" -- "ghe-cluster-each -- sudo touch $dir/$flag" 1>&3 2>&3; then
5266
ghe_verbose "Failed to $msg in all instances in cluster"
5367
fi
5468
fi
5569
}
5670

71+
# Add flag to not trigger transitions from MySQL to Elasticsearch
5772
set_skip_transition_flag(){
5873
set_remote_flag "skip" "Add flag to skip audit log import to MySQL"
5974
}
6075

76+
# Add flag to not trigger the truncation of the MySQL audit log table
6177
set_skip_truncate_flag(){
6278
set_remote_flag "skip_truncate" "Add flag to skip truncating audit log table in MySQL"
6379
}
@@ -111,9 +127,13 @@ do_restore(){
111127
return
112128
fi
113129

114-
# Only the table schema is available, restore it
115-
ghe_verbose "Only audit_entries schema is available"
116-
restore_mysql --only-schema
130+
if mysql_table_schema_available; then
131+
# Only the table schema is available, restore it
132+
ghe_verbose "Only audit_entries schema is available"
133+
restore_mysql --only-schema
134+
else
135+
ghe_verbose "MySQL table schema is not available"
136+
fi
117137
}
118138

119139
main(){

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#/
55
#/ Note: This command typically isn't called directly. It's invoked by
66
#/ ghe-restore.
7-
set -ex
7+
set -e
88

99
# Bring in the backup configuration
1010
# shellcheck source=share/github-backup-utils/ghe-backup-config

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#/
55
#/ Note: This command typically isn't called directly. It's invoked by
66
#/ ghe-restore-audit-log
7-
set -ex
7+
set -e
88

99
# Bring in the backup configuration
1010
base_path="$( dirname "${BASH_SOURCE[0]}" )"

test/test-ghe-restore.sh

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -280,32 +280,6 @@ begin_test "ghe-restore with no pages backup"
280280
)
281281
end_test
282282

283-
begin_test "ghe-restore removes audit log import to MySQL flag when is a < 2.17 snapshot"
284-
(
285-
set -e
286-
287-
rm -rf "$GHE_REMOTE_ROOT_DIR"
288-
setup_remote_metadata
289-
290-
# set as configured, enable maintenance mode and create required directories
291-
setup_maintenance_mode "configured"
292-
293-
flag="$GHE_REMOTE_ROOT_DIR/data/user/common/audit-log-import/complete"
294-
mkdir -p "$(dirname $flag)"
295-
touch "$flag"
296-
297-
if ! output=$(ghe-restore -v -f localhost 2>&1); then
298-
echo "Error: failed to restore $output" >&2
299-
exit 1
300-
fi
301-
302-
! test -e "$flag" || {
303-
echo "Error: the restore process should've removed $flag" >&2
304-
exit 1
305-
}
306-
)
307-
end_test
308-
309283
begin_test "ghe-restore cluster backup to non-cluster appliance"
310284
(
311285
set -e

test/testlib.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ setup_test_data () {
253253
mkdir -p "$loc/audit-log/"
254254
cd "$loc/audit-log/"
255255
echo "fake audit log last yr last mth" | gzip > audit_log-1-$last_yr-$last_mth-1.gz
256+
echo "1" > audit_log-1-$last_yr-$last_mth-1.size
256257
echo "fake audit log this yr this mth" | gzip > audit_log-1-$this_yr-$this_mth-1.gz
258+
echo "1" > audit_log-1-$this_yr-$this_mth-1.size
257259

258260
# Create hookshot logs
259261
mkdir -p "$loc/hookshot/"

0 commit comments

Comments
 (0)