Skip to content

Commit 4eac374

Browse files
committed
Merge branch 'master' into krayon-shellcheck-p1
2 parents d1304ea + e453b40 commit 4eac374

Some content is hidden

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

51 files changed

+354
-227
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
# macos-latest references are kept here for historical purposes. removed macos-latest from the
1111
#matrix as it is not a typical case for users and causes a lot of friction with other linux-based
1212
# installs. Recommend developing on codespaces or using an ubuntu container.
13-
os: ['ubuntu-22.04', 'ubuntu-20.04', 'ubuntu-18.04']
13+
os: ['ubuntu-22.04', 'ubuntu-20.04']
1414
fail-fast: false
1515
runs-on: ${{ matrix.os }}
1616
steps:

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: 33 additions & 35 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 [ "$(stat -c %i dest1/testfile)" != "$(stat -c %i dest2/testfile)" ]; 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,10 +134,7 @@ 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
@@ -150,8 +143,7 @@ echo "$GHE_SNAPSHOT_TIMESTAMP $$" > ../in-progress
150143
echo "$GHE_SNAPSHOT_TIMESTAMP $$" > "${GHE_DATA_DIR}/in-progress-backup"
151144

152145
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"
146+
log_info "Starting backup of $GHE_HOSTNAME with backup-utils v$BACKUP_UTILS_VERSION in snapshot $GHE_SNAPSHOT_TIMESTAMP"
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
@@ -175,18 +167,18 @@ echo "$GHE_BACKUP_STRATEGY" > strategy
175167
bm_init > /dev/null
176168

177169
ghe-backup-store-version ||
178-
echo "Warning: storing backup-utils version remotely failed."
170+
log_warn "Warning: storing backup-utils version remotely failed."
179171

180-
echo "Backing up GitHub settings ..."
172+
log_info "Backing up GitHub settings ..."
181173
ghe-backup-settings || failures="$failures settings"
182174

183-
echo "Backing up SSH authorized keys ..."
175+
log_info "Backing up SSH authorized keys ..."
184176
bm_start "ghe-export-authorized-keys"
185177
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-export-authorized-keys' > authorized-keys.json ||
186178
failures="$failures authorized-keys"
187179
bm_end "ghe-export-authorized-keys"
188180

189-
echo "Backing up SSH host keys ..."
181+
log_info "Backing up SSH host keys ..."
190182
bm_start "ghe-export-ssh-host-keys"
191183
ghe-ssh "$GHE_HOSTNAME" -- 'ghe-export-ssh-host-keys' > ssh-host-keys.tar ||
192184
failures="$failures ssh-host-keys"
@@ -195,45 +187,52 @@ bm_end "ghe-export-ssh-host-keys"
195187
ghe-backup-mysql || failures="$failures mysql"
196188

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

201-
echo "Backing up Actions data ..."
193+
log_info "Backing up Actions data ..."
202194
ghe-backup-actions 1>&3 || failures="$failures actions"
203195
fi
204196

205197
if ghe-ssh "$GHE_HOSTNAME" -- 'ghe-config --true app.minio.enabled'; then
206-
echo "Backing up Minio data ..."
198+
log_info "Backing up Minio data ..."
207199
ghe-backup-minio 1>&3 || failures="$failures minio"
208200
fi
209201

202+
cmd_title=$(log_info "Backing up Redis database ...")
210203
commands=("
211-
echo \"Backing up Redis database ...\"
204+
echo \"$cmd_title\"
212205
ghe-backup-redis > redis.rdb || printf %s \"redis \" >> \"$failures_file\"")
213206

207+
cmd_title=$(log_info "Backing up audit log ...")
214208
commands+=("
215-
echo \"Backing up audit log ...\"
209+
echo \"$cmd_title\"
216210
ghe-backup-es-audit-log || printf %s \"audit-log \" >> \"$failures_file\"")
217211

212+
cmd_title=$(log_info "Backing up Git repositories ...")
218213
commands+=("
219-
echo \"Backing up Git repositories ...\"
214+
echo \"$cmd_title\"
220215
ghe-backup-repositories || printf %s \"repositories \" >> \"$failures_file\"")
221216

217+
cmd_title=$(log_info "Backing up GitHub Pages artifacts ...")
222218
commands+=("
223-
echo \"Backing up GitHub Pages artifacts ...\"
219+
echo \"$cmd_title\"
224220
ghe-backup-pages || printf %s \"pages \" >> \"$failures_file\"")
225221

222+
cmd_title=$(log_info "Backing up storage data ...")
226223
commands+=("
227-
echo \"Backing up storage data ...\"
224+
echo \"$cmd_title\"
228225
ghe-backup-storage || printf %s \"storage \" >> \"$failures_file\"")
229226

227+
cmd_title=$(log_info "Backing up custom Git hooks ...")
230228
commands+=("
231-
echo \"Backing up custom Git hooks ...\"
229+
echo \"$cmd_title\"
232230
ghe-backup-git-hooks || printf %s \"git-hooks \" >> \"$failures_file\"")
233231

234232
if [ "$GHE_BACKUP_STRATEGY" = "rsync" ]; then
233+
cmd_title=$(log_info "Backing up Elasticsearch indices ...")
235234
commands+=("
236-
echo \"Backing up Elasticsearch indices ...\"
235+
echo \"$cmd_title\"
237236
ghe-backup-es-rsync || printf %s \"elasticsearch \" >> \"$failures_file\"")
238237
fi
239238

@@ -251,6 +250,7 @@ fi
251250

252251
# git fsck repositories after the backup
253252
if [ "$GHE_BACKUP_FSCK" = "yes" ]; then
253+
log_info "Running git fsck on repositories ..."
254254
ghe-backup-fsck "$GHE_SNAPSHOT_DIR" || failures="$failures fsck"
255255
fi
256256

@@ -267,23 +267,21 @@ if [ -z "$failures" ]; then
267267
fi
268268

269269
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")"
270+
log_info "Runtime: $((END_TIME - START_TIME)) seconds"
271+
log_info "Completed backup of $GHE_HOSTNAME in snapshot $GHE_SNAPSHOT_TIMESTAMP at $(date +"%H:%M:%S")"
274272

275273
# Exit non-zero and list the steps that failed.
276274
if [ -z "$failures" ]; then
277275
ghe_remote_logger "Completed backup from $(hostname) / snapshot $GHE_SNAPSHOT_TIMESTAMP successfully."
278276
else
279277
steps="${failures// /, }"
280278
ghe_remote_logger "Completed backup from $(hostname) / snapshot $GHE_SNAPSHOT_TIMESTAMP with failures: ${steps}."
281-
echo "Error: Snapshot incomplete. Some steps failed: ${steps}. "
279+
log_error "Error: Snapshot incomplete. Some steps failed: ${steps}. "
282280
exit 1
283281
fi
284282

285283
# Detect if the created backup contains any leaked ssh keys
286-
echo "Checking for leaked ssh keys ..."
284+
log_info "Checking for leaked ssh keys ..."
287285
ghe-detect-leaked-ssh-keys -s "$GHE_SNAPSHOT_DIR" || true
288286

289287
# Make sure we exit zero after the conditional

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)