Skip to content

Commit cf39b5b

Browse files
authored
Merge pull request #1070 from github/3.8.1-patch
3.8.1 patch
2 parents 5484cf0 + c216f2f commit cf39b5b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+730
-259
lines changed

backup.config-example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ GHE_NUM_SNAPSHOTS=10
4242
#
4343
#GHE_EXTRA_RSYNC_OPTS=""
4444

45+
46+
# If set to 'yes', logging output will be colorized.
47+
#
48+
#OUTPUT_COLOR=no
49+
4550
# If set to 'no', GHE_DATA_DIR will not be created automatically
4651
# and restore/backup will exit 8
4752
#

bin/ghe-backup

Lines changed: 63 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,18 @@ trap 'rm -rf src dest1 dest2' EXIT
6767
mkdir -p src
6868
touch src/testfile
6969
if ! ln -s /data/does/not/exist/hooks/ src/ >/dev/null 2>&1; then
70-
echo "Error: the filesystem containing $GHE_DATA_DIR does not support symbolic links." 1>&2
71-
echo "Git repositories contain symbolic links that need to be preserved during a backup." 1>&2
70+
log_error "Error: the filesystem containing $GHE_DATA_DIR does not support symbolic links. \nGit repositories contain symbolic links that need to be preserved during a backup." 1>&2
7271
exit 1
7372
fi
7473

7574
if ! output=$(rsync -a src/ dest1 2>&1 && rsync -av src/ --link-dest=../dest1 dest2 2>&1); then
76-
echo "Error: rsync encountered an error that could indicate a problem with permissions," 1>&2
77-
echo "hard links, symbolic links, or another issue that may affect backups." 1>&2
75+
log_error "Error: rsync encountered an error that could indicate a problem with permissions,\n hard links, symbolic links, or another issue that may affect backups." 1>&2
7876
echo "$output"
7977
exit 1
8078
fi
8179

8280
if [ "$(ls -il dest1/testfile | awk '{ print $1 }')" != "$(ls -il dest2/testfile | awk '{ print $1 }')" ]; then
83-
echo "Error: the filesystem containing $GHE_DATA_DIR does not support hard links." 1>&2
84-
echo "Backup Utilities use hard links to store backup data efficiently." 1>&2
81+
log_error "Error: the filesystem containing $GHE_DATA_DIR does not support hard links.\n Backup Utilities use hard links to store backup data efficiently." 1>&2
8582
exit 1
8683
fi
8784
rm -rf src dest1 dest2
@@ -122,9 +119,8 @@ ghe_restore_check
122119

123120
# Check to see if there is a running backup
124121
if [ -h ../in-progress ]; then
125-
echo "Error: detected a backup already in progress from a previous version of ghe-backup." 1>&2
126-
echo "If there is no backup in progress anymore, please remove" 1>&2
127-
echo "the $GHE_DATA_DIR/in-progress file and try again." 1>&2
122+
123+
log_error "Error: detected a backup already in progress from a previous version of ghe-backup. \nIf there is no backup in progress anymore, please remove \nthe $GHE_DATA_DIR/in-progress file." 1>&2
128124
exit 1
129125
fi
130126

@@ -137,20 +133,16 @@ if [ -f ../in-progress ]; then
137133
# will clean up the failed backup.
138134
unlink ../in-progress
139135
else
140-
echo "Error: A backup of $GHE_HOSTNAME may still be running on PID $pid." 1>&2
141-
echo 1>&2
142-
echo " If PID $pid is not a process related to the backup utilities, please remove" 1>&2
143-
echo " the $GHE_DATA_DIR/in-progress file and try again." 1>&2
136+
log_error "Error: A backup of $GHE_HOSTNAME may still be running on PID $pid. \nIf PID $pid is not a process related to the backup utilities, please remove \nthe $GHE_DATA_DIR/in-progress file and try again." 1>&2
144137
exit 1
145138
fi
146139
fi
147140

148141
echo "$GHE_SNAPSHOT_TIMESTAMP $$" > ../in-progress
149142
echo "$GHE_SNAPSHOT_TIMESTAMP $$" > ${GHE_DATA_DIR}/in-progress-backup
150143

151-
START_TIME=$(date +%s)
152-
echo 'Start time:' $START_TIME
153-
echo "Starting backup of $GHE_HOSTNAME with backup-utils v$BACKUP_UTILS_VERSION in snapshot $GHE_SNAPSHOT_TIMESTAMP"
144+
log_info "Starting backup of $GHE_HOSTNAME with backup-utils v$BACKUP_UTILS_VERSION in snapshot $GHE_SNAPSHOT_TIMESTAMP"
145+
154146

