Skip to content

Commit e453b40

Browse files
authored
Merge pull request #268 from github/improved-logging
Prepend colorized input to logging data
2 parents c1a4f1d + 66dcf2d commit e453b40

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
@@ -68,21 +68,18 @@ trap 'rm -rf src dest1 dest2' EXIT
6868
mkdir -p src
6969
touch src/testfile
7070
if ! ln -s /data/does/not/exist/hooks/ src/ >/dev/null 2>&1; then
71-
echo "Error: the filesystem containing $GHE_DATA_DIR does not support symbolic links." 1>&2
72-
echo "Git repositories contain symbolic links that need to be preserved during a backup." 1>&2
71+
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
7372
exit 1
7473
fi
7574

7675
if ! output=$(rsync -a src/ dest1 2>&1 && rsync -av src/ --link-dest=../dest1 dest2 2>&1); then
77-
echo "Error: rsync encountered an error that could indicate a problem with permissions," 1>&2
78-
echo "hard links, symbolic links, or another issue that may affect backups." 1>&2
76+
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
7977
echo "$output"
8078
exit 1
8179
fi
8280

8381
if [ "$(ls -il dest1/testfile | awk '{ print $1 }')" != "$(ls -il dest2/testfile | awk '{ print $1 }')" ]; then
84-
echo "Error: the filesystem containing $GHE_DATA_DIR does not support hard links." 1>&2
85-
echo "Backup Utilities use hard links to store backup data efficiently." 1>&2
82+
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
8683
exit 1
8784
fi
8885
rm -rf src dest1 dest2
@@ -123,9 +120,8 @@ ghe_restore_check
123120

124121
# Check to see if there is a running backup
125122
if [ -h ../in-progress ]; then
126-
echo "Error: detected a backup already in progress from a previous version of ghe-backup." 1>&2
127-
echo "If there is no backup in progress anymore, please remove" 1>&2
128-
echo "the $GHE_DATA_DIR/in-progress file and try again." 1>&2
123+
124+
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
129125
exit 1
130126
fi
131127

@@ -138,20 +134,16 @@ if [ -f ../in-progress ]; then
138134
# will clean up the failed backup.
139135
unlink ../in-progress
140136
else
141-
echo "Error: A backup of $GHE_HOSTNAME may still be running on PID $pid." 1>&2
142-
echo 1>&2
143-
echo " If PID $pid is not a process related to the backup utilities, please remove" 1>&2
144-
echo " the $GHE_DATA_DIR/in-progress file and try again." 1>&2
137+
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
145138
exit 1
146139
fi
147140
fi
148141

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

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

156148
# Perform a host connection check and establish the remote appliance version.
157149
# The version is available in the GHE_REMOTE_VERSION variable and also written
@@ -174,19 +166,22 @@ echo "$GHE_BACKUP_STRATEGY" > strategy
174166
# Create benchmark file
175167
bm_init > /dev/null
176168

169+
START_TIME=$(date +%s)
170+
log_info "Starting backup of $GHE_HOSTNAME with backup-utils v$BACKUP_UTILS_VERSION"
171+
177172
ghe-backup-store-version ||
178-
echo "Warning: storing backup-utils version remotely failed."
173+
log_warn "Warning: storing backup-utils version remotely failed."
179174

180-
echo "Backing up GitHub settings ..."
175+
log_info "Backing up GitHub settings ..."
181176
ghe-backup-settings || failures="$failures settings"
182177

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

189-
echo "Backing up SSH host keys ..."
184+
log_info "Backing up SSH host keys ..."
190185
bm_start "ghe-export-ssh-host-keys"
191186
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-export-ssh-host-keys' > ssh-host-keys.tar ||
192187
failures="$failures ssh-host-keys"
@@ -195,45 +190,52 @@ bm_end "ghe-export-ssh-host-keys"
195190
ghe-backup-mysql || failures="$failures mysql"
196191

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

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

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

205+
cmd_title=$(log_info "Backing up Redis database ...")
210206
commands=("
211-
echo \"Backing up Redis database ...\"
207+
echo \"$cmd_title\"
212208
ghe-backup-redis > redis.rdb || printf %s \"redis \" >> \"$failures_file\"")
213209

210+
cmd_title=$(log_info "Backing up audit log ...")
214211
commands+=("
215-
echo \"Backing up audit log ...\"
212+
echo \"$cmd_title\"
216213
ghe-backup-es-audit-log || printf %s \"audit-log \" >> \"$failures_file\"")
217214

215+
cmd_title=$(log_info "Backing up Git repositories ...")
218216
commands+=("
219-
echo \"Backing up Git repositories ...\"
217+
echo \"$cmd_title\"
220218
ghe-backup-repositories || printf %s \"repositories \" >> \"$failures_file\"")
221219

220+
cmd_title=$(log_info "Backing up GitHub Pages artifacts ...")
222221
commands+=("
223-
echo \"Backing up GitHub Pages artifacts ...\"
222+
echo \"$cmd_title\"
224223
ghe-backup-pages || printf %s \"pages \" >> \"$failures_file\"")
225224

225+
cmd_title=$(log_info "Backing up storage data ...")
226226
commands+=("
227-
echo \"Backing up storage data ...\"
227+
echo \"$cmd_title\"
228228
ghe-backup-storage || printf %s \"storage \" >> \"$failures_file\"")
229229

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

234235
if [ "$GHE_BACKUP_STRATEGY" = "rsync" ]; then
236+
cmd_title=$(log_info "Backing up Elasticsearch indices ...")
235237
commands+=("
236-
echo \"Backing up Elasticsearch indices ...\"
238+
echo \"$cmd_title\"
237239
ghe-backup-es-rsync || printf %s \"elasticsearch \" >> \"$failures_file\"")
238240
fi
239241

@@ -251,6 +253,7 @@ fi
251253

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

@@ -266,26 +269,25 @@ if [ -z "$failures" ]; then
266269
ghe-prune-snapshots
267270
fi
268271

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

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

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

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

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)