Skip to content

Commit 79339d7

Browse files
gamefiendhubot
authored andcommitted
Merge pull request #268 from github/improved-logging
Prepend colorized input to logging data
1 parent 5484cf0 commit 79339d7

Some content is hidden

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

50 files changed

+363
-234
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: 39 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
@@ -173,19 +165,22 @@ echo "$GHE_BACKUP_STRATEGY" > strategy
173165
# Create benchmark file
174166
bm_init > /dev/null
175167

168+
START_TIME=$(date +%s)
169+
log_info "Starting backup of $GHE_HOSTNAME with backup-utils v$BACKUP_UTILS_VERSION"
170+
176171
ghe-backup-store-version ||
177-
echo "Warning: storing backup-utils version remotely failed."
172+
log_warn "Warning: storing backup-utils version remotely failed."
178173

179-
echo "Backing up GitHub settings ..."
174+
log_info "Backing up GitHub settings ..."
180175
ghe-backup-settings || failures="$failures settings"
181176

182-
echo "Backing up SSH authorized keys ..."
177+
log_info "Backing up SSH authorized keys ..."
183178
bm_start "ghe-export-authorized-keys"
184179
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-export-authorized-keys' > authorized-keys.json ||
185180
failures="$failures authorized-keys"
186181
bm_end "ghe-export-authorized-keys"
187182

188-
echo "Backing up SSH host keys ..."
183+
log_info "Backing up SSH host keys ..."
189184
bm_start "ghe-export-ssh-host-keys"
190185
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-export-ssh-host-keys' > ssh-host-keys.tar ||
191186
failures="$failures ssh-host-keys"
@@ -194,45 +189,52 @@ bm_end "ghe-export-ssh-host-keys"
194189
ghe-backup-mysql || failures="$failures mysql"
195190

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

200-
echo "Backing up Actions data ..."
195+
log_info "Backing up Actions data ..."
201196
ghe-backup-actions 1>&3 || failures="$failures actions"
202197
fi
203198

204199
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.minio.enabled'; then
205-
echo "Backing up Minio data ..."
200+
log_info "Backing up Minio data ..."
206201
ghe-backup-minio 1>&3 || failures="$failures minio"
207202
fi
208203

204+
cmd_title=$(log_info "Backing up Redis database ...")
209205
commands=("
210-
echo \"Backing up Redis database ...\"
206+
echo \"$cmd_title\"
211207
ghe-backup-redis > redis.rdb || printf %s \"redis \" >> \"$failures_file\"")
212208

209+
cmd_title=$(log_info "Backing up audit log ...")
213210
commands+=("
214-
echo \"Backing up audit log ...\"
211+
echo \"$cmd_title\"
215212
ghe-backup-es-audit-log || printf %s \"audit-log \" >> \"$failures_file\"")
216213

214+
cmd_title=$(log_info "Backing up Git repositories ...")
217215
commands+=("
218-
echo \"Backing up Git repositories ...\"
216+
echo \"$cmd_title\"
219217
ghe-backup-repositories || printf %s \"repositories \" >> \"$failures_file\"")
220218

219+
cmd_title=$(log_info "Backing up GitHub Pages artifacts ...")
221220
commands+=("
222-
echo \"Backing up GitHub Pages artifacts ...\"
221+
echo \"$cmd_title\"
223222
ghe-backup-pages || printf %s \"pages \" >> \"$failures_file\"")
224223

224+
cmd_title=$(log_info "Backing up storage data ...")
225225
commands+=("
226-
echo \"Backing up storage data ...\"
226+
echo \"$cmd_title\"
227227
ghe-backup-storage || printf %s \"storage \" >> \"$failures_file\"")
228228

229+
cmd_title=$(log_info "Backing up custom Git hooks ...")
229230
commands+=("
230-
echo \"Backing up custom Git hooks ...\"
231+
echo \"$cmd_title\"
231232
ghe-backup-git-hooks || printf %s \"git-hooks \" >> \"$failures_file\"")
232233

233234
if [ "$GHE_BACKUP_STRATEGY" = "rsync" ]; then
235+
cmd_title=$(log_info "Backing up Elasticsearch indices ...")
234236
commands+=("
235-
echo \"Backing up Elasticsearch indices ...\"
237+
echo \"$cmd_title\"
236238
ghe-backup-es-rsync || printf %s \"elasticsearch \" >> \"$failures_file\"")
237239
fi
238240

@@ -250,6 +252,7 @@ fi
250252

251253
# git fsck repositories after the backup
252254
if [ "$GHE_BACKUP_FSCK" = "yes" ]; then
255+
log_info "Running git fsck on repositories ..."
253256
ghe-backup-fsck $GHE_SNAPSHOT_DIR || failures="$failures fsck"
254257
fi
255258

@@ -265,26 +268,25 @@ if [ -z "$failures" ]; then
265268
ghe-prune-snapshots
266269
fi
267270

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")"
271+
log_info "Completed backup of $GHE_HOSTNAME in snapshot $GHE_SNAPSHOT_TIMESTAMP at $(date +"%H:%M:%S")"
273272

274273
# Exit non-zero and list the steps that failed.
275274
if [ -z "$failures" ]; then
276275
ghe_remote_logger "Completed backup from $(hostname) / snapshot $GHE_SNAPSHOT_TIMESTAMP successfully."
277276
else
278277
steps="$(echo $failures | sed 's/ /, /g')"
279278
ghe_remote_logger "Completed backup from $(hostname) / snapshot $GHE_SNAPSHOT_TIMESTAMP with failures: ${steps}."
280-
echo "Error: Snapshot incomplete. Some steps failed: ${steps}. "
279+
log_error "Error: Snapshot incomplete. Some steps failed: ${steps}. "
281280
exit 1
282281
fi
283282

284283
# Detect if the created backup contains any leaked ssh keys
285-
echo "Checking for leaked ssh keys ..."
284+
log_info "Checking for leaked ssh keys ..."
286285
ghe-detect-leaked-ssh-keys -s "$GHE_SNAPSHOT_DIR" || true
287286

287+
END_TIME=$(date +%s)
288+
log_info "Runtime: $((${END_TIME} - ${START_TIME})) seconds"
289+
log_info "Backup of $GHE_HOSTNAME finished."
288290
# Make sure we exit zero after the conditional
289291
true
290292

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)