Skip to content

Commit 9c779e8

Browse files
authored
Merge pull request #280 from github/progress-indicator
Progress Indicator
2 parents ecd4404 + 5180d0c commit 9c779e8

File tree

8 files changed

+278
-9
lines changed

8 files changed

+278
-9
lines changed

bin/ghe-backup

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,21 @@ while true; do
3737
esac
3838
done
3939

40+
4041
export CALLING_SCRIPT="ghe-backup"
42+
4143
# Bring in the backup configuration
4244
# shellcheck source=share/github-backup-utils/ghe-backup-config
4345
. "$( dirname "${BASH_SOURCE[0]}" )/../share/github-backup-utils/ghe-backup-config"
4446

47+
# Setup progress tracking
48+
init-progress
49+
export PROGRESS_TYPE="Backup"
50+
echo "$PROGRESS_TYPE" > /tmp/backup-utils-progress-type
51+
export PROGRESS=0 # Used to track progress of backup
52+
echo "$PROGRESS" > /tmp/backup-utils-progress
53+
export PROGRESS_TOTAL=18 # Maximum number of steps in backup
54+
4555
# Check to make sure moreutils parallel is installed and working properly
4656
ghe_parallel_check
4757

@@ -121,7 +131,7 @@ ghe_restore_check
121131
# Check to see if there is a running backup
122132
if [ -h ../in-progress ]; then
123133

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
134+
log_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." >&2
125135
exit 1
126136
fi
127137

@@ -306,6 +316,7 @@ else
306316
steps="${failures// /, }"
307317
ghe_remote_logger "Completed backup from $(hostname) / snapshot $GHE_SNAPSHOT_TIMESTAMP with failures: ${steps}."
308318
log_error "Error: Snapshot incomplete. Some steps failed: ${steps}. "
319+
ghe_backup_finished
309320
exit 1
310321
fi
311322

bin/ghe-backup-progress

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: ghe-backup-progress [--once]
3+
#/ Tracks the completed steps of a backup or restore operation.
4+
#/
5+
#/ By default the progress is printed every continuously or until a key is pressed.
6+
#/ Use the --once option to print the current progress once and exit.
7+
#/
8+
#/ Options:
9+
#/ --once Don't loop, just print the current progress once.
10+
#
11+
set -e
12+
13+
while true; do
14+
case "$1" in
15+
-o|--once)
16+
ONCE=1
17+
shift
18+
;;
19+
-h|--help)
20+
export GHE_SHOW_HELP=true
21+
shift
22+
;;
23+
-*)
24+
echo "Unknown option: $1" >&2
25+
exit 1
26+
;;
27+
*)
28+
break
29+
;;
30+
esac
31+
done
32+
33+
check_for_progress_file() {
34+
if [ ! -f /tmp/backup-utils-progress-info ]; then
35+
echo "No progress file found. Has a backup or restore been started?"
36+
exit 1
37+
fi
38+
}
39+
40+
if [ -n "$ONCE" ]; then
41+
check_for_progress_file
42+
cat /tmp/backup-utils-progress-info
43+
else
44+
check_for_progress_file
45+
clear
46+
cat /tmp/backup-utils-progress-info
47+
while true; do
48+
if read -r -t 1 -n 1; then
49+
clear
50+
exit ;
51+
else
52+
clear
53+
cat /tmp/backup-utils-progress-info
54+
fi
55+
done
56+
fi

bin/ghe-restore

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ while true; do
8686
esac
8787
done
8888

