Skip to content

Commit 4ff376b

Browse files
authored
Merge pull request #543 from github/merge-stable-to-master
Merge stable to master
2 parents c8ef646 + 4c4050d commit 4ff376b

File tree

7 files changed

+133
-30
lines changed

7 files changed

+133
-30
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ matrix:
99
- brew install moreutils
1010
- brew install shellcheck
1111
- brew install jq
12+
- brew install coreutils
1213
- brew install pigz
1314
script: make test
1415
- os: linux
@@ -25,5 +26,6 @@ matrix:
2526
- moreutils
2627
- fakeroot
2728
- jq
29+
- coreutils
2830
- pigz
2931
script: debuild -uc -us

debian/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ github-backup-utils (2.20.0) UNRELEASED; urgency=medium
55

66
-- Alejandro Figueroa <[email protected]> Tue, 11 Feb 2020 20:47:17 +0000
77

8+
github-backup-utils (2.19.2) UNRELEASED; urgency=medium
9+
10+
* Fix `ghe-backup-repositories` performance for large instances #541
11+
12+
-- Evgenii Khramkov <[email protected]> Fri, 31 Jan 2020 19:13:46 +0000
13+
814
github-backup-utils (2.19.1) UNRELEASED; urgency=medium
915

1016
* Cater for more explicit gist paths used in routes file #524

