Skip to content

Commit b82a5b9

Browse files
authored
Merge branch 'master' into dependabot/github_actions/actions/checkout-4
2 parents be270ee + 0aa36fd commit b82a5b9

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

backup.config-example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ GHE_NUM_SNAPSHOTS=10
3232
# disk space validation and software version checks on the backup-host will be disabled.
3333
#GHE_SKIP_CHECKS=false
3434

35+
# Cluster filesystem to check if it's writable as part of ghe-host-check
36+
# By default it is /data/user/tmp but can be updated if needed
37+
#GHE_FILE_SYSTEM_WRITE_CHECK="/data/user/tmp"
38+
3539
# The hostname of the GitHub appliance to restore. If you've set up a separate
3640
# GitHub appliance to act as a standby for recovery, specify its IP or hostname
3741
# here. The host to restore to may also be specified directly when running

bin/ghe-backup

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ if [ -z "$failures" ]; then
377377
else
378378
log_info "Expired and incomplete snapshots to be pruned separately"
379379
fi
380-
else
380+
else
381381
log_info "Skipping pruning snapshots, since some backups failed..."
382382
fi
383383

bin/ghe-host-check

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,33 @@ if [ $rc -ne 0 ]; then
8585
exit $rc
8686
fi
8787

88-
CLUSTER=false
88+
if [ -z "$CLUSTER" ]; then
89+
CLUSTER=false
90+
fi
8991
if ghe-ssh "$host" -- \
9092
"[ -f '$GHE_REMOTE_ROOT_DIR/etc/github/cluster' ]"; then
9193
CLUSTER=true
9294
fi
9395

96+
set +e
9497
# ensure all nodes in the cluster are online/reachable and running the same version
9598
if "$CLUSTER"; then
9699
online_status=$(ghe-ssh "$host" ghe-cluster-host-check)
97100
if [ "$online_status" != "Cluster is ready to configure." ]; then
98-
echo "Error: Not all nodes are online! Please ensure cluster is in a healthy state before using backup-utils." 1>&2
101+
echo "$online_status" 1>&2
102+
log_error "Error: Not all nodes are online! Please ensure cluster is in a healthy state before using backup-utils." 1>&2
99103
exit 1
100104
fi
101105

102106
node_version_list=$(ghe-ssh "$host" ghe-cluster-each -- ghe-version)
103107
distinct_versions=$(echo "$node_version_list" | awk '{split($0, a, ":"); print a[2]}' | awk '{print $4}' | uniq | wc -l)
104108
if [ "$distinct_versions" -ne 1 ]; then
105109
echo "Version mismatch: $node_version_list" 1>&2
106-
echo "Error: Not all nodes are running the same version! Please ensure all nodes are running the same version before using backup-utils." 1>&2
110+
log_error "Error: Not all nodes are running the same version! Please ensure all nodes are running the same version before using backup-utils." 1>&2
107111
exit 1
108112
fi
109113
fi
114+
set -e
110115

111116
version=$(echo "$output" | grep "GitHub Enterprise" | awk '{print $NF}')
112117

@@ -115,6 +120,37 @@ if [ -z "$version" ]; then
115120
exit 2
116121
fi
117122

123+
NON_WRITABLE=""
124+
# ensure all nodes are writable
125+
if [ "$CLUSTER" == "true" ] ; then
126+
if [ -z "$GHE_FILE_SYSTEM_WRITE_CHECK" ]; then
127+
if [ -d "/data/user/tmp" ]; then
128+
WRITE_CHECK_FILE="/data/user/tmp/test-ro-file.txt"
129+
else
130+
WRITE_CHECK_FILE="/tmp/test-ro-file.txt"
131+
fi
132+
else
133+
WRITE_CHECK_FILE="$GHE_FILE_SYSTEM_CHECK/test-ro-file.txt"
134+
fi
135+
136+
# Iterate through each node in the cluster
137+
nodes=$(ghe-ssh "$host" ghe-cluster-nodes)
138+
for node in $nodes; do
139+
if ! echo "set -o pipefail; ssh $node -- 'touch $WRITE_CHECK_FILE && rm $WRITE_CHECK_FILE'" | ghe-ssh "$host" /bin/bash; then
140+
echo "File system is not writeable or no permission on $node" 1>&2
141+
NON_WRITABLE+="$node "
142+
fi || true
143+
done
144+
# Display the comma-separated list of non-writable nodes
145+
if [ -n "$NON_WRITABLE" ]; then
146+
NON_WRITABLE=$(echo "$NON_WRITABLE" | sed 's/ /, /g; s/, $//')
147+
log_error "Error: Following nodes are non-writable - $NON_WRITABLE. Please make sure the filesystem for all GHES nodes are writable." 1>&2
148+
exit 1
149+
else
150+
log_info "All nodes are writable."
151+
fi
152+
fi
153+
118154
# Block restoring snapshots to older releases of GitHub Enterprise Server
119155
if [ -n "$GHE_RESTORE_SNAPSHOT_PATH" ]; then
120156
snapshot_version=$(cat $GHE_RESTORE_SNAPSHOT_PATH/version)
@@ -177,7 +213,7 @@ SKIP_MSG
177213

178214
#Display dir requirements for repositories and mysql
179215
echo -e "\nChecking host for sufficient space for a backup..."
180-
available_space=$(df -B 1k $GHE_DATA_DIR | awk 'END{printf "%.0f", $4 * 1024}')
216+
available_space=$(df -B 1k $GHE_DATA_DIR | awk 'END{printf "%.0f", $4 * 1024}')
181217
echo " We recommend allocating at least 5x the amount of storage allocated to the primary GitHub appliance for historical snapshots and growth over time."
182218

183219
repos_disk_size=$(transfer_size repositories /tmp)

test/test-ghe-host-check.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,18 @@ begin_test "ghe-host-check blocks restore to old release"
123123
! GHE_TEST_REMOTE_VERSION=$bu_version_major.$((bu_version_minor-1)).$bu_version_patch ghe-restore -v
124124
)
125125
end_test
126+
127+
# Check ghe-host-check detects RO file system
128+
begin_test "ghe-host-check fails when encountering RO file-system"
129+
(
130+
set -e
131+
132+
ghe-ssh "$GHE_HOSTNAME" -- 'mkdir -p "~/tmp"'
133+
# Remove write access in ~/tmp
134+
ghe-ssh "$GHE_HOSTNAME" -- 'chmod a-w -R "~/tmp"'
135+
136+
# File creation fails for CLUSTER
137+
! WRITE_CHECK_FILE="$HOME/tmp/test" CLUSTER=true GHE_ALLOW_REPLICA_BACKUP=no ghe-host-check
138+
WRITE_CHECK_FILE="$HOME/tmp/test" CLUSTER=false GHE_ALLOW_REPLICA_BACKUP=no ghe-host-check
139+
)
140+
end_test

0 commit comments

Comments
 (0)