155147
# Perform a host connection check and establish the remote appliance version.
156148
# The version is available in the GHE_REMOTE_VERSION variable and also written
@@ -162,6 +154,30 @@ if [ -n "$GHE_ALLOW_REPLICA_BACKUP" ]; then
162154
echo "Warning: backing up a high availability replica may result in inconsistent or unreliable backups."
163155
fi
164156

157+
# Output system information of the backup host
158+
159+
# If /etc/issue.net exists, use it to get the OS version
160+
if [ -f /etc/issue.net ]; then
161+
echo "Running on: $(cat /etc/issue.net)"
162+
else
163+
echo "Running on: Unknown OS"
164+
fi
165+
166+
# If nproc command exists, use it to get the number of CPUs
167+
if command -v nproc >/dev/null 2>&1; then
168+
echo "CPUs: $(nproc)"
169+
else
170+
echo "CPUs: Unknown"
171+
fi
172+
173+
# If the free command exists, use it to get the memory details
174+
if command -v free >/dev/null 2>&1; then
175+
echo "Memory $(free -m | grep '^Mem:' | awk '{print "total/used/free+share/buff/cache: " $2 "/" $3 "/" $4 "+" $5 "/" $6 "/" $7}')"
176+
else
177+
echo "Memory: Unknown"
178+
fi
179+
180+
165181
# Log backup start message in /var/log/syslog on remote instance
166182
ghe_remote_logger "Starting backup from $(hostname) with backup-utils v$BACKUP_UTILS_VERSION in snapshot $GHE_SNAPSHOT_TIMESTAMP ..."
167183

@@ -173,19 +189,22 @@ echo "$GHE_BACKUP_STRATEGY" > strategy
173189
# Create benchmark file
174190
bm_init > /dev/null
175191

192+
START_TIME=$(date +%s)
193+
log_info "Starting backup of $GHE_HOSTNAME with backup-utils v$BACKUP_UTILS_VERSION"
194+
176195
ghe-backup-store-version ||
177-
echo "Warning: storing backup-utils version remotely failed."
196+
log_warn "Warning: storing backup-utils version remotely failed."
178197

179-
echo "Backing up GitHub settings ..."
198+
log_info "Backing up GitHub settings ..."
180199
ghe-backup-settings || failures="$failures settings"
181200

182-
echo "Backing up SSH authorized keys ..."
201+
log_info "Backing up SSH authorized keys ..."
183202
bm_start "ghe-export-authorized-keys"
184203
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-export-authorized-keys' > authorized-keys.json ||
185204
failures="$failures authorized-keys"
186205
bm_end "ghe-export-authorized-keys"
187206

188-
echo "Backing up SSH host keys ..."
207+
log_info "Backing up SSH host keys ..."
189208
bm_start "ghe-export-ssh-host-keys"
190209
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-export-ssh-host-keys' > ssh-host-keys.tar ||
191210
failures="$failures ssh-host-keys"
@@ -194,45 +213,52 @@ bm_end "ghe-export-ssh-host-keys"
194213
ghe-backup-mysql || failures="$failures mysql"
195214

196215
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
197-
echo "Backing up MSSQL databases ..."
216+
log_info "Backing up MSSQL databases ..."
198217
ghe-backup-mssql 1>&3 || failures="$failures mssql"
199218

200-
echo "Backing up Actions data ..."
219+
log_info "Backing up Actions data ..."
201220
ghe-backup-actions 1>&3 || failures="$failures actions"
202221
fi
203222

204223
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.minio.enabled'; then
205-
echo "Backing up Minio data ..."
224+
log_info "Backing up Minio data ..."
206225
ghe-backup-minio 1>&3 || failures="$failures minio"
207226
fi
208227

228+
cmd_title=$(log_info "Backing up Redis database ...")
209229
commands=("
210-
echo \"Backing up Redis database ...\"
230+
echo \"$cmd_title\"
211231
ghe-backup-redis > redis.rdb || printf %s \"redis \" >> \"$failures_file\"")
212232

233+
cmd_title=$(log_info "Backing up audit log ...")
213234
commands+=("
214-
echo \"Backing up audit log ...\"
235+
echo \"$cmd_title\"
215236
ghe-backup-es-audit-log || printf %s \"audit-log \" >> \"$failures_file\"")
216237