share/github-backup-utils/ghe-backup-config

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,29 @@ ghe_debug() {
304304
version() {
305305
echo "${@#v}" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
306306
}
307+
308+
# The list of gists returned by the source changed in 2.16.23, 2.17.14,
309+
# 2.18.8, and 2.19.3. We need to account for this difference here.
310+
# In older versions, all paths need to be truncated with `dirname`.
311+
# In newer versions, gist paths are unmodified, and only other repo types
312+
# are truncated with `dirname`.
313+
fix_paths_for_ghe_version() {
314+
if [[ "$GHE_REMOTE_VERSION" =~ 2.16. && "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.16.23)" ]] || \
315+
[[ "$GHE_REMOTE_VERSION" =~ 2.17. && "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.17.14)" ]] || \
316+
[[ "$GHE_REMOTE_VERSION" =~ 2.18. && "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.18.8)" ]] || \
317+
[[ "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.19.3)" ]]; then
318+
GIST_FILTER="-e /gist/b"
319+
else
320+
unset GIST_FILTER
321+
fi
322+
323+
# This sed expression is equivalent to running `dirname` on each line,
324+
# but without all the fork+exec overhead of calling `dirname` that many
325+
# times:
326+
# 1. strip off trailing slashes
327+
# 2. if the result has no slashes in it, the dirname is "."
328+
# 3. truncate from the final slash (if any) to the end
329+
# If the GIST_FILTER was set above (because we're on a modern version of
330+
# GHES), then don't modify lines with "gist" in them.
331+
sed $GIST_FILTER -e 's/\/$//; s/^[^\/]*$/./; s/\/[^\/]*$//'
332+
}

share/github-backup-utils/ghe-backup-repositories

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -366,25 +366,8 @@ bm_end "$(basename $0) - Special Data Directories Sync"
366366

367367
if [ -z "$GHE_SKIP_ROUTE_VERIFICATION" ]; then
368368
bm_start "$(basename $0) - Verifying Routes"
369-
370-
# The list of gists returned by the source changed in 2.16.23, 2.17.14, 2.18.8 & 2.19.3
371-
# so we need to account for this difference here.
372-
parse_paths() {
373-
while read -r line; do
374-
if [[ "$GHE_REMOTE_VERSION" =~ 2.16 && "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.16.23)" ]] || \
375-
[[ "$GHE_REMOTE_VERSION" =~ 2.17 && "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.17.14)" ]] || \
376-
[[ "$GHE_REMOTE_VERSION" =~ 2.18 && "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.18.8)" ]] || \
377-
[[ "$GHE_REMOTE_VERSION" =~ 2.19 && "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.19.3)" ]] && \
378-
(echo "$line" | grep -q "gist"); then
379-
echo "$line"
380-
else
381-
dirname "$line"
382-
fi
383-
done
384-
}
385-
386-
cat $tempdir/*.rsync | sort | uniq > $tempdir/source_routes
387-
(cd $backup_dir/ && find * -mindepth 5 -maxdepth 6 -type d -name \*.git | parse_paths | sort | uniq) > $tempdir/destination_routes
369+
cat $tempdir/*.rsync | uniq | sort | uniq > $tempdir/source_routes
370+
(cd $backup_dir/ && find * -mindepth 5 -maxdepth 6 -type d -name \*.git | fix_paths_for_ghe_version | uniq | sort | uniq) > $tempdir/destination_routes
388371

389372
git --no-pager diff --unified=0 --no-prefix -- $tempdir/source_routes $tempdir/destination_routes || echo "Warning: One or more repository networks and/or gists were not found on the source appliance. Please contact GitHub Enterprise Support for assistance."
390373

share/github-backup-utils/ghe-backup-storage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ bm_end "$(basename $0) - Storage object sync"
141141
if [ -z "$GHE_SKIP_ROUTE_VERIFICATION" ]; then
142142
bm_start "$(basename $0) - Verifying Routes"
143143

144-
cat $tempdir/*.rsync | sort | uniq > $tempdir/source_routes
145-
(cd $backup_dir/ && find * -mindepth 3 -maxdepth 3 -type f -print | sort | uniq) > $tempdir/destination_routes
144+
cat $tempdir/*.rsync | uniq | sort | uniq > $tempdir/source_routes
145+
(cd $backup_dir/ && find * -mindepth 3 -maxdepth 3 -type f -print | uniq | sort | uniq) > $tempdir/destination_routes
146146

147147
git --no-pager diff --unified=0 --no-prefix -- $tempdir/source_routes $tempdir/destination_routes || echo "Warning: One or more storage objects were not found on the source appliance. Please contact GitHub Enterprise Support for assistance."
148148

test/bin/dgit-cluster-backup-routes

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
#!/usr/bin/env bash
22
# Usage: dgit-cluster-backup-routes
3-
# Emulates the remote GitHub enterprise-configure command. Tests use this
4-
# to assert that the command was executed.
3+
# Emulates the remote GitHub dgit-cluster-backup-routes command. Tests use this
4+
# to assert that all repos and gists get backed up.
55
set -e
6-
cat <<EOF
7-
0/nw/01/aa/3f/1234 git-server-fake-uuid
8-
1/nw/23/bb/4c/2345 git-server-fake-uuid1
9-
0/01/aa/3f/gist git-server-fake-uuid2
10-
1/23/bb/4c/gist git-server-fake-uuid
11-
EOF
6+
7+
version() {
8+
echo "${@#v}" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
9+
}
10+
11+
if [ -z "$GHE_REMOTE_VERSION" ]; then
12+
echo GHE_REMOTE_VERSION must be set for this script to work.
13+
exit 1
14+
fi
15+
16+
# The list of gists returned by the source changed in 2.16.23, 2.17.14,
17+
# 2.18.8, and 2.19.3. We need to account for this difference here.
18+
if [[ "$GHE_REMOTE_VERSION" =~ 2.16. && "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.16.23)" ]] || \
19+
[[ "$GHE_REMOTE_VERSION" =~ 2.17. && "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.17.14)" ]] || \
20+
[[ "$GHE_REMOTE_VERSION" =~ 2.18. && "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.18.8)" ]] || \
21+
[[ "$(version $GHE_REMOTE_VERSION)" -ge "$(version 2.19.3)" ]]; then
22+
echo 0/nw/01/aa/3f/1234 git-server-fake-uuid
23+
echo 1/nw/23/bb/4c/2345 git-server-fake-uuid1
24+
echo 0/01/aa/3f/gist/93069ad4c391b6203f183e147d52a97a.git git-server-fake-uuid2
25+
echo 1/23/bb/4c/gist/1234.git git-server-fake-uuid
26+
else
27+
echo 0/nw/01/aa/3f/1234 git-server-fake-uuid
28+
echo 1/nw/23/bb/4c/2345 git-server-fake-uuid1
29+
echo 0/01/aa/3f/gist git-server-fake-uuid2
30+
echo 1/23/bb/4c/gist git-server-fake-uuid
31+
fi

test/test-ghe-backup.sh

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env bash
22
# ghe-backup command tests
33

4+
TESTS_DIR="$PWD/$(dirname "$0")"
45
# Bring in testlib
56
# shellcheck source=test/testlib.sh
6-
. "$(dirname "$0")/testlib.sh"
7+
. "$TESTS_DIR/testlib.sh"
78

89
# Create the backup data dir and fake remote repositories dirs
910
mkdir -p "$GHE_DATA_DIR" "$GHE_REMOTE_DATA_USER_DIR"
@@ -344,3 +345,68 @@ begin_test "ghe-backup missing directories or files on source appliance"
344345
verify_all_backedup_data
345346
)
346347
end_test
348+
349+
# acceptance criteria is less then 2 seconds for 100,000 lines
350+
begin_test "ghe-backup fix_paths_for_ghe_version performance tests - gists"
351+
(
352+
set -e
353+
timeout 2 bash -c "
354+
source '$TESTS_DIR/../share/github-backup-utils/ghe-backup-config'
355+
GHE_REMOTE_VERSION=2.16.23
356+
seq 1 100000 | sed -e 's/$/ gist/' | fix_paths_for_ghe_version | grep -c gist
357+
"
358+
)
359+
end_test
360+
361+
# acceptance criteria is less then 2 seconds for 100,000 lines
362+
begin_test "ghe-backup fix_paths_for_ghe_version performance tests - wikis"
363+
(
364+
set -e
365+
timeout 2 bash -c "
366+
source '$TESTS_DIR/../share/github-backup-utils/ghe-backup-config'
367+
GHE_REMOTE_VERSION=2.16.23
368+
seq 1 100000 | sed -e 's/$/ wiki/' | fix_paths_for_ghe_version | grep -c '^\.$'
369+
"
370+
)
371+
end_test
372+
373+
# check fix_paths_for_ghe_version version thresholds
374+
begin_test "ghe-backup fix_paths_for_ghe_version newer/older"
375+
(
376+
set -e
377+
378+
# modern versions keep foo/gist as foo/gist
379+
for ver in 2.16.23 v2.16.23 v2.17.14 v2.18.8 v2.19.3 v2.20.0 v3.0.0; do
380+
echo "## $ver, not gist"
381+
[ "$(bash -c "
382+
source '$TESTS_DIR/../share/github-backup-utils/ghe-backup-config'
383+
GHE_REMOTE_VERSION=$ver
384+
echo foo/bar | fix_paths_for_ghe_version
385+
")" == "foo" ]
386+
387+
echo "## $ver, gist"
388+
[ "$(bash -c "
389+
source '$TESTS_DIR/../share/github-backup-utils/ghe-backup-config'
390+
GHE_REMOTE_VERSION=$ver
391+
echo foo/gist | fix_paths_for_ghe_version
392+
")" == "foo/gist" ]
393+
done
394+
395+
# old versions change foo/gist to foo
396+
for ver in 1.0.0 bob a.b.c "" 1.2.16 2.0.0 v2.0.0 v2.15.123 v2.16.22 v2.17.13 v2.18.7 v2.19.2; do
397+
echo "## $ver, not gist"
398+
[ "$(bash -c "
399+
source '$TESTS_DIR/../share/github-backup-utils/ghe-backup-config'
400+
GHE_REMOTE_VERSION=$ver
401+
echo foo/bar | fix_paths_for_ghe_version
402+
")" == "foo" ]
403+
404+
echo "## $ver, gist"
405+
[ "$(bash -c "
406+
source '$TESTS_DIR/../share/github-backup-utils/ghe-backup-config'
407+
GHE_REMOTE_VERSION=$ver
408+
echo foo/gist | fix_paths_for_ghe_version
409+
")" == "foo" ]
410+
done
411+
)
412+
end_test

0 commit comments

Comments
 (0)