89+
90+
8991
start_cron () {
9092
log_info "Starting cron ..."
9193
if $CLUSTER; then
@@ -164,6 +166,10 @@ cleanup_cluster_nodes() {
164166
# shellcheck source=share/github-backup-utils/ghe-backup-config
165167
. "$( dirname "${BASH_SOURCE[0]}" )/../share/github-backup-utils/ghe-backup-config"
166168

169+
170+
171+
172+
167173
# Check to make sure moreutils parallel is installed and working properly
168174
ghe_parallel_check
169175

@@ -265,6 +271,48 @@ if is_external_database_snapshot && ! $instance_configured && ! $FORCE; then
265271

266272
prompt_for_confirmation "Please confirm this before continuing."
267273
fi
274+
# Calculate the actual amounts of steps in the restore process
275+
# taking into account the options passed to the script and the appliance configuration
276+
# calculate restore steps
277+
OPTIONAL_STEPS=0
278+
# Cluster restores add an additional step
279+
if $CLUSTER ; then
280+
OPTIONAL_STEPS=$((OPTIONAL_STEPS + 1))
281+
fi
282+
# Restoring UUID
283+
if [ -s "$GHE_RESTORE_SNAPSHOT_PATH/uuid" ] && ! $CLUSTER; then
284+
OPTIONAL_STEPS=$((OPTIONAL_STEPS + 1))
285+
fi
286+
# Restoring Actions
287+
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
288+
OPTIONAL_STEPS=$((OPTIONAL_STEPS + 1))
289+
fi
290+
# Restoring minio
291+
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.minio.enabled'; then
292+
OPTIONAL_STEPS=$((OPTIONAL_STEPS + 1))
293+
fi
294+
# Restoring Elasticsearch
295+
if ! $CLUSTER && [ -d "$GHE_RESTORE_SNAPSHOT_PATH/elasticsearch" ]; then
296+
OPTIONAL_STEPS=$((OPTIONAL_STEPS + 1))
297+
fi
298+
# Restoring audit log
299+
if $CLUSTER || [ "$(version "$GHE_REMOTE_VERSION")" -ge "$(version 2.12.9)" ]; then
300+
if [[ "$GHE_RESTORE_SKIP_AUDIT_LOG" != "yes" ]]; then
301+
OPTIONAL_STEPS=$((OPTIONAL_STEPS + 1))
302+
fi
303+
fi
304+
# Replica cleanup
305+
if ! $CLUSTER && $instance_configured; then
306+
OPTIONAL_STEPS=$((OPTIONAL_STEPS + 1))
307+
fi
308+
# Maximum restore steps
309+
export PROGRESS_TOTAL=$((OPTIONAL_STEPS + 6))
310+
311+
init-progress
312+
export PROGRESS_TYPE="Restore"
313+
echo "$PROGRESS_TYPE" > /tmp/backup-utils-progress-type
314+
export PROGRESS=0 # Used to track progress of restore
315+
echo "$PROGRESS" > /tmp/backup-utils-progress
268316

269317
# Log restore start message locally and in /var/log/syslog on remote instance
270318
START_TIME=$(date +%s)
@@ -343,10 +391,11 @@ log_warn "Warning: storing backup-utils version remotely failed."
343391
# Stop cron and timerd, as scheduled jobs may disrupt the restore process.
344392
log_info "Stopping cron and github-timerd ..."
345393
if $CLUSTER; then
394+
bm_start "$(basename $0) - Stopping cron and github-timerd on cluster"
346395
if ! ghe-ssh "$GHE_HOSTNAME" -- "ghe-cluster-each -- sudo service cron stop"; then
347396
log_warn "Failed to stop cron on one or more nodes" 1>&3
348397
fi
349-
398+
bm_end "$(basename $0) - Stopping cron and github-timerd on cluster"
350399
if [ "$GHE_VERSION_MAJOR" -eq "3" ]; then
351400
if ghe-ssh "$GHE_HOSTNAME" -- "systemctl -q is-active nomad && nomad job status --short github-timerd &>/dev/null"; then
352401
if ! ghe-ssh "$GHE_HOSTNAME" -- "sudo nomad stop github-timerd 1>/dev/null"; then
@@ -358,11 +407,14 @@ if $CLUSTER; then
358407
log_warn "Failed to stop github-timerd on one or more nodes" 1>&3
359408
fi
360409
fi
410+
361411
else
412+
bm_start "$(basename $0) - Stopping cron and github-timerd"
413+
echo "$(basename $0) - Stopping cron and github-timerd"
362414
if ! ghe-ssh "$GHE_HOSTNAME" -- "sudo service cron stop"; then
363415
log_warn "Failed to stop cron" 1>&3
364416
fi
365-
417+
bm_end "$(basename $0) - Stopping cron and github-timerd"
366418
if [ "$GHE_VERSION_MAJOR" -eq "3" ]; then
367419
if ghe-ssh "$GHE_HOSTNAME" -- "systemctl -q is-active nomad && nomad job status --short github-timerd &>/dev/null"; then
368420
if ! ghe-ssh "$GHE_HOSTNAME" -- "sudo nomad stop github-timerd 1>/dev/null"; then
@@ -374,9 +426,11 @@ else
374426
log_warn "Failed to stop github-timerd" 1>&3
375427
fi
376428
fi
429+
377430
fi
378431
CRON_RUNNING=false
379432

433+
380434
# Restore settings and license if restoring to an unconfigured appliance or when
381435
# specified manually.
382436
if $RESTORE_SETTINGS; then
@@ -394,11 +448,15 @@ fi
394448
# Restore UUID if present and not restoring to cluster.
395449
if [ -s "$GHE_RESTORE_SNAPSHOT_PATH/uuid" ] && ! $CLUSTER; then
396450
log_info "Restoring UUID ..."
451+
452+
bm_start "$(basename $0) - Restore UUID"
397453
ghe-ssh "$GHE_HOSTNAME" -- "sudo sponge '$GHE_REMOTE_DATA_USER_DIR/common/uuid' 2>/dev/null" <"$GHE_RESTORE_SNAPSHOT_PATH/uuid"
398454
ghe-ssh "$GHE_HOSTNAME" -- "sudo systemctl stop consul" || true
399455
ghe-ssh "$GHE_HOSTNAME" -- "sudo rm -rf /data/user/consul/raft"
456+
bm_end "$(basename $0) - Restore UUID"
400457
fi
401458

459+
402460
if is_external_database_snapshot; then
403461
appliance_strategy="external"
404462
backup_snapshot_strategy="external"
@@ -448,7 +506,7 @@ fi
448506
cmd_title=$(log_info "Restoring Redis database ...")
449507
commands=("
450508
echo \"$cmd_title\"
451-
ghe-ssh \"$GHE_HOSTNAME\" -- 'ghe-import-redis' < \"$GHE_RESTORE_SNAPSHOT_PATH/redis.rdb\" 1>&3")
509+
ghe-restore-redis \"$GHE_HOSTNAME\" \"$GHE_RESTORE_SNAPSHOT_PATH\"")
452510

453511
cmd_title=$(log_info "Restoring Git Repositories ...")
454512
commands+=("
@@ -470,7 +528,7 @@ fi
470528
cmd_title=$(log_info "Restoring SSH authorized keys ...")
471529
commands+=("
472530
echo \"$cmd_title\"
473-
ghe-ssh \"$GHE_HOSTNAME\" -- 'ghe-import-authorized-keys' < \"$GHE_RESTORE_SNAPSHOT_PATH/authorized-keys.json\" 1>&3")
531+
ghe-restore-ssh-keys \"$GHE_HOSTNAME\" \"$GHE_RESTORE_SNAPSHOT_PATH\"")
474532

475533
cmd_title=$(log_info "Restoring storage data ...")
476534
commands+=("
@@ -517,14 +575,17 @@ if [ "$GHE_PARALLEL_ENABLED" = "yes" ]; then
517575
else
518576
log_info "Restoring data serially ..." 1>&3
519577
for c in "${commands[@]}"; do
578+
. "$( dirname "${BASH_SOURCE[0]}" )/../share/github-backup-utils/bm.sh"
520579
eval "$c"
521580
done
522581
fi
523582

524583
# Restart an already running memcached to reset the cache after restore
525-
log_info "Restarting memcached ..." 1>&3
584+
log_info "Restarting memcached ..." 1>&3
585+
bm_start "$(basename $0) - Restarting memcached"
526586
echo "sudo restart -q memcached 2>/dev/null || true" |
527587
ghe-ssh "$GHE_HOSTNAME" -- /bin/sh
588+
bm_end "$(basename $0) - Restarting memcached"
528589

529590
# Prevent GitHub Connect jobs running before we've had a chance to reset
530591
# the configuration by setting the last run date to now.
@@ -538,20 +599,24 @@ fi
538599
# config run to perform data migrations.
539600
if $CLUSTER; then
540601
log_info "Configuring cluster ..."
602+
bm_start "$(basename $0) - configure cluster"
541603
if [ "$GHE_VERSION_MAJOR" -eq "3" ]; then
542604
ghe-ssh "$GHE_HOSTNAME" -- "ghe-cluster-nomad-cleanup" 1>&3 2>&3
543605
elif [ "$GHE_VERSION_MAJOR" -eq "2" ] && [ "$GHE_VERSION_MINOR" -eq "22" ]; then
544606
ghe-ssh "$GHE_HOSTNAME" -- "ghe-cluster-each -- /usr/local/share/enterprise/ghe-nomad-cleanup" 1>&3 2>&3
545607
fi
546608
ghe-ssh "$GHE_HOSTNAME" -- "ghe-cluster-config-apply" 1>&3 2>&3
609+
bm_end "configure_cluster"
547610
elif $instance_configured; then
548611
log_info "Configuring appliance ..."
612+
bm_start "configure_appliance"
549613
if [ "$GHE_VERSION_MAJOR" -eq "3" ]; then
550614
ghe-ssh "$GHE_HOSTNAME" -- "ghe-nomad-cleanup" 1>&3 2>&3
551615
elif [ "$GHE_VERSION_MAJOR" -eq "2" ] && [ "$GHE_VERSION_MINOR" -eq "22" ]; then
552616
ghe-ssh "$GHE_HOSTNAME" -- "/usr/local/share/enterprise/ghe-nomad-cleanup" 1>&3 2>&3
553617
fi
554618
ghe-ssh "$GHE_HOSTNAME" -- "ghe-config-apply" 1>&3 2>&3
619+
bm_end "$(basename $0) - configure appliance"
555620
fi
556621

557622
# Clear GitHub Connect settings stored in the restored database.
@@ -569,6 +634,7 @@ CRON_RUNNING=true
569634
# Clean up all stale replicas on configured instances.
570635
if ! $CLUSTER && $instance_configured; then
571636
log_info "Cleaning up replicas..." 1>&3
637+
bm_start "$(basename $0) - Cleanup replicas"
572638
restored_uuid=$(cat "$GHE_RESTORE_SNAPSHOT_PATH/uuid")
573639
other_nodes=$(echo "
574640
set -o pipefail; \
@@ -584,6 +650,7 @@ if ! $CLUSTER && $instance_configured; then
584650
echo "set -o pipefail; $(typeset -f cleanup_cluster_nodes); cleanup_cluster_nodes $uuid" | ghe-ssh "$GHE_HOSTNAME" 1>&3
585651
done
586652
fi
653+
bm_end "$(basename $0) - Cleanup replicas"
587654
fi
588655

589656
# Update the remote status to "complete". This has to happen before importing

share/github-backup-utils/bm.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ bm_end() {
4949
local tend tstart total
5050
tend=$(date +%s)
5151
tstart=$(eval "echo \$$(bm_desc_to_varname "$@")_start")
52+
5253
total=$(($tend - $tstart))
5354

5455
echo "$1 took ${total}s" >> $BM_FILE_PATH
@@ -57,4 +58,6 @@ bm_end() {
5758
if [ -n "$GHE_DEBUG" ]; then
5859
echo "Debug: $1 took ${total}s (bm_end)"
5960
fi
61+
# track progress
62+
progress "$1 took ${total}s"
6063
}

0 commit comments

Comments
 (0)