238+
cmd_title=$(log_info "Backing up Git repositories ...")
217239
commands+=("
218-
echo \"Backing up Git repositories ...\"
240+
echo \"$cmd_title\"
219241
ghe-backup-repositories || printf %s \"repositories \" >> \"$failures_file\"")
220242

243+
cmd_title=$(log_info "Backing up GitHub Pages artifacts ...")
221244
commands+=("
222-
echo \"Backing up GitHub Pages artifacts ...\"
245+
echo \"$cmd_title\"
223246
ghe-backup-pages || printf %s \"pages \" >> \"$failures_file\"")
224247

248+
cmd_title=$(log_info "Backing up storage data ...")
225249
commands+=("
226-
echo \"Backing up storage data ...\"
250+
echo \"$cmd_title\"
227251
ghe-backup-storage || printf %s \"storage \" >> \"$failures_file\"")
228252

253+
cmd_title=$(log_info "Backing up custom Git hooks ...")
229254
commands+=("
230-
echo \"Backing up custom Git hooks ...\"
255+
echo \"$cmd_title\"
231256
ghe-backup-git-hooks || printf %s \"git-hooks \" >> \"$failures_file\"")
232257

233258
if [ "$GHE_BACKUP_STRATEGY" = "rsync" ]; then
259+
cmd_title=$(log_info "Backing up Elasticsearch indices ...")
234260
commands+=("
235-
echo \"Backing up Elasticsearch indices ...\"
261+
echo \"$cmd_title\"
236262
ghe-backup-es-rsync || printf %s \"elasticsearch \" >> \"$failures_file\"")
237263
fi
238264

@@ -250,6 +276,7 @@ fi
250276

251277
# git fsck repositories after the backup
252278
if [ "$GHE_BACKUP_FSCK" = "yes" ]; then
279+
log_info "Running git fsck on repositories ..."
253280
ghe-backup-fsck $GHE_SNAPSHOT_DIR || failures="$failures fsck"
254281
fi
255282

@@ -265,26 +292,25 @@ if [ -z "$failures" ]; then
265292
ghe-prune-snapshots
266293
fi
267294

268-
END_TIME=$(date +%s)
269-
echo 'End time:' $END_TIME
270-
echo 'Runtime:' $(($END_TIME - $START_TIME)) 'seconds'
271-
272-
echo "Completed backup of $GHE_HOSTNAME in snapshot $GHE_SNAPSHOT_TIMESTAMP at $(date +"%H:%M:%S")"
295+
log_info "Completed backup of $GHE_HOSTNAME in snapshot $GHE_SNAPSHOT_TIMESTAMP at $(date +"%H:%M:%S")"
273296

274297
# Exit non-zero and list the steps that failed.
275298
if [ -z "$failures" ]; then
276299
ghe_remote_logger "Completed backup from $(hostname) / snapshot $GHE_SNAPSHOT_TIMESTAMP successfully."
277300
else
278301
steps="$(echo $failures | sed 's/ /, /g')"
279302
ghe_remote_logger "Completed backup from $(hostname) / snapshot $GHE_SNAPSHOT_TIMESTAMP with failures: ${steps}."
280-
echo "Error: Snapshot incomplete. Some steps failed: ${steps}. "
303+
log_error "Error: Snapshot incomplete. Some steps failed: ${steps}. "
281304
exit 1
282305
fi
283306

284307
# Detect if the created backup contains any leaked ssh keys
285-
echo "Checking for leaked ssh keys ..."
308+
log_info "Checking for leaked ssh keys ..."
286309
ghe-detect-leaked-ssh-keys -s "$GHE_SNAPSHOT_DIR" || true
287310

311+
END_TIME=$(date +%s)
312+
log_info "Runtime: $((${END_TIME} - ${START_TIME})) seconds"
313+
log_info "Backup of $GHE_HOSTNAME finished."
288314
# Make sure we exit zero after the conditional
289315
true
290316

bin/ghe-host-check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ if "$CLUSTER"; then
9797
distinct_versions=$(echo "$node_version_list" | awk '{split($0, a, ":"); print a[2]}' | awk '{print $4}' | uniq | wc -l)
9898
if [ "$distinct_versions" -ne 1 ]; then
9999
echo "$node_version_list" 1>&2
100-
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
100+
echo "Error: Not all nodes are running the same version! Please ensure all nodes are running the same version before using backup-utils." 1>&3
101101
exit 1
102102
fi
103103
fi

0 commit comments

Comments
 (0)