Skip to content

Commit db19e98

Browse files
committed
reintroducing logging into the file
1 parent 00fd39c commit db19e98

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

bin/ghe-restore

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ start_cron () {
100100
}
101101

102102
cleanup () {
103-
echo " Exiting, cleaning up ..."
103+
log_info " Exiting, cleaning up ..."
104104
if [ -n "$1" ]; then
105105
update_restore_status "$1"
106106
fi
107107

108108
if $ACTIONS_STOPPED && ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
109-
echo "Restarting Actions after restore ..."
109+
log_info "Restarting Actions after restore ..."
110110
# In GHES 3.3+, ghe-actions-start no longer has a -f (force) flag. In GHES 3.2 and below, we must provide the
111111
# force flag to make sure it can start in maintenance mode. Use it conditionally based on whether it exists
112112
# in the --help output
@@ -122,15 +122,15 @@ cleanup () {
122122
fi
123123

124124
# Cleanup SSH multiplexing
125-
echo "Cleaning up SSH multiplexing ..."
125+
log_info "Cleaning up SSH multiplexing ..."
126126
if ! ghe-ssh --clean ; then
127-
echo "Failed to clean up SSH multiplexing"
127+
log_info "Failed to clean up SSH multiplexing"
128128
fi
129129
# Remove in-progress file
130-
echo "Removing in-progress file ..." 1>&3
130+
log_info "Removing in-progress file ..." 1>&3
131131

132132
if ! rm -f ${GHE_DATA_DIR}/in-progress-restore ; then
133-
echo "Failed to remove in-progress file" 1>&3
133+
log_error "Failed to remove in-progress file" 1>&3
134134
fi
135135
}
136136

@@ -139,21 +139,21 @@ cleanup () {
139139
cleanup_cluster_nodes() {
140140
uuid="$1"
141141
if [ -z "$uuid" ]; then
142-
echo "Node UUID required."
142+
log_error "Node UUID required."
143143
exit 2
144144
fi
145-
echo "Cleaning up spokes" 1>&3
145+
log_info "Cleaning up spokes" 1>&3
146146
ghe-spokes server evacuate git-server-$uuid 'Removing replica'
147147
ghe-spokes server destroy git-server-$uuid
148148

149-
echo "Cleaning up storage" 1>&3
149+
log_info "Cleaning up storage" 1>&3
150150
ghe-storage destroy-host storage-server-$uuid --force
151151

152-
echo "Cleaning up dpages" 1>&3
152+
log_info "Cleaning up dpages" 1>&3
153153
ghe-dpages offline pages-server-$uuid
154154
ghe-dpages remove pages-server-$uuid
155155

156-
echo "Cleaning up redis" 1>&3
156+
log_info "Cleaning up redis" 1>&3
157157
ghe-redis-cli del resque:queue:maint_git-server-$uuid
158158
ghe-redis-cli srem resque:queues maint_git-server-$uuid
159159
}
@@ -218,7 +218,7 @@ export CLUSTER
218218

219219
# Restoring a cluster backup to a standalone appliance is not supported
220220
if ! $CLUSTER && [ "$GHE_BACKUP_STRATEGY" = "cluster" ]; then
221-
echo "Error: Snapshot from a GitHub Enterprise cluster cannot be restored to a standalone appliance. Aborting." >&2
221+
log_error "Error: Snapshot from a GitHub Enterprise cluster cannot be restored to a standalone appliance. Aborting." >&2
222222
exit 1
223223
fi
224224

@@ -230,7 +230,7 @@ fi
230230
# Figure out if this appliance is in a replication pair
231231
if ghe-ssh "$GHE_HOSTNAME" -- \
232232
"[ -f '$GHE_REMOTE_ROOT_DIR/etc/github/repl-state' ]"; then
233-
echo "Error: Restoring to an appliance with replication enabled is not supported. Please teardown replication before restoring." >&2
233+
log_error "Error: Restoring to an appliance with replication enabled is not supported. Please teardown replication before restoring." >&2
234234
exit 1
235235
fi
236236

@@ -295,7 +295,7 @@ update_restore_status "restoring"
295295
# Make sure the GitHub appliance is in maintenance mode.
296296
if $instance_configured; then
297297
if ! ghe-maintenance-mode-status "$GHE_HOSTNAME"; then
298-
echo "Error: $GHE_HOSTNAME must be put in maintenance mode before restoring. Aborting." 1>&2
298+
log_error "Error: $GHE_HOSTNAME must be put in maintenance mode before restoring. Aborting." 1>&2
299299
exit 1
300300
fi
301301
fi
@@ -307,7 +307,7 @@ RELEASE_VERSION=$(ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --get core.package-vers
307307
# mismatches in the secrets needed for Actions which ultimately results in Actions not working properly. Note: xargs is to remove whitespace
308308
ACTIONS_ENABLED_IN_BACKUP=$(git config -f $GHE_RESTORE_SNAPSHOT_PATH/settings.json --bool app.actions.enabled | xargs)
309309
if [[ $ACTIONS_ENABLED_IN_BACKUP != true ]] && ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
310-
echo "Restoring a backup with Actions disabled onto an appliance with Actions enabled is not supported." >&2
310+
log_error "Restoring a backup with Actions disabled onto an appliance with Actions enabled is not supported." >&2
311311
exit 1
312312
fi
313313

@@ -318,15 +318,15 @@ if [ -d "$GHE_RESTORE_SNAPSHOT_PATH/mssql" ] || [ -d "$GHE_RESTORE_SNAPSHOT_PATH
318318
ac_db_ghe=$(echo 'ghe-mssql-console -y -n -q "SELECT name FROM sys.databases" | grep -i "ArtifactCache" | wc -l | tr -d " "' | ghe-ssh "$GHE_HOSTNAME" /bin/bash)
319319
ac_db_snapshot=$(find "$GHE_DATA_DIR/$GHE_RESTORE_SNAPSHOT/mssql/" -maxdepth 1 -name 'ArtifactCache*.bak' | wc -l | tr -d " ")
320320
if [[ $ac_db_ghe -gt 0 && $ac_db_snapshot -eq 0 ]]; then
321-
echo "$GHE_HOSTNAME has Actions Cache service enabled but no Actions Cache data is present in snapshot to restore. Aborting \n Please disable Actions cache service in $GHE_HOSTNAME and retry\nTo disable Actions Cache service run as admin: ghe-actions-cache-disable" 1>&2
321+
log_error "$GHE_HOSTNAME has Actions Cache service enabled but no Actions Cache data is present in snapshot to restore. Aborting \n Please disable Actions cache service in $GHE_HOSTNAME and retry\nTo disable Actions Cache service run as admin: ghe-actions-cache-disable" 1>&2
322322
exit 1
323323
fi
324324
if [[ $ac_db_ghe -eq 0 && $ac_db_snapshot -gt 0 && ! $RESTORE_SETTINGS ]]; then
325-
echo "$GHE_HOSTNAME has Actions Cache service disabled but the snapshot is attempting to restore data for the service. Aborting. \n Please enable Actions cache service in $GHE_HOSTNAME and retry \n To enable Actions Cache service run as admin: ghe-actions-cache-enable" 1>&2
325+
log_error "$GHE_HOSTNAME has Actions Cache service disabled but the snapshot is attempting to restore data for the service. Aborting. \n Please enable Actions cache service in $GHE_HOSTNAME and retry \n To enable Actions Cache service run as admin: ghe-actions-cache-enable" 1>&2
326326
exit 1
327327
fi
328328
else
329-
echo "$GHE_HOSTNAME must have GitHub Actions enabled before restoring since the snapshot contains Actions data. Aborting. \n Setup details for enabling Actions can be found here: https://docs.github.com/en/enterprise-server@$RELEASE_VERSION/admin/github-actions/advanced-configuration-and-troubleshooting/backing-up-and-restoring-github-enterprise-server-with-github-actions-enabled" 1>&2
329+
log_error "$GHE_HOSTNAME must have GitHub Actions enabled before restoring since the snapshot contains Actions data. Aborting. \n Setup details for enabling Actions can be found here: https://docs.github.com/en/enterprise-server@$RELEASE_VERSION/admin/github-actions/advanced-configuration-and-troubleshooting/backing-up-and-restoring-github-enterprise-server-with-github-actions-enabled" 1>&2
330330
exit 1
331331
fi
332332
fi
@@ -335,40 +335,40 @@ fi
335335
bm_init > /dev/null
336336

337337
ghe-backup-store-version ||
338-
echo "Warning: storing backup-utils version remotely failed."
338+
log_warn "Warning: storing backup-utils version remotely failed."
339339

340340
# Stop cron and timerd, as scheduled jobs may disrupt the restore process.
341-
echo "Stopping cron and github-timerd ..."
341+
log_info "Stopping cron and github-timerd ..."
342342
if $CLUSTER; then
343343
if ! ghe-ssh "$GHE_HOSTNAME" -- "ghe-cluster-each -- sudo service cron stop"; then
344-
ghe_verbose "* Warning: Failed to stop cron on one or more nodes"
344+
log_warn "Failed to stop cron on one or more nodes" 1>&3
345345
fi
346346

347347
if [ "$GHE_VERSION_MAJOR" -eq "3" ]; then
348348
if ghe-ssh "$GHE_HOSTNAME" -- "systemctl -q is-active nomad && nomad job status --short github-timerd &>/dev/null"; then
349349
if ! ghe-ssh "$GHE_HOSTNAME" -- "sudo nomad stop github-timerd 1>/dev/null"; then
350-
ghe_verbose "* Warning: Failed to stop github-timerd on one or more nodes"
350+
log_warn "Failed to stop github-timerd on one or more nodes" 1>&3
351351
fi
352352
fi
353353
else
354354
if ! ghe-ssh "$GHE_HOSTNAME" -- "ghe-cluster-each -- sudo service github-timerd stop"; then
355-
ghe_verbose "* Warning: Failed to stop github-timerd on one or more nodes"
355+
log_warn "Failed to stop github-timerd on one or more nodes" 1>&3
356356
fi
357357
fi
358358
else
359359
if ! ghe-ssh "$GHE_HOSTNAME" -- "sudo service cron stop"; then
360-
ghe_verbose "* Warning: Failed to stop cron"
360+
log_warn "Failed to stop cron" 1>&3
361361
fi
362362

363363
if [ "$GHE_VERSION_MAJOR" -eq "3" ]; then
364364
if ghe-ssh "$GHE_HOSTNAME" -- "systemctl -q is-active nomad && nomad job status --short github-timerd &>/dev/null"; then
365365
if ! ghe-ssh "$GHE_HOSTNAME" -- "sudo nomad stop github-timerd 1>/dev/null"; then
366-
ghe_verbose "* Warning: Failed to stop github-timerd"
366+
log_warn "Failed to stop github-timerd" 1>&3
367367
fi
368368
fi
369369
else
370370
if ! ghe-ssh "$GHE_HOSTNAME" -- "sudo service github-timerd stop"; then
371-
ghe_verbose "* Warning: Failed to stop github-timerd"
371+
log_warn "Failed to stop github-timerd" 1>&3
372372
fi
373373
fi
374374
fi
@@ -390,7 +390,7 @@ fi
390390

391391
# Restore UUID if present and not restoring to cluster.
392392
if [ -s "$GHE_RESTORE_SNAPSHOT_PATH/uuid" ] && ! $CLUSTER; then
393-
echo "Restoring UUID ..."
393+
log_info "Restoring UUID ..."
394394
cat "$GHE_RESTORE_SNAPSHOT_PATH/uuid" |
395395
ghe-ssh "$GHE_HOSTNAME" -- "sudo sponge '$GHE_REMOTE_DATA_USER_DIR/common/uuid' 2>/dev/null"
396396
ghe-ssh "$GHE_HOSTNAME" -- "sudo systemctl stop consul" || true
@@ -415,29 +415,29 @@ else
415415
fi
416416

417417
if is_external_database_target_or_snapshot && $SKIP_MYSQL; then
418-
echo "Skipping MySQL restore."
418+
log_info "Skipping MySQL restore."
419419
else
420-
echo "Restoring MySQL database from ${backup_snapshot_strategy} backup snapshot on an appliance configured for ${appliance_strategy} backups ..."
420+
log_info "Restoring MySQL database from ${backup_snapshot_strategy} backup snapshot on an appliance configured for ${appliance_strategy} backups ..."
421421
ghe-restore-mysql "$GHE_HOSTNAME" 1>&3
422422
fi
423423

424424
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.actions.enabled'; then
425-
echo "Stopping Actions before restoring databases ..."
425+
log_info "Stopping Actions before restoring databases ..."
426426
# We mark Actions as stopped even if the `ghe-actions-stop`
427427
# fails to ensure that we cleanly start actions when performing cleanup.
428428
ACTIONS_STOPPED=true
429429
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-actions-stop' 1>&3
430430

431-
echo "Restoring MSSQL databases ..."
431+
log_info "Restoring MSSQL databases ..."
432432
ghe-restore-mssql "$GHE_HOSTNAME" 1>&3
433433

434-
echo "Restoring Actions data ..."
434+
log_info "Restoring Actions data ..."
435435
ghe-restore-actions "$GHE_HOSTNAME" 1>&3
436436
echo "* WARNING: Every self-hosted Actions runner that communicates with the restored GHES server must be restarted or reconfigured in order to continue functioning. \n See https://docs.github.com/en/actions/hosting-your-own-runners/adding-self-hosted-runners for more details on how to reconfigure self-hosted Actions runners."
437437
fi
438438

439439
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.minio.enabled'; then
440-
echo "Restoring MinIO data ..."
440+
log_info "Restoring MinIO data ..."
441441
ghe-restore-minio "$GHE_HOSTNAME" 1>&3
442442
fi
443443

0 commit comments

Comments
 (0)