@@ -86,6 +86,8 @@ while true; do
86
86
esac
87
87
done
88
88
89
+
90
+
89
91
start_cron () {
90
92
log_info " Starting cron ..."
91
93
if $CLUSTER ; then
@@ -164,6 +166,10 @@ cleanup_cluster_nodes() {
164
166
# shellcheck source=share/github-backup-utils/ghe-backup-config
165
167
. " $( dirname " ${BASH_SOURCE[0]} " ) /../share/github-backup-utils/ghe-backup-config"
166
168
169
+
170
+
171
+
172
+
167
173
# Check to make sure moreutils parallel is installed and working properly
168
174
ghe_parallel_check
169
175
@@ -265,6 +271,48 @@ if is_external_database_snapshot && ! $instance_configured && ! $FORCE; then
265
271
266
272
prompt_for_confirmation " Please confirm this before continuing."
267
273
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
268
316
269
317
# Log restore start message locally and in /var/log/syslog on remote instance
270
318
START_TIME=$( date +%s)
@@ -343,10 +391,11 @@ log_warn "Warning: storing backup-utils version remotely failed."
343
391
# Stop cron and timerd, as scheduled jobs may disrupt the restore process.
344
392
log_info " Stopping cron and github-timerd ..."
345
393
if $CLUSTER ; then
394
+ bm_start " $( basename $0 ) - Stopping cron and github-timerd on cluster"
346
395
if ! ghe-ssh " $GHE_HOSTNAME " -- " ghe-cluster-each -- sudo service cron stop" ; then
347
396
log_warn " Failed to stop cron on one or more nodes" 1>&3
348
397
fi
349
-
398
+ bm_end " $( basename $0 ) - Stopping cron and github-timerd on cluster "
350
399
if [ " $GHE_VERSION_MAJOR " -eq " 3" ]; then
351
400
if ghe-ssh " $GHE_HOSTNAME " -- " systemctl -q is-active nomad && nomad job status --short github-timerd &>/dev/null" ; then
352
401
if ! ghe-ssh " $GHE_HOSTNAME " -- " sudo nomad stop github-timerd 1>/dev/null" ; then
@@ -358,11 +407,14 @@ if $CLUSTER; then
358
407
log_warn " Failed to stop github-timerd on one or more nodes" 1>&3
359
408
fi
360
409
fi
410
+
361
411
else
412
+ bm_start " $( basename $0 ) - Stopping cron and github-timerd"
413
+ echo " $( basename $0 ) - Stopping cron and github-timerd"
362
414
if ! ghe-ssh " $GHE_HOSTNAME " -- " sudo service cron stop" ; then
363
415
log_warn " Failed to stop cron" 1>&3
364
416
fi
365
-
417
+ bm_end " $( basename $0 ) - Stopping cron and github-timerd "
366
418
if [ " $GHE_VERSION_MAJOR " -eq " 3" ]; then
367
419
if ghe-ssh " $GHE_HOSTNAME " -- " systemctl -q is-active nomad && nomad job status --short github-timerd &>/dev/null" ; then
368
420
if ! ghe-ssh " $GHE_HOSTNAME " -- " sudo nomad stop github-timerd 1>/dev/null" ; then
@@ -374,9 +426,11 @@ else
374
426
log_warn " Failed to stop github-timerd" 1>&3
375
427
fi
376
428
fi
429
+
377
430
fi
378
431
CRON_RUNNING=false
379
432
433
+
380
434
# Restore settings and license if restoring to an unconfigured appliance or when
381
435
# specified manually.
382
436
if $RESTORE_SETTINGS ; then
394
448
# Restore UUID if present and not restoring to cluster.
395
449
if [ -s " $GHE_RESTORE_SNAPSHOT_PATH /uuid" ] && ! $CLUSTER ; then
396
450
log_info " Restoring UUID ..."
451
+
452
+ bm_start " $( basename $0 ) - Restore UUID"
397
453
ghe-ssh " $GHE_HOSTNAME " -- " sudo sponge '$GHE_REMOTE_DATA_USER_DIR /common/uuid' 2>/dev/null" < " $GHE_RESTORE_SNAPSHOT_PATH /uuid"
398
454
ghe-ssh " $GHE_HOSTNAME " -- " sudo systemctl stop consul" || true
399
455
ghe-ssh " $GHE_HOSTNAME " -- " sudo rm -rf /data/user/consul/raft"
456
+ bm_end " $( basename $0 ) - Restore UUID"
400
457
fi
401
458
459
+
402
460
if is_external_database_snapshot; then
403
461
appliance_strategy=" external"
404
462
backup_snapshot_strategy=" external"
448
506
cmd_title=$( log_info " Restoring Redis database ..." )
449
507
commands=("
450
508
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 \" " )
452
510
453
511
cmd_title=$( log_info " Restoring Git Repositories ..." )
454
512
commands+=("
470
528
cmd_title=$( log_info " Restoring SSH authorized keys ..." )
471
529
commands+=("
472
530
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 \" " )
474
532
475
533
cmd_title=$( log_info " Restoring storage data ..." )
476
534
commands+=("
@@ -517,14 +575,17 @@ if [ "$GHE_PARALLEL_ENABLED" = "yes" ]; then
517
575
else
518
576
log_info " Restoring data serially ..." 1>&3
519
577
for c in " ${commands[@]} " ; do
578
+ . " $( dirname " ${BASH_SOURCE[0]} " ) /../share/github-backup-utils/bm.sh"
520
579
eval " $c "
521
580
done
522
581
fi
523
582
524
583
# 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"
526
586
echo " sudo restart -q memcached 2>/dev/null || true" |
527
587
ghe-ssh " $GHE_HOSTNAME " -- /bin/sh
588
+ bm_end " $( basename $0 ) - Restarting memcached"
528
589
529
590
# Prevent GitHub Connect jobs running before we've had a chance to reset
530
591
# the configuration by setting the last run date to now.
538
599
# config run to perform data migrations.
539
600
if $CLUSTER ; then
540
601
log_info " Configuring cluster ..."
602
+ bm_start " $( basename $0 ) - configure cluster"
541
603
if [ " $GHE_VERSION_MAJOR " -eq " 3" ]; then
542
604
ghe-ssh " $GHE_HOSTNAME " -- " ghe-cluster-nomad-cleanup" 1>&3 2>&3
543
605
elif [ " $GHE_VERSION_MAJOR " -eq " 2" ] && [ " $GHE_VERSION_MINOR " -eq " 22" ]; then
544
606
ghe-ssh " $GHE_HOSTNAME " -- " ghe-cluster-each -- /usr/local/share/enterprise/ghe-nomad-cleanup" 1>&3 2>&3
545
607
fi
546
608
ghe-ssh " $GHE_HOSTNAME " -- " ghe-cluster-config-apply" 1>&3 2>&3
609
+ bm_end " configure_cluster"
547
610
elif $instance_configured ; then
548
611
log_info " Configuring appliance ..."
612
+ bm_start " configure_appliance"
549
613
if [ " $GHE_VERSION_MAJOR " -eq " 3" ]; then
550
614
ghe-ssh " $GHE_HOSTNAME " -- " ghe-nomad-cleanup" 1>&3 2>&3
551
615
elif [ " $GHE_VERSION_MAJOR " -eq " 2" ] && [ " $GHE_VERSION_MINOR " -eq " 22" ]; then
552
616
ghe-ssh " $GHE_HOSTNAME " -- " /usr/local/share/enterprise/ghe-nomad-cleanup" 1>&3 2>&3
553
617
fi
554
618
ghe-ssh " $GHE_HOSTNAME " -- " ghe-config-apply" 1>&3 2>&3
619
+ bm_end " $( basename $0 ) - configure appliance"
555
620
fi
556
621
557
622
# Clear GitHub Connect settings stored in the restored database.
@@ -569,6 +634,7 @@ CRON_RUNNING=true
569
634
# Clean up all stale replicas on configured instances.
570
635
if ! $CLUSTER && $instance_configured ; then
571
636
log_info " Cleaning up replicas..." 1>&3
637
+ bm_start " $( basename $0 ) - Cleanup replicas"
572
638
restored_uuid=$( cat " $GHE_RESTORE_SNAPSHOT_PATH /uuid" )
573
639
other_nodes=$( echo "
574
640
set -o pipefail; \
@@ -584,6 +650,7 @@ if ! $CLUSTER && $instance_configured; then
584
650
echo " set -o pipefail; $( typeset -f cleanup_cluster_nodes) ; cleanup_cluster_nodes $uuid " | ghe-ssh " $GHE_HOSTNAME " 1>&3
585
651
done
586
652
fi
653
+ bm_end " $( basename $0 ) - Cleanup replicas"
587
654
fi
588
655
589
656
# Update the remote status to "complete". This has to happen before importing
0 commit comments